specify 1.1.0

  • README.md
  • Installing
  • Versions
  • 32

specify

Specifications allow simple classes to encapsulate business rules in a flexible, testable, and reusable manner.

examples

import 'package:specify/specify.dart';

class StringContains extends Specification<String> {
    final String _substring;
    StringContains(this._substring);
    bool isSatisfiedBy(String aString) => aString.contains(_substring);
}

class StringNotContains extends StringContains {
    StringNotContains(String aSubstring) : super(aSubstring);
    bool isSatisfiedBy(String aString) => !super.isSatisfiedBy(aString);
}

class StringIn extends OrSpecification<String> {
    StringIn(List<String> aWordList) : super(
        aWordList.map((String aWord) => new StringContains(aWord)).toList()
    );
}

class StringNotIn extends AndSpecification<String> {
    StringNotIn(List<String> aWordList) : super(
        aWordList.map((String aWord) => new StringNotContains(aWord)).toList()
    );
}

main() {
    StringIn    isWord    = new StringIn(['foo', 'bar']);
    StringNotIn isNotWord = new StringNotIn(['baz', 'zim']);

    print(isWord('barge'));
    print(isNotWord('hello'));
}

filters

Filtering with specifications can be very powerful, especially when used with CompositeSpecification.

import 'package:specify/specify.dart';

class StringLength extends Specification<String> {
    final int _length;

    StringLength(this._length);

    bool isSatisfiedBy(String aString) => aString.length == _length;
}

class LengthFilter extends Filter<String> {
    LengthFilter(int aLength) : super(new StringLength(aLength));
}

main() {
    LengthFilter filter = new LengthFilter(3);

    print(filter(['foo', 'bar', 'nice', 'to', 'know', 'you']));
}

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  specify: "^1.1.0"

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:specify/specify.dart';
        
Version Uploaded Documentation Archive
1.1.0 Feb 5, 2017 Go to the documentation of specify 1.1.0 Download specify 1.1.0 archive
1.0.1 Jan 21, 2017 Go to the documentation of specify 1.0.1 Download specify 1.0.1 archive
1.0.0 Jan 19, 2017 Go to the documentation of specify 1.0.0 Download specify 1.0.0 archive

Analysis

We analyzed this package on Apr 9, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.46.0
  • pana: 0.10.6

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
0 / 100
Health:
Code health derived from static analysis. [more]
64 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
65 / 100
Overall score:
Weighted score of the above. [more]
32
Learn more about scoring.

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:specify/specify.dart.

Suggestions

  • Maintain CHANGELOG.md.

    Changelog entries help clients to follow the progress in your code.

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 2 errors 5 hints.

    Strong-mode analysis of lib/src/composite_specification.dart failed with the following error:

    line: 22 col: 5
    Invalid override. The type of 'CompositeSpecification.isSpecialCaseOf' ('(Specification<T>) → bool') isn't a subtype of 'Specification<T>.isSpecialCaseOf' ('(Specification<dynamic>) → bool').

    Run dartfmt to format lib/src/and_specification.dart.

    Similar analysis of the following files failed:

    • lib/src/filter.dart (hint)
    • lib/src/or_specification.dart (hint)
    • lib/src/specification.dart (hint)
  • The description is too short.

    Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

  • Maintain an example.

    Create a short demo in the example/ directory to show how to use this package. Common file name patterns include: main.dart, example.dart or you could also use specify.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.15.0 <2.0.0
Dev dependencies
test ^0.12.7