toystore 0.6.5 → 0.6.6

Sign up to get free protection for your applications and to get access to all the features.
data/lib/toy/identity.rb CHANGED
@@ -9,23 +9,27 @@ module Toy
9
9
  module ClassMethods
10
10
  def key(name_or_factory = :uuid)
11
11
  @key_factory = case name_or_factory
12
- when :uuid
13
- UUIDKeyFactory.new
14
- when :object_id
15
- require 'toy/identity/object_id_key_factory'
16
- ObjectIdKeyFactory.new
17
- else
18
- if name_or_factory.respond_to?(:next_key) &&
19
- name_or_factory.respond_to?(:key_type)
20
- name_or_factory
12
+ when :uuid
13
+ UUIDKeyFactory.new
14
+ when :object_id
15
+ require 'toy/identity/object_id_key_factory'
16
+ ObjectIdKeyFactory.new
21
17
  else
22
- raise InvalidKeyFactory.new(name_or_factory)
18
+ if name_or_factory.respond_to?(:next_key) &&
19
+ name_or_factory.respond_to?(:key_type)
20
+ name_or_factory
21
+ else
22
+ raise InvalidKeyFactory.new(name_or_factory)
23
+ end
23
24
  end
24
- end
25
25
  attribute :id, @key_factory.key_type
26
26
  @key_factory
27
27
  end
28
28
 
29
+ def key_factory
30
+ @key_factory || raise('Set your key_factory using key(...)')
31
+ end
32
+
29
33
  def key_type
30
34
  @key_factory.key_type
31
35
  end
data/lib/toy/plugins.rb CHANGED
@@ -1,23 +1,32 @@
1
1
  module Toy
2
2
  def models
3
- @models ||= Set.new
3
+ Toy::Store.direct_descendants
4
4
  end
5
5
 
6
6
  def plugins
7
- @plugins ||= Set.new
7
+ Toy::Store.plugins
8
8
  end
9
9
 
10
10
  def plugin(mod)
11
- Toy.models.each { |model| model.send(:include, mod) }
12
- plugins << mod
11
+ Toy::Store.plugin(mod)
13
12
  end
14
13
 
15
14
  module Plugins
16
- extend ActiveSupport::Concern
15
+ include ActiveSupport::DescendantsTracker
17
16
 
18
- included do
19
- Toy.models << self
20
- Toy.plugins.each { |mod| include mod }
17
+ def plugins
18
+ @plugins ||= []
19
+ end
20
+
21
+ def plugin(mod)
22
+ include(mod)
23
+ direct_descendants.each {|model| model.send(:include, mod) }
24
+ plugins << mod
25
+ end
26
+
27
+ def included(base=nil, &block)
28
+ direct_descendants << base if base
29
+ super
21
30
  end
22
31
  end
23
- end
32
+ end
data/lib/toy/store.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  module Toy
2
2
  module Store
3
3
  extend ActiveSupport::Concern
4
+ extend Plugins
4
5
 
5
6
  included do
6
7
  extend ActiveModel::Naming
@@ -9,7 +10,6 @@ module Toy
9
10
  include Identity
10
11
  include Persistence
11
12
  include MassAssignmentSecurity
12
- include Plugins
13
13
  include Dolly
14
14
  include Dirty
15
15
  include Equality
data/lib/toy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Toy
2
- VERSION = "0.6.5"
2
+ VERSION = "0.6.6"
3
3
  end
@@ -18,14 +18,11 @@ describe Toy::Identity do
18
18
  end
19
19
 
20
20
  it "should use Toy.key_factory by default" do
21
- key_factory = Toy::Identity::UUIDKeyFactory.new
21
+ key_factory = Toy::Identity::ObjectIdKeyFactory.new
22
22
  Toy.key_factory = key_factory
23
- klass = Class.new { include Toy::Store }
24
-
25
- key_factory.should_receive(:next_key).and_return('some_key')
26
- klass.next_key
27
-
28
- Toy.key_factory = nil
23
+ Class.new do
24
+ include Toy::Store
25
+ end.key_factory.should be_instance_of(Toy::Identity::ObjectIdKeyFactory)
29
26
  end
30
27
  end
31
28
 
@@ -4,7 +4,7 @@ describe Toy::Plugins do
4
4
  uses_constants('User', 'Game')
5
5
 
6
6
  it "keeps track of class that include toy store" do
7
- Toy.models.should == [User, Game].to_set
7
+ Toy.models.should == [User, Game]
8
8
  end
9
9
 
10
10
  describe ".plugin" do
@@ -27,7 +27,7 @@ describe Toy::Plugins do
27
27
  end
28
28
 
29
29
  it "adds plugin to plugins" do
30
- Toy.plugins.should == [@mod].to_set
30
+ Toy.plugins.should == [@mod]
31
31
  end
32
32
 
33
33
  it "adds plugins to classes declared after plugin was called" do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toystore
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
5
- prerelease: false
4
+ hash: 11
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 5
10
- version: 0.6.5
9
+ - 6
10
+ version: 0.6.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Geoffrey Dagley
@@ -16,8 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-04-15 00:00:00 -04:00
20
- default_executable:
19
+ date: 2011-05-08 00:00:00 Z
21
20
  dependencies:
22
21
  - !ruby/object:Gem::Dependency
23
22
  name: adapter
@@ -216,7 +215,6 @@ files:
216
215
  - specs.watchr
217
216
  - test/lint_test.rb
218
217
  - toystore.gemspec
219
- has_rdoc: true
220
218
  homepage: http://github.com/newtoy/toystore
221
219
  licenses: []
222
220
 
@@ -246,7 +244,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
246
244
  requirements: []
247
245
 
248
246
  rubyforge_project:
249
- rubygems_version: 1.3.7
247
+ rubygems_version: 1.7.2
250
248
  signing_key:
251
249
  specification_version: 3
252
250
  summary: An object mapper for anything that can read, write and delete data
@@ -301,3 +299,4 @@ test_files:
301
299
  - spec/toy/validations_spec.rb
302
300
  - spec/toy_spec.rb
303
301
  - test/lint_test.rb
302
+ has_rdoc: