collector 0.0.6 → 0.0.7
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 +5 -1
- data/lib/collector/model.rb +3 -5
- data/lib/collector/version.rb +1 -1
- data/test/collector/model_spec.rb +4 -11
- metadata +2 -2
data/README.md
CHANGED
@@ -55,7 +55,7 @@ Models automatically create and update timestamps for `created_at` and `updated_
|
|
55
55
|
|
56
56
|
### Repositories
|
57
57
|
|
58
|
-
Include `Collector::Repository` in
|
58
|
+
Include `Collector::Repository` in an object to turn it into a repository for a model of the same name. Use the same inflection as your model's name (singular).
|
59
59
|
|
60
60
|
```ruby
|
61
61
|
class PickleRepository
|
@@ -72,6 +72,10 @@ pickle = Pickle.new(brine: "vinegar", started_at: Time.now)
|
|
72
72
|
PickleRepository.save(pickle)
|
73
73
|
```
|
74
74
|
|
75
|
+
### Requirements
|
76
|
+
|
77
|
+
Collector will only work with 1.9.x and above. Specifically it's tested with 1.9.2 and 1.9.3.
|
78
|
+
|
75
79
|
## Contributing
|
76
80
|
|
77
81
|
1. Fork it
|
data/lib/collector/model.rb
CHANGED
@@ -10,12 +10,10 @@ module Collector
|
|
10
10
|
def initialize(attributes = {})
|
11
11
|
attributes.symbolize_keys!
|
12
12
|
|
13
|
-
attributes.each do |
|
14
|
-
|
13
|
+
attributes.each do |key, value|
|
14
|
+
instance_variable_set("@#{key}", value) if methods.include? "#{key}".to_sym
|
15
|
+
send("#{key}=", value) if methods.include? "#{key}=".to_sym
|
15
16
|
end
|
16
|
-
|
17
|
-
instance_variable_set("@created_at", attributes[:created_at]) if attributes[:created_at]
|
18
|
-
instance_variable_set("@updated_at", attributes[:updated_at]) if attributes[:updated_at]
|
19
17
|
end
|
20
18
|
|
21
19
|
def touch
|
data/lib/collector/version.rb
CHANGED
@@ -9,15 +9,15 @@ describe Collector::Model do
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
it "sets attributes during initialization if a
|
12
|
+
it "sets attributes via instance variable during initialization if a reader exists" do
|
13
13
|
TestModel.send(:attr_reader, :foo)
|
14
|
-
TestModel.send(:attr_writer, :foo)
|
15
14
|
TestModel.new(foo: "bar").foo.must_equal "bar"
|
16
15
|
end
|
17
16
|
|
18
|
-
it "
|
17
|
+
it "sets attributes via writer if a writer exists" do
|
19
18
|
TestModel.send(:attr_reader, :foo)
|
20
|
-
TestModel.
|
19
|
+
TestModel.send(:attr_writer, :foo)
|
20
|
+
TestModel.new(foo: "bar").foo.must_equal "bar"
|
21
21
|
end
|
22
22
|
|
23
23
|
it "has a created_at and updated_at timestamp" do
|
@@ -27,13 +27,6 @@ describe Collector::Model do
|
|
27
27
|
test_model.created_at.must_equal now
|
28
28
|
end
|
29
29
|
|
30
|
-
it "sets timestamps via instance variables during initialization" do
|
31
|
-
now = Time.now
|
32
|
-
test_model = TestModel.new(created_at: now, updated_at: now)
|
33
|
-
test_model.created_at.must_equal now
|
34
|
-
test_model.updated_at.must_equal now
|
35
|
-
end
|
36
|
-
|
37
30
|
describe "#touch" do
|
38
31
|
it "sets the timestamps" do
|
39
32
|
Timecop.freeze
|
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.
|
4
|
+
version: 0.0.7
|
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-11-
|
12
|
+
date: 2012-11-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|