collector 0.0.18 → 0.0.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -84,6 +84,14 @@ PickleRepository.find_first_by_color("green")
84
84
  PickleRepository.find_first_by_taste("delicious")
85
85
  ```
86
86
 
87
+ Repositories can delete models.
88
+
89
+ ```ruby
90
+ pickle = Pickle.new(brine: "vinegar", started_at: Time.now)
91
+ PickleRepository.save(pickle)
92
+ PickleRepository.delete(pickle)
93
+ ```
94
+
87
95
  ### Requirements
88
96
 
89
97
  Collector will only work with 1.9.x and above. Specifically it's tested with 1.9.2 and 1.9.3.
@@ -33,6 +33,10 @@ module Collector
33
33
  collection.save(attributes)
34
34
  end
35
35
 
36
+ def delete(model)
37
+ collection.remove(_id: normalize_id(model.id))
38
+ end
39
+
36
40
  def serialize!(model)
37
41
  attributes = serialize(model)
38
42
  attributes["_id"] = BSON::ObjectId.from_string(attributes.delete("id")) if attributes["id"]
@@ -1,3 +1,3 @@
1
1
  module Collector
2
- VERSION = "0.0.18"
2
+ VERSION = "0.0.19"
3
3
  end
@@ -49,6 +49,17 @@ describe Collector::Repository do
49
49
  end
50
50
  end
51
51
 
52
+ describe "delete" do
53
+ it "deletes the model from the collection" do
54
+ model = stub(id: "50c58f4ab392d4381a000001")
55
+
56
+ collection = mock { expects(:remove).with(_id: BSON::ObjectId("50c58f4ab392d4381a000001")) }
57
+ TestRepository.stubs(:collection).returns(collection)
58
+
59
+ TestRepository.delete(model)
60
+ end
61
+ end
62
+
52
63
  describe "serialize!" do
53
64
  it "normalize id to _id and converts to a BSON::ObjectId" do
54
65
  model = mock(attributes: { id: "50c58f4ab392d4381a000001", foo: "bar" })
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.18
4
+ version: 0.0.19
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-11 00:00:00.000000000 Z
12
+ date: 2012-12-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport