toystore 0.12.0 → 0.13.0

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/Changelog.md CHANGED
@@ -1,43 +1,61 @@
1
+ # Changelog
2
+
1
3
  I will do my best to keep this up to date with significant changes here, starting in 0.8.3.
2
4
 
3
- * 0.12.0
4
-
5
- * Ruby 1.9 only. Officially not supporting Ruby 1.8.x.
6
- * Added :native_uuid key factory for using when your data store supports them.
7
- * Aliased .find and .read to .get.
8
- * Aliased .find_multiple and .read_multiple to .get_multiple.
9
-
10
- * 0.10.x => 0.11.0
11
-
12
- * Added get_multiple which returns Hash of id pointed at instance.
13
- * Aliased get_multi to get_multiple which means it now returns Hash instead of Array.
14
- * Updated to latest version of adapter.
15
-
16
- * 0.10.4
17
- * Support for ActiveSupport/ActiveModel 3.2.*
18
-
19
- * 0.10.3
20
- * More liberal uuid gem dependency version
21
-
22
- * 0.10.2
23
- * [Allow changing list attribute type](https://github.com/jnunemaker/toystore/commit/a5b1a944622509c32688d2e56088a7d7aa6fc0b3)
24
- * [No longer include id in `persisted_attributes`](https://github.com/jnunemaker/toystore/commit/9f713311ebf174e314db700392e27af86ca00662)
25
- * [Allow overriding `persist` safely](https://github.com/jnunemaker/toystore/commit/304e50c7e4ac11a365ae00f5d4caed722de31909)
26
- * [Choose accessor over `write_attribute` for `attributes=`](https://github.com/jnunemaker/toystore/commit/65a8f81d933f0ebe1f13c9b1ff776f9e20333cb3)
27
-
28
- * 0.10.0
29
- * [Reference proxy api changes](https://github.com/jnunemaker/toystore/pull/5) thanks to jakehow
30
- * [Support for inheritance](https://github.com/jnunemaker/toystore/pull/4)
31
- * [Pass model class to callable default](https://github.com/jnunemaker/toystore/commit/45eff74fb712e5b2a437e3c09b382421fc05539d)
32
- * [Added #hash](https://github.com/jnunemaker/toystore/commit/0769f548be669ad1b456cb1b8e11e394e0fee303)
33
- * [Added pretty inspect for classes](https://github.com/jnunemaker/toystore/commit/2fdc18b8d8428a932c1e5eeafa6a4db2269f1473)
34
- * [Always show id first in #inspect](https://github.com/jnunemaker/toystore/commit/145312b961a519ab84b010d37be075d85fa290a2)
35
- * [Moved object serialization into Toy::Object](https://github.com/jnunemaker/toystore/commit/d9431557f0f12c4e171fc888f3eb846fb631d4aa)
36
-
37
- * 0.8.3 => 0.9.0
38
- * [Changed from `store` to `adapter`](https://github.com/jnunemaker/toystore/pull/1)
39
- * [Embedded objects were removed](https://github.com/jnunemaker/toystore/pull/2)
40
- * [Defaulted `adapter` to memory and removed `has_adapter?`](https://github.com/jnunemaker/toystore/commit/64268705fcb22d82eb7ac3e934508770ceb1f101)
41
- * [Introduced Toy::Object](https://github.com/jnunemaker/toystore/commit/f22fddff96b388db3bd22f36cc1cc29b28d0ae5e).
42
- * [Default Identity Map to off](https://github.com/jnunemaker/toystore/compare/02b652b4dbd4a652bf3d788fbf8cf7d0bae805f6...5cec60be60f9bf749964d5c2d437189287d6d837)
43
- * Removed several class methods related to identity map as well (identity_map_on/off/on?/off?/etc)
5
+ ## 0.13.0
6
+
7
+ * Update to adapter 0.7.0
8
+ * Removed .get_multi
9
+ * Change read multiple methods to take array with options.
10
+ * Allow passing options to read methods
11
+ * Added rails model/scaffold generators
12
+ * Delegate #to_key to key factory. Allows non-Stringish ids to work with to_key.
13
+ * Removed plugins
14
+ * Removed Toy.clear and Toy.reset
15
+
16
+ ## 0.12.0
17
+
18
+ * Ruby 1.9 only. Officially not supporting Ruby 1.8.x.
19
+ * Added :native_uuid key factory for using when your data store supports them.
20
+ * Aliased .find and .read to .get.
21
+ * Aliased .find_multiple and .read_multiple to .get_multiple.
22
+
23
+ ## 0.10.x => 0.11.0
24
+
25
+ * Added get_multiple which returns Hash of id pointed at instance.
26
+ * Aliased get_multi to get_multiple which means it now returns Hash instead of Array.
27
+ * Updated to latest version of adapter.
28
+
29
+ ## 0.10.4
30
+
31
+ * Support for ActiveSupport/ActiveModel 3.2.*
32
+
33
+ ## 0.10.3
34
+
35
+ * More liberal uuid gem dependency version
36
+
37
+ ## 0.10.2
38
+
39
+ * [Allow changing list attribute type](https://github.com/jnunemaker/toystore/commit/a5b1a944622509c32688d2e56088a7d7aa6fc0b3)
40
+ * [No longer include id in `persisted_attributes`](https://github.com/jnunemaker/toystore/commit/9f713311ebf174e314db700392e27af86ca00662)
41
+ * [Allow overriding `persist` safely](https://github.com/jnunemaker/toystore/commit/304e50c7e4ac11a365ae00f5d4caed722de31909)
42
+ * [Choose accessor over `write_attribute` for `attributes=`](https://github.com/jnunemaker/toystore/commit/65a8f81d933f0ebe1f13c9b1ff776f9e20333cb3)
43
+
44
+ ## 0.10.0
45
+
46
+ * [Reference proxy api changes](https://github.com/jnunemaker/toystore/pull/5) thanks to jakehow
47
+ * [Support for inheritance](https://github.com/jnunemaker/toystore/pull/4)
48
+ * [Pass model class to callable default](https://github.com/jnunemaker/toystore/commit/45eff74fb712e5b2a437e3c09b382421fc05539d)
49
+ * [Added #hash](https://github.com/jnunemaker/toystore/commit/0769f548be669ad1b456cb1b8e11e394e0fee303)
50
+ * [Added pretty inspect for classes](https://github.com/jnunemaker/toystore/commit/2fdc18b8d8428a932c1e5eeafa6a4db2269f1473)
51
+ * [Always show id first in #inspect](https://github.com/jnunemaker/toystore/commit/145312b961a519ab84b010d37be075d85fa290a2)
52
+ * [Moved object serialization into Toy::Object](https://github.com/jnunemaker/toystore/commit/d9431557f0f12c4e171fc888f3eb846fb631d4aa)
53
+
54
+ ## 0.8.3 => 0.9.0
55
+
56
+ * [Changed from `store` to `adapter`](https://github.com/jnunemaker/toystore/pull/1)
57
+ * [Embedded objects were removed](https://github.com/jnunemaker/toystore/pull/2)
58
+ * [Defaulted `adapter` to memory and removed `has_adapter?`](https://github.com/jnunemaker/toystore/commit/64268705fcb22d82eb7ac3e934508770ceb1f101)
59
+ * [Introduced Toy::Object](https://github.com/jnunemaker/toystore/commit/f22fddff96b388db3bd22f36cc1cc29b28d0ae5e).
60
+ * [Default Identity Map to off](https://github.com/jnunemaker/toystore/compare/02b652b4dbd4a652bf3d788fbf8cf7d0bae805f6...5cec60be60f9bf749964d5c2d437189287d6d837)
61
+ * Removed several class methods related to identity map as well (identity_map_on/off/on?/off?/etc)
data/README.md CHANGED
@@ -85,7 +85,7 @@ pp person.role # "guest"
85
85
 
86
86
  # Querying
87
87
  pp Person.get(john.id)
88
- pp Person.get_multiple(john.id)
88
+ pp Person.get_multiple([john.id])
89
89
  pp Person.get('NOT HERE') # nil
90
90
  pp Person.get_or_new('NOT HERE') # new person with id of 'NOT HERE'
91
91
 
@@ -34,7 +34,7 @@ pp person.role # "guest"
34
34
 
35
35
  # Querying
36
36
  pp Person.get(john.id)
37
- pp Person.get_multiple(john.id)
37
+ pp Person.get_multiple([john.id])
38
38
  pp Person.get('NOT HERE') # nil
39
39
  pp Person.get_or_new('NOT HERE') # new person with id of 'NOT HERE'
40
40
 
@@ -0,0 +1,60 @@
1
+ require 'rails/generators/named_base'
2
+ require 'rails/generators/migration'
3
+ require 'rails/generators/active_model'
4
+
5
+ module Toystore
6
+ module Generators
7
+ class Base < ::Rails::Generators::NamedBase
8
+ def self.source_root
9
+ @_toystore_source_root ||= File.expand_path("../#{base_name}/#{generator_name}/templates", __FILE__)
10
+ end
11
+ end
12
+
13
+ class ActiveModel < ::Rails::Generators::ActiveModel
14
+ def self.all(klass)
15
+ "raise 'all is not supported'"
16
+ end
17
+
18
+ def self.find(klass, params=nil)
19
+ "#{klass}.find(#{params})"
20
+ end
21
+
22
+ def self.build(klass, params=nil)
23
+ if params
24
+ "#{klass}.new(#{params})"
25
+ else
26
+ "#{klass}.new"
27
+ end
28
+ end
29
+
30
+ def save
31
+ "#{name}.save"
32
+ end
33
+
34
+ def update_attributes(params=nil)
35
+ "#{name}.update_attributes(#{params})"
36
+ end
37
+
38
+ def errors
39
+ "#{name}.errors"
40
+ end
41
+
42
+ def destroy
43
+ "#{name}.destroy"
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+ module Rails
50
+ module Generators
51
+ class GeneratedAttribute
52
+ # Override type_class to return correct for uuid and automatically camel
53
+ # case all other types.
54
+ def type_class
55
+ return 'SimpleUUID::UUID' if type.to_s == 'uuid'
56
+ return type.to_s.camelcase
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,20 @@
1
+ require 'generators/toystore'
2
+
3
+ module Toystore
4
+ module Generators
5
+ class ModelGenerator < Base
6
+ argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
7
+
8
+ check_class_collision
9
+
10
+ class_option :timestamps, :type => :boolean
11
+ class_option :parent, :type => :string, :desc => "The parent class for the generated model"
12
+
13
+ def create_model_file
14
+ template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
15
+ end
16
+
17
+ hook_for :test_framework
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,16 @@
1
+ class <%= class_name %><%= " < #{options[:parent].classify}" if options[:parent] %>
2
+ <%- unless options[:parent] -%>
3
+ include Toy::Store
4
+
5
+ # replace this with whatever adapter you want
6
+ adapter :memory, {}
7
+ <%- end -%>
8
+
9
+ <%- attributes.each do |attribute| -%>
10
+ attribute :<%= attribute.name %>, <%= attribute.type_class %>
11
+ <%- end -%>
12
+
13
+ <%- if options[:timestamps] -%>
14
+ timestamps
15
+ <%- end -%>
16
+ end
data/lib/toy.rb CHANGED
@@ -17,27 +17,6 @@ Dir[extensions_path + '**/*.rb'].each { |file| require(file) }
17
17
  module Toy
18
18
  extend self
19
19
 
20
- # Resets all tracking of things in memory. Useful for running
21
- # before each request in development mode with Rails and such.
22
- def reset
23
- IdentityMap.clear
24
- plugins.clear
25
- models.clear
26
- end
27
-
28
- # Clears all the adapters for all the models. Useful in specs/tests/etc.
29
- # Do not use in production, harty harr harr.
30
- #
31
- # Note: that if your models are auto-loaded like in Rails, you will need
32
- # to make sure they are loaded in order to clear them or ToyStore will
33
- # not be aware of their existence.
34
- def clear
35
- models.each do |model|
36
- model.adapter.clear
37
- end
38
- IdentityMap.clear
39
- end
40
-
41
20
  def logger
42
21
  @logger
43
22
  end
@@ -98,7 +77,6 @@ end
98
77
 
99
78
  require 'toy/identity_map'
100
79
  require 'toy/exceptions'
101
- require 'toy/plugins'
102
80
  require 'toy/object'
103
81
  require 'toy/store'
104
82
 
@@ -12,8 +12,8 @@ module Toy
12
12
  end
13
13
 
14
14
  class NotFound < Error
15
- def initialize(id)
16
- super("Could not find document with id: #{id.inspect}")
15
+ def initialize(*args)
16
+ super("Could not find document with: #{args.inspect}")
17
17
  end
18
18
  end
19
19
 
data/lib/toy/identity.rb CHANGED
@@ -38,5 +38,9 @@ module Toy
38
38
  end
39
39
  end
40
40
  end
41
+
42
+ def key_factory
43
+ self.class.key_factory
44
+ end
41
45
  end
42
46
  end
@@ -9,6 +9,10 @@ module Toy
9
9
  raise NotImplementedError, "#{self.class.name}#next_key isn't implemented."
10
10
  end
11
11
 
12
+ def to_key(object)
13
+ [object.id] if object.persisted?
14
+ end
15
+
12
16
  def eql?(other)
13
17
  self.class == other.class && key_type == other.key_type
14
18
  end
@@ -8,6 +8,10 @@ module Toy
8
8
  def next_key(object)
9
9
  SimpleUUID::UUID.new
10
10
  end
11
+
12
+ def to_key(object)
13
+ [object.id.to_guid] if object.persisted?
14
+ end
11
15
  end
12
16
  end
13
17
  end
@@ -44,7 +44,7 @@ module Toy
44
44
  end
45
45
 
46
46
  module ClassMethods
47
- def get(id)
47
+ def get(id, options = nil)
48
48
  get_from_identity_map(id) || super
49
49
  end
50
50
 
data/lib/toy/object.rb CHANGED
@@ -17,5 +17,9 @@ module Toy
17
17
  def persisted?
18
18
  false
19
19
  end
20
+
21
+ def to_key
22
+ key_factory.to_key(self)
23
+ end
20
24
  end
21
25
  end
data/lib/toy/querying.rb CHANGED
@@ -3,8 +3,8 @@ module Toy
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  module ClassMethods
6
- def get(id)
7
- if (attrs = adapter.read(id))
6
+ def get(id, options = nil)
7
+ if (attrs = adapter.read(id, options))
8
8
  load(id, attrs)
9
9
  end
10
10
  end
@@ -12,22 +12,21 @@ module Toy
12
12
  alias_method :read, :get
13
13
  alias_method :find, :get
14
14
 
15
- def get!(id)
16
- get(id) || raise(Toy::NotFound.new(id))
15
+ def get!(id, options = nil)
16
+ get(id, options) || raise(Toy::NotFound.new(id))
17
17
  end
18
18
 
19
19
  alias_method :read!, :get!
20
20
  alias_method :find!, :get!
21
21
 
22
- def get_multiple(*ids)
23
- result = adapter.read_multiple(*ids.flatten)
22
+ def get_multiple(ids, options = nil)
23
+ result = adapter.read_multiple(ids, options)
24
24
  result.each do |id, attrs|
25
25
  result[id] = attrs.nil? ? nil : load(id, attrs)
26
26
  end
27
27
  result
28
28
  end
29
29
 
30
- alias_method :get_multi, :get_multiple
31
30
  alias_method :read_multiple, :get_multiple
32
31
  alias_method :find_multiple, :get_multiple
33
32
 
@@ -39,8 +38,8 @@ module Toy
39
38
  get(id) || create(:id => id)
40
39
  end
41
40
 
42
- def key?(id)
43
- adapter.key?(id)
41
+ def key?(id, options = nil)
42
+ adapter.key?(id, options)
44
43
  end
45
44
  alias :has_key? :key?
46
45
 
data/lib/toy/store.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  module Toy
2
2
  module Store
3
3
  extend ActiveSupport::Concern
4
- extend Plugins
5
4
 
6
5
  include Toy::Object
7
6
  include Persistence
@@ -19,7 +19,6 @@ module Toy
19
19
  end
20
20
 
21
21
  def save(options={})
22
- options.assert_valid_keys(:validate)
23
22
  !options.fetch(:validate, true) || valid? ? super : false
24
23
  end
25
24
 
data/lib/toy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Toy
2
- VERSION = "0.12.0"
2
+ VERSION = "0.13.0"
3
3
  end
data/spec/helper.rb CHANGED
@@ -36,8 +36,6 @@ RSpec.configure do |c|
36
36
 
37
37
  c.before(:each) do
38
38
  Toy::IdentityMap.enabled = false
39
- Toy.clear
40
- Toy.reset
41
39
  Toy.key_factory = nil
42
40
  end
43
41
  end
@@ -116,7 +116,7 @@ describe Toy::IdentityMap do
116
116
  user = User.create
117
117
  user.should be_in_identity_map
118
118
  Toy::IdentityMap.enabled = false
119
- user.adapter.should_receive(:read).with(user.id).and_return(user.persisted_attributes)
119
+ user.adapter.should_receive(:read).with(user.id, nil).and_return(user.persisted_attributes)
120
120
  User.get(user.id)
121
121
  end
122
122
  end
@@ -159,4 +159,4 @@ describe Toy::IdentityMap do
159
159
  Toy::IdentityMap.repository.should be_empty
160
160
  end
161
161
  end
162
- end
162
+ end
@@ -45,6 +45,12 @@ describe Toy::Identity do
45
45
  end
46
46
  end
47
47
 
48
+ describe "#key_factory" do
49
+ it "returns class key factory" do
50
+ User.new.key_factory.should eq(User.key_factory)
51
+ end
52
+ end
53
+
48
54
  describe "initializing the id" do
49
55
  it "should pass use pass the new object" do
50
56
  Piece.attribute(:name, String)
@@ -574,7 +574,7 @@ describe Toy::List do
574
574
  it "returns game if found" do
575
575
  lambda {
576
576
  @user.games.get!('does-not-exist')
577
- }.should raise_error(Toy::NotFound, 'Could not find document with id: "does-not-exist"')
577
+ }.should raise_error(Toy::NotFound, 'Could not find document with: ["does-not-exist"]')
578
578
  end
579
579
 
580
580
  it "raises exception if not found" do
@@ -35,6 +35,22 @@ describe Toy::Object do
35
35
  it "returns nil if not persisted" do
36
36
  User.new.to_key.should be_nil
37
37
  end
38
+
39
+ context "with native uuid" do
40
+ before do
41
+ User.key :native_uuid
42
+ end
43
+
44
+ it "returns array with guid if persisted" do
45
+ user = User.new
46
+ user.stub(:persisted?).and_return(true)
47
+ user.to_key.should == [user.id.to_guid]
48
+ end
49
+
50
+ it "returns nil if not persisted" do
51
+ User.new.to_key.should be_nil
52
+ end
53
+ end
38
54
  end
39
55
 
40
56
  describe "#to_param" do
@@ -16,6 +16,12 @@ describe Toy::Querying do
16
16
  it "returns nil if not found" do
17
17
  User.send(method_name, '1').should be_nil
18
18
  end
19
+
20
+ it "passes options to adapter read" do
21
+ john = User.create(:name => 'John')
22
+ User.adapter.should_receive(:read).with(john.id, my: 'options').and_return({'name' => 'John'})
23
+ User.send(method_name, john.id, my: 'options')
24
+ end
19
25
  end
20
26
 
21
27
  shared_examples_for "adapter read and load instance with bang" do |method_name|
@@ -27,7 +33,13 @@ describe Toy::Querying do
27
33
  it "raises not found exception if not found" do
28
34
  lambda {
29
35
  User.send(method_name, '1')
30
- }.should raise_error(Toy::NotFound, 'Could not find document with id: "1"')
36
+ }.should raise_error(Toy::NotFound, 'Could not find document with: ["1"]')
37
+ end
38
+
39
+ it "passes options to adapter read" do
40
+ john = User.create(:name => 'John')
41
+ User.adapter.should_receive(:read).with(john.id, my: 'options').and_return({'name' => 'John'})
42
+ User.send(method_name, john.id, my: 'options')
31
43
  end
32
44
  end
33
45
 
@@ -35,12 +47,29 @@ describe Toy::Querying do
35
47
  it "returns Hash of ids pointed at result" do
36
48
  john = User.create(:name => 'John')
37
49
  steve = User.create(:name => 'Steve')
38
- User.send(method_name, john.id, steve.id, 'foo').should == {
50
+ User.send(method_name, [john.id, steve.id, 'foo']).should == {
39
51
  john.id => john,
40
52
  steve.id => steve,
41
53
  'foo' => nil,
42
54
  }
43
55
  end
56
+
57
+ it "passes options to adapter read_multiple" do
58
+ john = User.create(:name => 'John')
59
+ User.adapter.should_receive(:read_multiple).with([john.id], my: 'options').and_return({john.id => {'name' => 'John'}})
60
+ User.send(method_name, [john.id], my: 'options')
61
+ end
62
+ end
63
+
64
+ shared_examples_for "adapter key?" do |method_name|
65
+ it "returns true if key exists" do
66
+ user = User.create(:name => 'John')
67
+ User.send(method_name, user.id).should be_true
68
+ end
69
+
70
+ it "returns false if key does not exist" do
71
+ User.send(method_name, 'taco:bell:tacos').should be_false
72
+ end
44
73
  end
45
74
 
46
75
  describe ".get" do
@@ -79,10 +108,6 @@ describe Toy::Querying do
79
108
  include_examples "adapter read_multiple and load instances", :find_multiple
80
109
  end
81
110
 
82
- describe ".get_multi" do
83
- include_examples "adapter read_multiple and load instances", :get_multi
84
- end
85
-
86
111
  describe ".get_or_new" do
87
112
  it "returns found" do
88
113
  user = User.create
@@ -110,25 +135,11 @@ describe Toy::Querying do
110
135
  end
111
136
 
112
137
  describe ".key?" do
113
- it "returns true if key exists" do
114
- user = User.create(:name => 'John')
115
- User.key?(user.id).should be_true
116
- end
117
-
118
- it "returns false if key does not exist" do
119
- User.key?('taco:bell:tacos').should be_false
120
- end
138
+ include_examples "adapter key?", :key?
121
139
  end
122
140
 
123
141
  describe ".has_key?" do
124
- it "returns true if key exists" do
125
- user = User.create(:name => 'John')
126
- User.has_key?(user.id).should be_true
127
- end
128
-
129
- it "returns false if key does not exist" do
130
- User.has_key?('taco:bell:tacos').should be_false
131
- end
142
+ include_examples "adapter key?", :has_key?
132
143
  end
133
144
 
134
145
  describe ".load" do
@@ -82,12 +82,6 @@ describe Toy::Validations do
82
82
  end
83
83
  end
84
84
 
85
- context "with invalid option" do
86
- it "raises error" do
87
- lambda { User.new.save(:foobar => '') }.should raise_error
88
- end
89
- end
90
-
91
85
  context "with :validate option" do
92
86
  before do
93
87
  User.validates_presence_of(:name)
@@ -147,4 +141,4 @@ describe Toy::Validations do
147
141
  end
148
142
  end
149
143
  end
150
- end
144
+ end
data/spec/toy_spec.rb CHANGED
@@ -3,21 +3,6 @@ require 'helper'
3
3
  describe Toy do
4
4
  uses_constants('User', 'Game')
5
5
 
6
- describe ".clear" do
7
- it "can clear all the adapters in one magical moment" do
8
- user = User.create!
9
- game = Game.create!
10
- Toy.clear
11
- User.get(user.id).should be_nil
12
- Game.get(game.id).should be_nil
13
- end
14
-
15
- it "does not raise error when no default adapter set" do
16
- klass = Class.new { include Toy::Store }
17
- lambda { Toy.clear }.should_not raise_error
18
- end
19
- end
20
-
21
6
  describe ".logger" do
22
7
  before do
23
8
  @logger = Toy.logger
@@ -46,4 +31,4 @@ describe Toy do
46
31
  Toy.key_factory.should be_instance_of(Toy::Identity::UUIDKeyFactory)
47
32
  end
48
33
  end
49
- end
34
+ end
data/toystore.gemspec CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
17
17
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
18
  s.require_paths = ["lib"]
19
19
 
20
- s.add_dependency 'adapter', '~> 0.6.0'
20
+ s.add_dependency 'adapter', '~> 0.7.0'
21
21
  s.add_dependency 'activemodel', '~> 3.0'
22
22
  s.add_dependency 'activesupport', '~> 3.0'
23
23
  s.add_dependency 'simple_uuid', '~> 0.2'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toystore
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.13.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-11-14 00:00:00.000000000 Z
13
+ date: 2012-11-19 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: adapter
@@ -19,7 +19,7 @@ dependencies:
19
19
  requirements:
20
20
  - - ~>
21
21
  - !ruby/object:Gem::Version
22
- version: 0.6.0
22
+ version: 0.7.0
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -27,7 +27,7 @@ dependencies:
27
27
  requirements:
28
28
  - - ~>
29
29
  - !ruby/object:Gem::Version
30
- version: 0.6.0
30
+ version: 0.7.0
31
31
  - !ruby/object:Gem::Dependency
32
32
  name: activemodel
33
33
  requirement: !ruby/object:Gem::Requirement
@@ -106,6 +106,9 @@ files:
106
106
  - examples/riak.rb
107
107
  - gemfiles/rails_3_0.gemfile
108
108
  - gemfiles/rails_3_1.gemfile
109
+ - lib/generators/toystore.rb
110
+ - lib/generators/toystore/model/model_generator.rb
111
+ - lib/generators/toystore/model/templates/model.rb
109
112
  - lib/toy.rb
110
113
  - lib/toy/association_serialization.rb
111
114
  - lib/toy/attribute.rb
@@ -143,7 +146,6 @@ files:
143
146
  - lib/toy/middleware/identity_map.rb
144
147
  - lib/toy/object.rb
145
148
  - lib/toy/persistence.rb
146
- - lib/toy/plugins.rb
147
149
  - lib/toy/proxies/list.rb
148
150
  - lib/toy/proxies/proxy.rb
149
151
  - lib/toy/querying.rb
@@ -200,7 +202,6 @@ files:
200
202
  - spec/toy/middleware/identity_map_spec.rb
201
203
  - spec/toy/object_spec.rb
202
204
  - spec/toy/persistence_spec.rb
203
- - spec/toy/plugins_spec.rb
204
205
  - spec/toy/querying_spec.rb
205
206
  - spec/toy/reference_spec.rb
206
207
  - spec/toy/references_spec.rb
@@ -225,7 +226,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
225
226
  version: '0'
226
227
  segments:
227
228
  - 0
228
- hash: -1651404938588113
229
+ hash: -1758812902377714196
229
230
  required_rubygems_version: !ruby/object:Gem::Requirement
230
231
  none: false
231
232
  requirements:
@@ -234,7 +235,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
234
235
  version: '0'
235
236
  segments:
236
237
  - 0
237
- hash: -1651404938588113
238
+ hash: -1758812902377714196
238
239
  requirements: []
239
240
  rubyforge_project:
240
241
  rubygems_version: 1.8.23
@@ -284,7 +285,6 @@ test_files:
284
285
  - spec/toy/middleware/identity_map_spec.rb
285
286
  - spec/toy/object_spec.rb
286
287
  - spec/toy/persistence_spec.rb
287
- - spec/toy/plugins_spec.rb
288
288
  - spec/toy/querying_spec.rb
289
289
  - spec/toy/reference_spec.rb
290
290
  - spec/toy/references_spec.rb
data/lib/toy/plugins.rb DELETED
@@ -1,32 +0,0 @@
1
- module Toy
2
- def models
3
- Toy::Store.direct_descendants
4
- end
5
-
6
- def plugins
7
- Toy::Store.plugins
8
- end
9
-
10
- def plugin(mod)
11
- Toy::Store.plugin(mod)
12
- end
13
-
14
- module Plugins
15
- include ActiveSupport::DescendantsTracker
16
-
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
30
- end
31
- end
32
- end
@@ -1,48 +0,0 @@
1
- require 'helper'
2
-
3
- describe Toy::Plugins do
4
- uses_constants('User', 'Game')
5
-
6
- it "keeps track of class that include toy store" do
7
- Toy.models.should == [User, Game]
8
- end
9
-
10
- describe ".plugin" do
11
- before do
12
- @mod = Module.new {
13
- extend ActiveSupport::Concern
14
-
15
- def bar
16
- 'bar'
17
- end
18
- }
19
-
20
- class_methods_module = Module.new do
21
- def foo
22
- 'foo'
23
- end
24
- end
25
-
26
- @mod.const_set :ClassMethods, class_methods_module
27
-
28
- Toy.plugin(@mod)
29
- end
30
-
31
- it "includes module in all models" do
32
- [User, Game].each do |model|
33
- model.foo.should == 'foo'
34
- model.new.bar.should == 'bar'
35
- end
36
- end
37
-
38
- it "adds plugin to plugins" do
39
- Toy.plugins.should == [@mod]
40
- end
41
-
42
- it "adds plugins to classes declared after plugin was called" do
43
- klass = ToyStore()
44
- klass.foo.should == 'foo'
45
- klass.new.bar.should == 'bar'
46
- end
47
- end
48
- end