diff options
| author | mo khan <mo@mokhan.ca> | 2013-11-09 08:36:15 -0700 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2013-11-09 08:36:15 -0700 |
| commit | 86ad7b779e64880bde62bf51ea72c6afa528ab33 (patch) | |
| tree | e4c653eef6bdc2c8a5472a3e544d87c9d2851aa5 | |
| parent | eac28ff73ae2ef2738a058d60a2e4d35a610db60 (diff) | |
refactor to Where Specification to match by target object attributes.
| -rw-r--r-- | src/movie.coffee | 18 | ||||
| -rw-r--r-- | test/movie_library_spec.coffee | 2 |
2 files changed, 11 insertions, 9 deletions
diff --git a/src/movie.coffee b/src/movie.coffee index 9d22e85..9fe2348 100644 --- a/src/movie.coffee +++ b/src/movie.coffee @@ -7,13 +7,15 @@ module.exports = class Movie equals: (other) -> @title == other["title"] - @by: (studio) -> - console.log(studio) - new StudioSpecification(studio) + @where: (condition) -> + new WhereSpecification(condition) + +class WhereSpecification + constructor: (condition) -> + @condition = condition + + matches: (item) -> + for key in Object.keys(@condition) + item[key] == @condition[key] -class StudioSpecification - constructor: (studio) -> - @studio = studio - matches: (movie) -> - @studio == movie.studio diff --git a/test/movie_library_spec.coffee b/test/movie_library_spec.coffee index 8e9b0f6..284f129 100644 --- a/test/movie_library_spec.coffee +++ b/test/movie_library_spec.coffee @@ -49,7 +49,7 @@ describe "MovieLibrary", -> @sut.add(movie) it "can find all pixar movies", -> - results = @sut.all(Movie.by(Studio.Pixar)) + results = @sut.all(Movie.where(studio: Studio.Pixar)) results.should.include(@toy_story) results.should.include(@up) results.should.include(@cars) |
