collector 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -3,10 +3,10 @@
3
3
  [![Build Status](https://travis-ci.org/brandonweiss/collector.png)](https://travis-ci.org/brandonweiss/collector)
4
4
  [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/brandonweiss/collector)
5
5
 
6
- _Collector isn't ready for use just yet. And I don't mean it's unstable or alpha, I mean literally it doesn't do anything yet. When the basic feature set is ready I will bump the minor version (to 0.1.0)._
7
-
8
6
  Collector is an implementation of the Repository Pattern for MongoDB. For those new to the Repository Pattern, it is a Facade that isolates the persistence layer from your application. If you're familiar with Rails, or more specifically ActiveRecord or most other ORMs, you'll know that the models and persistence layer are tightly coupled—literally they are the same object. That pattern is a great way to cut your teeth, but ultimately it's a terrible design. Your application does not and should not care about how its data is persisted. Collector will help with that.
9
7
 
8
+ _Collector is currently under initial development, and I mean that in the context of [semantic versioning](http://semver.org), which I follow. Initial development is anything with a major version of zero (0.x.x), which means anything may change at any time; there is no public API. I'll do my best not to wildly change anything, but if you upgrade, run your application tests to see if anything breaks. If you don't have application tests then you have failed. Go home and re-think your life choices that have brought you to this point._
9
+
10
10
  ## Installation
11
11
 
12
12
  Add this line to your application's Gemfile:
@@ -72,6 +72,15 @@ pickle = Pickle.new(brine: "vinegar", started_at: Time.now)
72
72
  PickleRepository.save(pickle)
73
73
  ```
74
74
 
75
+ Repositories can get all models, find by ID, or find dynamically by any attribute.
76
+
77
+ ```ruby
78
+ PickleRepository.all
79
+ PickleRepository.find_by_id(BSON::ObjectId("50af1f3fb392d4aa0d000001"))
80
+ PickleRepository.find_by_color("green")
81
+ PickleRepository.find_by_taste("delicious")
82
+ ```
83
+
75
84
  ### Requirements
76
85
 
77
86
  Collector will only work with 1.9.x and above. Specifically it's tested with 1.9.2 and 1.9.3.
@@ -59,6 +59,10 @@ module Collector
59
59
  end
60
60
  end
61
61
 
62
+ def find_by_id(id)
63
+ deserialize!(collection.find(_id: id))
64
+ end
65
+
62
66
  def method_missing(method_sym, *arguments, &block)
63
67
  if method_sym.to_s =~ /^find_by_(.*)$/
64
68
  collection.find($1.to_sym => arguments.first).map do |document|
@@ -1,3 +1,3 @@
1
1
  module Collector
2
- VERSION = "0.0.10"
2
+ VERSION = "0.0.11"
3
3
  end
@@ -96,6 +96,17 @@ describe Collector::Repository do
96
96
  end
97
97
  end
98
98
 
99
+ describe "find_by_id" do
100
+ it "returns a document by its ID" do
101
+ id = "bson-id"
102
+ document = stub
103
+ TestRepository.expects(:deserialize!).with(document)
104
+ collection = mock { expects(:find).with(_id: id).returns(document) }
105
+ TestRepository.expects(:collection).returns(collection)
106
+ TestRepository.find_by_id(id)
107
+ end
108
+ end
109
+
99
110
  describe "finders" do
100
111
  it "dynamically matches find_by finders" do
101
112
  document_1 = stub
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: collector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: