dynamoid 0.1.1 → 0.1.2
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/Dynamoid.gemspec +2 -6
- data/README.markdown +28 -4
- data/VERSION +1 -1
- data/lib/dynamoid.rb +4 -1
- data/lib/dynamoid/adapter.rb +79 -6
- data/lib/dynamoid/adapter/aws_sdk.rb +9 -7
- data/lib/dynamoid/adapter/local.rb +1 -1
- data/lib/dynamoid/associations.rb +1 -1
- data/lib/dynamoid/associations/association.rb +26 -4
- data/lib/dynamoid/associations/belongs_to.rb +8 -0
- data/lib/dynamoid/components.rb +3 -1
- data/lib/dynamoid/config.rb +3 -0
- data/lib/dynamoid/criteria/chain.rb +1 -1
- data/lib/dynamoid/document.rb +18 -15
- data/lib/dynamoid/fields.rb +39 -4
- data/lib/dynamoid/finders.rb +3 -3
- data/lib/dynamoid/indexes.rb +10 -17
- data/lib/dynamoid/persistence.rb +92 -16
- data/spec/app/models/magazine.rb +2 -0
- data/spec/app/models/subscription.rb +2 -0
- data/spec/dynamoid/adapter_spec.rb +76 -0
- data/spec/dynamoid/associations/association_spec.rb +22 -0
- data/spec/dynamoid/associations/belongs_to_spec.rb +8 -0
- data/spec/dynamoid/criteria_spec.rb +3 -0
- data/spec/dynamoid/document_spec.rb +11 -2
- data/spec/dynamoid/fields_spec.rb +57 -0
- data/spec/dynamoid/indexes_spec.rb +7 -15
- data/spec/dynamoid/persistence_spec.rb +34 -4
- data/spec/spec_helper.rb +5 -5
- metadata +21 -25
- data/lib/dynamoid/attributes.rb +0 -37
- data/lib/dynamoid/relations.rb +0 -21
- data/spec/dynamoid/attributes_spec.rb +0 -46
- data/spec/dynamoid/relations_spec.rb +0 -6
@@ -2,7 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
2
|
|
3
3
|
describe "Dynamoid::Indexes" do
|
4
4
|
|
5
|
-
before do
|
5
|
+
before(:all) do
|
6
6
|
User.create_indexes
|
7
7
|
end
|
8
8
|
|
@@ -22,40 +22,32 @@ describe "Dynamoid::Indexes" do
|
|
22
22
|
User.index_table_name([:email, :name]).should == 'dynamoid_tests_index_user_emails_and_names'
|
23
23
|
end
|
24
24
|
|
25
|
-
it 'creates a key name for a table index' do
|
26
|
-
User.index_key_name([:email, :name]).should == 'user_emails_and_names'
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'creates a table after an index is created' do
|
30
|
-
User.send(:index, :password)
|
31
|
-
|
32
|
-
User.table_exists?(User.index_table_name([:password])).should be_true
|
33
|
-
end
|
34
|
-
|
35
25
|
it 'assembles a hashed value for the key of an index' do
|
36
26
|
@user = User.create(:name => 'Josh', :email => 'josh@joshsymonds.com')
|
37
27
|
|
38
|
-
@user.key_for_index([:email, :name]).should ==
|
28
|
+
@user.key_for_index([:email, :name]).should == "Josh.josh@joshsymonds.com"
|
39
29
|
end
|
40
30
|
|
41
31
|
it 'saves indexes to their tables' do
|
42
32
|
@user = User.create(:name => 'Josh')
|
43
33
|
|
44
|
-
Dynamoid::Adapter.
|
34
|
+
Dynamoid::Adapter.read("dynamoid_tests_index_user_names", @user.key_for_index([:name]))[:id].should == @user.key_for_index([:name])
|
35
|
+
Dynamoid::Adapter.read("dynamoid_tests_index_user_names", @user.key_for_index([:name]))[:ids].should == Set[@user.id]
|
45
36
|
end
|
46
37
|
|
47
38
|
it 'saves multiple indexes with the same value as an array' do
|
48
39
|
@user1 = User.create(:name => 'Josh')
|
49
40
|
@user2 = User.create(:name => 'Josh')
|
50
41
|
|
51
|
-
Dynamoid::Adapter.
|
42
|
+
Dynamoid::Adapter.read("dynamoid_tests_index_user_names", @user1.key_for_index([:name]))[:id].should == @user1.key_for_index([:name])
|
43
|
+
Dynamoid::Adapter.read("dynamoid_tests_index_user_names", @user1.key_for_index([:name]))[:ids].should == Set[@user2.id, @user1.id]
|
52
44
|
end
|
53
45
|
|
54
46
|
it 'deletes indexes when the object is destroyed' do
|
55
47
|
@user = User.create(:name => 'Josh')
|
56
48
|
@user.destroy
|
57
49
|
|
58
|
-
Dynamoid::Adapter.
|
50
|
+
Dynamoid::Adapter.read("dynamoid_tests_index_user_names", @user.key_for_index([:name]))[:id].should == @user.key_for_index([:name])
|
59
51
|
end
|
60
52
|
|
61
53
|
end
|
@@ -3,6 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
3
3
|
describe "Dynamoid::Persistence" do
|
4
4
|
|
5
5
|
before do
|
6
|
+
Random.stubs(:rand).with(Dynamoid::Config.partition_size).returns(0)
|
6
7
|
@address = Address.new
|
7
8
|
end
|
8
9
|
|
@@ -27,18 +28,17 @@ describe "Dynamoid::Persistence" do
|
|
27
28
|
end
|
28
29
|
end
|
29
30
|
|
30
|
-
|
31
31
|
it 'assigns itself an id on save' do
|
32
32
|
@address.save
|
33
33
|
|
34
|
-
Dynamoid::Adapter.
|
34
|
+
Dynamoid::Adapter.read("dynamoid_tests_addresses", @address.id)[:id].should == @address.id
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'assigns itself an id on save only if it does not have one' do
|
38
38
|
@address.id = 'test123'
|
39
39
|
@address.save
|
40
40
|
|
41
|
-
Dynamoid::Adapter.
|
41
|
+
Dynamoid::Adapter.read("dynamoid_tests_addresses", 'test123').should_not be_empty
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'has a table name' do
|
@@ -56,7 +56,37 @@ describe "Dynamoid::Persistence" do
|
|
56
56
|
@user = User.create(:name => 'Josh')
|
57
57
|
@user.destroy
|
58
58
|
|
59
|
-
Dynamoid::Adapter.
|
59
|
+
Dynamoid::Adapter.read("dynamoid_tests_users", @user.id).should be_nil
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'keeps string attributes as strings' do
|
63
|
+
@user = User.new(:name => 'Josh')
|
64
|
+
@user.send(:dump)[:name].should == 'Josh'
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'dumps datetime attributes' do
|
68
|
+
@user = User.create(:name => 'Josh')
|
69
|
+
@user.send(:dump)[:name].should == 'Josh'
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'dumps integer attributes' do
|
73
|
+
@subscription = Subscription.create(:length => 10)
|
74
|
+
@subscription.send(:dump)[:length].should == 10
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'dumps set attributes' do
|
78
|
+
@subscription = Subscription.create(:length => 10)
|
79
|
+
@magazine = @subscription.magazine.create
|
80
|
+
|
81
|
+
@subscription.send(:dump)[:magazine_ids].should == Set[@magazine.id]
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'loads attributes from a hash' do
|
85
|
+
@time = DateTime.now
|
86
|
+
@hash = {:name => 'Josh', :created_at => @time.to_f}
|
87
|
+
|
88
|
+
User.undump(@hash)[:name].should == 'Josh'
|
89
|
+
User.undump(@hash)[:created_at].to_f == @time.to_f
|
60
90
|
end
|
61
91
|
|
62
92
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -41,11 +41,11 @@ RSpec.configure do |config|
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
44
|
+
config.after(:suite) do
|
45
|
+
Dynamoid::Adapter.list_tables.each do |table|
|
46
|
+
Dynamoid::Adapter.delete_table(table) if table =~ /^#{Dynamoid::Config.namespace}/
|
47
|
+
end
|
48
|
+
end
|
49
49
|
else
|
50
50
|
config.before(:each) do
|
51
51
|
Dynamoid::Adapter.reset_data
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dynamoid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-03-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|
16
|
-
requirement: &
|
16
|
+
requirement: &70138865789600 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70138865789600
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: tzinfo
|
27
|
-
requirement: &
|
27
|
+
requirement: &70138865788440 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70138865788440
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: aws-sdk
|
38
|
-
requirement: &
|
38
|
+
requirement: &70138865787560 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70138865787560
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: mocha
|
49
|
-
requirement: &
|
49
|
+
requirement: &70138865787060 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70138865787060
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rake
|
60
|
-
requirement: &
|
60
|
+
requirement: &70138865786540 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70138865786540
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
|
-
requirement: &
|
71
|
+
requirement: &70138865785960 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70138865785960
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: bundler
|
82
|
-
requirement: &
|
82
|
+
requirement: &70138865785300 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70138865785300
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: jeweler
|
93
|
-
requirement: &
|
93
|
+
requirement: &70138865807640 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ! '>='
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: '0'
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *70138865807640
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: rcov
|
104
|
-
requirement: &
|
104
|
+
requirement: &70138865806900 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ! '>='
|
@@ -109,7 +109,7 @@ dependencies:
|
|
109
109
|
version: '0'
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *70138865806900
|
113
113
|
description: Dynamoid is an ORM for Amazon's DynamoDB that supports offline development,
|
114
114
|
associations, querying, and everything else you'd expect from an ActiveRecord-style
|
115
115
|
replacement.
|
@@ -139,7 +139,6 @@ files:
|
|
139
139
|
- lib/dynamoid/associations/has_and_belongs_to_many.rb
|
140
140
|
- lib/dynamoid/associations/has_many.rb
|
141
141
|
- lib/dynamoid/associations/has_one.rb
|
142
|
-
- lib/dynamoid/attributes.rb
|
143
142
|
- lib/dynamoid/components.rb
|
144
143
|
- lib/dynamoid/config.rb
|
145
144
|
- lib/dynamoid/config/options.rb
|
@@ -151,7 +150,6 @@ files:
|
|
151
150
|
- lib/dynamoid/finders.rb
|
152
151
|
- lib/dynamoid/indexes.rb
|
153
152
|
- lib/dynamoid/persistence.rb
|
154
|
-
- lib/dynamoid/relations.rb
|
155
153
|
- spec/app/models/address.rb
|
156
154
|
- spec/app/models/magazine.rb
|
157
155
|
- spec/app/models/sponsor.rb
|
@@ -166,7 +164,6 @@ files:
|
|
166
164
|
- spec/dynamoid/associations/has_many_spec.rb
|
167
165
|
- spec/dynamoid/associations/has_one_spec.rb
|
168
166
|
- spec/dynamoid/associations_spec.rb
|
169
|
-
- spec/dynamoid/attributes_spec.rb
|
170
167
|
- spec/dynamoid/config_spec.rb
|
171
168
|
- spec/dynamoid/criteria/chain_spec.rb
|
172
169
|
- spec/dynamoid/criteria_spec.rb
|
@@ -175,7 +172,6 @@ files:
|
|
175
172
|
- spec/dynamoid/finders_spec.rb
|
176
173
|
- spec/dynamoid/indexes_spec.rb
|
177
174
|
- spec/dynamoid/persistence_spec.rb
|
178
|
-
- spec/dynamoid/relations_spec.rb
|
179
175
|
- spec/dynamoid_spec.rb
|
180
176
|
- spec/spec_helper.rb
|
181
177
|
homepage: http://github.com/Veraticus/Dynamoid
|
@@ -193,7 +189,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
193
189
|
version: '0'
|
194
190
|
segments:
|
195
191
|
- 0
|
196
|
-
hash:
|
192
|
+
hash: 2498222871702438577
|
197
193
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
198
194
|
none: false
|
199
195
|
requirements:
|
data/lib/dynamoid/attributes.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
module Dynamoid #:nodoc:
|
3
|
-
|
4
|
-
module Attributes
|
5
|
-
extend ActiveSupport::Concern
|
6
|
-
|
7
|
-
attr_accessor :attributes
|
8
|
-
alias :raw_attributes :attributes
|
9
|
-
|
10
|
-
def write_attribute(name, value)
|
11
|
-
attributes[name.to_sym] = value
|
12
|
-
end
|
13
|
-
alias :[]= :write_attribute
|
14
|
-
|
15
|
-
def read_attribute(name)
|
16
|
-
attributes[name.to_sym]
|
17
|
-
end
|
18
|
-
alias :[] :read_attribute
|
19
|
-
|
20
|
-
def update_attributes(attributes)
|
21
|
-
self.attributes = self.attributes.merge(attributes)
|
22
|
-
save
|
23
|
-
end
|
24
|
-
|
25
|
-
def update_attribute(attribute, value)
|
26
|
-
self.attributes[attribute] = value
|
27
|
-
save
|
28
|
-
end
|
29
|
-
|
30
|
-
module ClassMethods
|
31
|
-
def attributes
|
32
|
-
[self.fields + [:id]].flatten.uniq
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
data/lib/dynamoid/relations.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'digest/sha2'
|
2
|
-
|
3
|
-
# encoding: utf-8
|
4
|
-
module Dynamoid #:nodoc:
|
5
|
-
|
6
|
-
# Associate a document with another object: belongs_to, has_many, and has_and_belongs_to_many
|
7
|
-
module Relations
|
8
|
-
extend ActiveSupport::Concern
|
9
|
-
|
10
|
-
included do
|
11
|
-
class_attribute :indexes
|
12
|
-
|
13
|
-
self.indexes = []
|
14
|
-
end
|
15
|
-
|
16
|
-
module ClassMethods
|
17
|
-
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
-
|
3
|
-
describe "Dynamoid::Attributes" do
|
4
|
-
|
5
|
-
before do
|
6
|
-
@address = Address.create
|
7
|
-
@original_id = @address.id
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'should write an attribute correctly' do
|
11
|
-
@address.write_attribute(:city, 'Chicago')
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'should write an attribute with the alias' do
|
15
|
-
@address[:city] = 'Chicago'
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'should read a written attribute' do
|
19
|
-
@address.write_attribute(:city, 'Chicago')
|
20
|
-
@address.read_attribute(:city).should == 'Chicago'
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'should read a written attribute with the alias' do
|
24
|
-
@address.write_attribute(:city, 'Chicago')
|
25
|
-
@address[:city].should == 'Chicago'
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'should update all attributes' do
|
29
|
-
@address.expects(:save).once.returns(true)
|
30
|
-
@address.update_attributes(:city => 'Chicago')
|
31
|
-
@address[:city].should == 'Chicago'
|
32
|
-
@address.id.should == @original_id
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'should update one attribute' do
|
36
|
-
@address.expects(:save).once.returns(true)
|
37
|
-
@address.update_attribute(:city, 'Chicago')
|
38
|
-
@address[:city].should == 'Chicago'
|
39
|
-
@address.id.should == @original_id
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'returns all attributes' do
|
43
|
-
Address.attributes.should == [:id, :city]
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|