squares 0.2.1 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7f03e84cc85c9fb4614abcacd298ca3ccda13e40
4
- data.tar.gz: 255f0581816730697789dc2e4a087066449588d8
3
+ metadata.gz: 3ae6fe521a019f5b9834c3287c089b03fec26ecd
4
+ data.tar.gz: 5c57b3e5651a35a0e0432ac38cc2f50dffb738fc
5
5
  SHA512:
6
- metadata.gz: 2708b3e0a06a5cedadea36176180cbbbe76cbaab60b18f61af5008d97a0b3a18514cc06a1c4bf9382de2de8f5dc4f6c8bcad1a7c97b7ff9ffffbb980459efca7
7
- data.tar.gz: 773b53890ab342f512fd527aefcf2cf77f46d606b25f53fdb440740db7b5fd6e1d7ee6685372832376c1476c2b1da61fb9f03f0116a2ea5f0e757591a67bd964
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 setup a bunch of 'em like this:
68
+ Or if you just want to use a plain ole in-memory hash:
69
69
 
70
70
  ```ruby
71
- [Person, Place, Thing].each do |model|
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
- ...or if you just want to use a plain ole in-memory hash:
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
- tom_sellecks_mustache = {}
80
- Soup.store = tom_sellecks_mustache
91
+ Squares.map &:underscore_name #=> ['person', 'place', 'swamp_thing']
81
92
  ```
82
93
 
83
- Squares actually defaults the store to an empty hash, which means if you're ok
84
- with in-memory, transient storage (e.g. when writing tests, etc.) you don't have
85
- to do any config-- er, bootstrapping `;)` at all!
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
@@ -1,3 +1,3 @@
1
1
  module Squares
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.3"
3
3
  end
data/lib/squares.rb CHANGED
@@ -2,5 +2,16 @@ require 'squares/version'
2
2
  require 'squares/base'
3
3
 
4
4
  module Squares
5
- # Your code goes here...
5
+ class << self
6
+ include Enumerable
7
+
8
+ def each &block
9
+ models.each &block
10
+ end
11
+
12
+ def models
13
+ Squares::Base.models
14
+ end
15
+
16
+ end
6
17
  end
@@ -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'] }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: squares
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel Helbling