squares 0.2.1 → 0.2.3
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.
- checksums.yaml +4 -4
- data/README.md +23 -8
- data/lib/squares/base.rb +9 -0
- data/lib/squares/version.rb +1 -1
- data/lib/squares.rb +12 -1
- data/spec/squares/base_spec.rb +5 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ae6fe521a019f5b9834c3287c089b03fec26ecd
|
4
|
+
data.tar.gz: 5c57b3e5651a35a0e0432ac38cc2f50dffb738fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dfe664abc8053d4f996cc73acb690b7a44f63cda1cecf8e8febadfd05180c34f445f676779759afb842231aaf681b25f133d2aa1c9d824c261c073973e01dc18
|
7
|
+
data.tar.gz: 78bd50b7cd5588a6fcce8794455f9ea3a92033afd1a7656c22493911e8744951f321e9542cecaa12bd952e33baf59f7ac83f64275817cc5e1781f0f64c943845
|
data/README.md
CHANGED
@@ -65,24 +65,39 @@ people_storage = Redis::Namespace.new(
|
|
65
65
|
Person.store = people_storage
|
66
66
|
```
|
67
67
|
|
68
|
-
Or
|
68
|
+
Or if you just want to use a plain ole in-memory hash:
|
69
69
|
|
70
70
|
```ruby
|
71
|
-
|
71
|
+
tom_sellecks_mustache = {}
|
72
|
+
Soup.store = tom_sellecks_mustache
|
73
|
+
```
|
74
|
+
|
75
|
+
Squares actually defaults the store to an empty hash, which means if you're ok
|
76
|
+
with in-memory, transient storage (e.g. when writing tests, etc.) you don't have
|
77
|
+
to do any config-- er, bootstrapping `;)` at all!
|
78
|
+
|
79
|
+
You can setup a bunch of 'em like this:
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
[Person, Place, SwampThing].each do |model|
|
72
83
|
model.store = LevelDB::DB.new("./tmp/#{model.underscore_name}")
|
73
84
|
end
|
74
85
|
```
|
75
86
|
|
76
|
-
|
87
|
+
But it gets even better: the Squares module is an `Enumerable` which enumerates all
|
88
|
+
the model classes (inheritors of `Squares::Base`). So you can:
|
77
89
|
|
78
90
|
```ruby
|
79
|
-
|
80
|
-
Soup.store = tom_sellecks_mustache
|
91
|
+
Squares.map &:underscore_name #=> ['person', 'place', 'swamp_thing']
|
81
92
|
```
|
82
93
|
|
83
|
-
|
84
|
-
|
85
|
-
|
94
|
+
Or better yet:
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
Squares.each do |model|
|
98
|
+
model.store = LevelDB::DB.new './tmp/#{model.underscore_name}'
|
99
|
+
end
|
100
|
+
```
|
86
101
|
|
87
102
|
### Onward To The Fun
|
88
103
|
|
data/lib/squares/base.rb
CHANGED
@@ -132,12 +132,21 @@ module Squares
|
|
132
132
|
end
|
133
133
|
end
|
134
134
|
|
135
|
+
def models
|
136
|
+
@_models.uniq.sort { |a,b| a.to_s <=> b.to_s }
|
137
|
+
end
|
138
|
+
|
135
139
|
private
|
136
140
|
|
137
141
|
def uniquify_properties
|
138
142
|
@_properties = @_properties.uniq.compact
|
139
143
|
end
|
140
144
|
|
145
|
+
def inherited(subclass)
|
146
|
+
@_models ||= []
|
147
|
+
@_models << subclass
|
148
|
+
end
|
149
|
+
|
141
150
|
end
|
142
151
|
end
|
143
152
|
end
|
data/lib/squares/version.rb
CHANGED
data/lib/squares.rb
CHANGED
data/spec/squares/base_spec.rb
CHANGED
@@ -38,6 +38,11 @@ module Squares
|
|
38
38
|
Then { test_class.store == storage }
|
39
39
|
end
|
40
40
|
|
41
|
+
describe '.models lists defined models (inheritors)' do
|
42
|
+
When(:result) { described_class.models }
|
43
|
+
Then { result == [ Marvel::SuperHero, Marvel::Villain ] }
|
44
|
+
end
|
45
|
+
|
41
46
|
describe '.[]' do
|
42
47
|
Given { storage[id] = Marshal.dump hero }
|
43
48
|
When(:recovered_hero) { Marvel::SuperHero['Captain America'] }
|