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 +59 -41
- data/README.md +1 -1
- data/examples/plain_old_object_on_roids.rb +1 -1
- data/lib/generators/toystore.rb +60 -0
- data/lib/generators/toystore/model/model_generator.rb +20 -0
- data/lib/generators/toystore/model/templates/model.rb +16 -0
- data/lib/toy.rb +0 -22
- data/lib/toy/exceptions.rb +2 -2
- data/lib/toy/identity.rb +4 -0
- data/lib/toy/identity/abstract_key_factory.rb +4 -0
- data/lib/toy/identity/native_uuid_key_factory.rb +4 -0
- data/lib/toy/identity_map.rb +1 -1
- data/lib/toy/object.rb +4 -0
- data/lib/toy/querying.rb +8 -9
- data/lib/toy/store.rb +0 -1
- data/lib/toy/validations.rb +0 -1
- data/lib/toy/version.rb +1 -1
- data/spec/helper.rb +0 -2
- data/spec/toy/identity_map_spec.rb +2 -2
- data/spec/toy/identity_spec.rb +6 -0
- data/spec/toy/list_spec.rb +1 -1
- data/spec/toy/object_spec.rb +16 -0
- data/spec/toy/querying_spec.rb +33 -22
- data/spec/toy/validations_spec.rb +1 -7
- data/spec/toy_spec.rb +1 -16
- data/toystore.gemspec +1 -1
- metadata +9 -9
- data/lib/toy/plugins.rb +0 -32
- data/spec/toy/plugins_spec.rb +0 -48
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
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
*
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
*
|
17
|
-
|
18
|
-
|
19
|
-
*
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
*
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
@@ -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
|
|
data/lib/toy/exceptions.rb
CHANGED
data/lib/toy/identity.rb
CHANGED
data/lib/toy/identity_map.rb
CHANGED
data/lib/toy/object.rb
CHANGED
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(
|
23
|
-
result = adapter.read_multiple(
|
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
data/lib/toy/validations.rb
CHANGED
data/lib/toy/version.rb
CHANGED
data/spec/helper.rb
CHANGED
@@ -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
|
data/spec/toy/identity_spec.rb
CHANGED
@@ -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)
|
data/spec/toy/list_spec.rb
CHANGED
@@ -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
|
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
|
data/spec/toy/object_spec.rb
CHANGED
@@ -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
|
data/spec/toy/querying_spec.rb
CHANGED
@@ -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
|
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
|
-
|
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
|
-
|
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.
|
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.
|
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-
|
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.
|
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.
|
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: -
|
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: -
|
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
|
data/spec/toy/plugins_spec.rb
DELETED
@@ -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
|