dynamoid 1.3.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +20 -4
- data/Appraisals +15 -0
- data/CHANGELOG.md +11 -0
- data/README.md +70 -1
- data/Rakefile +6 -0
- data/dynamoid.gemspec +16 -11
- data/gemfiles/rails_4_0.gemfile +9 -0
- data/gemfiles/rails_4_0.gemfile.lock +150 -0
- data/gemfiles/rails_4_1.gemfile +9 -0
- data/gemfiles/rails_4_1.gemfile.lock +154 -0
- data/gemfiles/rails_4_2.gemfile +9 -0
- data/gemfiles/rails_4_2.gemfile.lock +175 -0
- data/gemfiles/rails_5_0.gemfile +7 -0
- data/gemfiles/rails_5_0.gemfile.lock +180 -0
- data/lib/dynamoid.rb +6 -0
- data/lib/dynamoid/adapter.rb +1 -1
- data/lib/dynamoid/criteria/chain.rb +10 -2
- data/lib/dynamoid/document.rb +1 -1
- data/lib/dynamoid/errors.rb +9 -0
- data/lib/dynamoid/fields.rb +3 -2
- data/lib/dynamoid/persistence.rb +47 -34
- data/lib/dynamoid/railtie.rb +11 -0
- data/lib/dynamoid/tasks/database.rake +40 -0
- data/lib/dynamoid/tasks/database.rb +30 -0
- data/lib/dynamoid/version.rb +1 -1
- metadata +65 -39
data/lib/dynamoid/fields.rb
CHANGED
@@ -5,6 +5,7 @@ module Dynamoid #:nodoc:
|
|
5
5
|
module Fields
|
6
6
|
extend ActiveSupport::Concern
|
7
7
|
|
8
|
+
# Types allowed in indexes:
|
8
9
|
PERMITTED_KEY_TYPES = [
|
9
10
|
:number,
|
10
11
|
:integer,
|
@@ -145,14 +146,14 @@ module Dynamoid #:nodoc:
|
|
145
146
|
#
|
146
147
|
# @since 0.2.0
|
147
148
|
def set_created_at
|
148
|
-
self.created_at = DateTime.now if Dynamoid::Config.timestamps
|
149
|
+
self.created_at = DateTime.now.in_time_zone(Time.zone) if Dynamoid::Config.timestamps
|
149
150
|
end
|
150
151
|
|
151
152
|
# Automatically called during the save callback to set the updated_at time.
|
152
153
|
#
|
153
154
|
# @since 0.2.0
|
154
155
|
def set_updated_at
|
155
|
-
self.updated_at = DateTime.now if Dynamoid::Config.timestamps
|
156
|
+
self.updated_at = DateTime.now.in_time_zone(Time.zone) if Dynamoid::Config.timestamps
|
156
157
|
end
|
157
158
|
|
158
159
|
def set_type
|
data/lib/dynamoid/persistence.rb
CHANGED
@@ -52,6 +52,11 @@ module Dynamoid
|
|
52
52
|
Dynamoid.adapter.create_table(options[:table_name], options[:id], options)
|
53
53
|
end
|
54
54
|
|
55
|
+
# Deletes the table for the model
|
56
|
+
def delete_table
|
57
|
+
Dynamoid.adapter.delete_table(self.table_name)
|
58
|
+
end
|
59
|
+
|
55
60
|
def from_database(attrs = {})
|
56
61
|
clazz = attrs[:type] ? obj = attrs[:type].constantize : self
|
57
62
|
clazz.new(attrs).tap { |r| r.new_record = false }
|
@@ -131,6 +136,41 @@ module Dynamoid
|
|
131
136
|
end
|
132
137
|
end
|
133
138
|
|
139
|
+
def dump_field(value, options)
|
140
|
+
if (field_class = options[:type]).is_a?(Class)
|
141
|
+
if value.respond_to?(:dynamoid_dump)
|
142
|
+
value.dynamoid_dump
|
143
|
+
elsif field_class.respond_to?(:dynamoid_dump)
|
144
|
+
field_class.dynamoid_dump(value)
|
145
|
+
else
|
146
|
+
raise ArgumentError, "Neither #{field_class} nor #{value} support serialization for Dynamoid."
|
147
|
+
end
|
148
|
+
else
|
149
|
+
case options[:type]
|
150
|
+
when :string
|
151
|
+
!value.nil? ? value.to_s : nil
|
152
|
+
when :integer
|
153
|
+
!value.nil? ? Integer(value) : nil
|
154
|
+
when :number
|
155
|
+
!value.nil? ? value : nil
|
156
|
+
when :set
|
157
|
+
!value.nil? ? Set.new(value) : nil
|
158
|
+
when :array
|
159
|
+
!value.nil? ? value : nil
|
160
|
+
when :datetime
|
161
|
+
!value.nil? ? value.to_time.to_f : nil
|
162
|
+
when :serialized
|
163
|
+
options[:serializer] ? options[:serializer].dump(value) : value.to_yaml
|
164
|
+
when :raw
|
165
|
+
!value.nil? ? value : nil
|
166
|
+
when :boolean
|
167
|
+
!value.nil? ? value.to_s[0] : nil
|
168
|
+
else
|
169
|
+
raise ArgumentError, "Unknown type #{options[:type]}"
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
134
174
|
def dynamo_type(type)
|
135
175
|
if type.is_a?(Class)
|
136
176
|
type.respond_to?(:dynamoid_field_type) ? type.dynamoid_field_type : :string
|
@@ -241,10 +281,14 @@ module Dynamoid
|
|
241
281
|
#
|
242
282
|
# @since 0.2.0
|
243
283
|
def destroy
|
244
|
-
run_callbacks(:destroy) do
|
284
|
+
ret = run_callbacks(:destroy) do
|
245
285
|
self.delete
|
246
286
|
end
|
247
|
-
self
|
287
|
+
(ret == false) ? false : self
|
288
|
+
end
|
289
|
+
|
290
|
+
def destroy!
|
291
|
+
destroy || raise(Dynamoid::Errors::RecordNotDestroyed.new(self))
|
248
292
|
end
|
249
293
|
|
250
294
|
# Delete this object from the datastore.
|
@@ -287,38 +331,7 @@ module Dynamoid
|
|
287
331
|
#
|
288
332
|
# @since 0.2.0
|
289
333
|
def dump_field(value, options)
|
290
|
-
|
291
|
-
if value.respond_to?(:dynamoid_dump)
|
292
|
-
value.dynamoid_dump
|
293
|
-
elsif field_class.respond_to?(:dynamoid_dump)
|
294
|
-
field_class.dynamoid_dump(value)
|
295
|
-
else
|
296
|
-
raise ArgumentError, "Neither #{field_class} nor #{value} support serialization for Dynamoid."
|
297
|
-
end
|
298
|
-
else
|
299
|
-
case options[:type]
|
300
|
-
when :string
|
301
|
-
!value.nil? ? value.to_s : nil
|
302
|
-
when :integer
|
303
|
-
!value.nil? ? Integer(value) : nil
|
304
|
-
when :number
|
305
|
-
!value.nil? ? value : nil
|
306
|
-
when :set
|
307
|
-
!value.nil? ? Set.new(value) : nil
|
308
|
-
when :array
|
309
|
-
!value.nil? ? value : nil
|
310
|
-
when :datetime
|
311
|
-
!value.nil? ? value.to_time.to_f : nil
|
312
|
-
when :serialized
|
313
|
-
options[:serializer] ? options[:serializer].dump(value) : value.to_yaml
|
314
|
-
when :raw
|
315
|
-
!value.nil? ? value : nil
|
316
|
-
when :boolean
|
317
|
-
!value.nil? ? value.to_s[0] : nil
|
318
|
-
else
|
319
|
-
raise ArgumentError, "Unknown type #{options[:type]}"
|
320
|
-
end
|
321
|
-
end
|
334
|
+
self.class.dump_field(value, options)
|
322
335
|
end
|
323
336
|
|
324
337
|
# Persist the object into the datastore. Assign it an id first if it doesn't have one.
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'dynamoid'
|
2
|
+
require 'dynamoid/tasks/database'
|
3
|
+
|
4
|
+
MODELS = File.join(Rails.root, "app/models")
|
5
|
+
|
6
|
+
Dir[ File.join(MODELS, "*.rb") ].sort.each { |file| require file }
|
7
|
+
|
8
|
+
|
9
|
+
namespace :dynamoid do
|
10
|
+
desc "Creates DynamoDB tables, one for each of your Dynamoid models - does not modify pre-existing tables"
|
11
|
+
task :create_tables => :environment do
|
12
|
+
tables = Dynamoid::Tasks::Database.create_tables
|
13
|
+
result = tables[:created].map{ |c| "#{c} created" } + tables[:existing].map{ |e| "#{e} already exists" }
|
14
|
+
result.sort.each{ |r| puts r }
|
15
|
+
end
|
16
|
+
|
17
|
+
desc 'Tests if the DynamoDB instance can be contacted using your configuration'
|
18
|
+
task :ping => :environment do
|
19
|
+
success = false
|
20
|
+
failure_reason = nil
|
21
|
+
|
22
|
+
begin
|
23
|
+
Dynamoid::Tasks::Database.ping
|
24
|
+
success = true
|
25
|
+
rescue Exception => e
|
26
|
+
failure_reason = e.message
|
27
|
+
end
|
28
|
+
|
29
|
+
msg = "Connection to DynamoDB #{success ? 'OK' : 'FAILED'}"
|
30
|
+
msg << if Dynamoid.config.endpoint
|
31
|
+
" at local endpoint '#{Dynamoid.config.endpoint}'"
|
32
|
+
else
|
33
|
+
' at remote AWS endpoint'
|
34
|
+
end
|
35
|
+
if not success
|
36
|
+
msg << ", reason being '#{failure_reason}'"
|
37
|
+
end
|
38
|
+
puts msg
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Dynamoid
|
2
|
+
module Tasks
|
3
|
+
module Database
|
4
|
+
extend self
|
5
|
+
|
6
|
+
# Create any new tables for the models. Existing tables are not
|
7
|
+
# modified.
|
8
|
+
def create_tables
|
9
|
+
results = { created: [], existing: [] }
|
10
|
+
# We can't quite rely on Dynamoid.included_models alone, we need to select only viable models
|
11
|
+
Dynamoid.included_models.select{ |m| not m.base_class.try(:name).blank? }.uniq(&:table_name).each do |model|
|
12
|
+
if Dynamoid.adapter.list_tables.include? model.table_name
|
13
|
+
results[:existing] << model.table_name
|
14
|
+
else
|
15
|
+
model.create_table
|
16
|
+
results[:created] << model.table_name
|
17
|
+
end
|
18
|
+
end
|
19
|
+
results
|
20
|
+
end
|
21
|
+
|
22
|
+
# Is the DynamoDB reachable?
|
23
|
+
def ping
|
24
|
+
Dynamoid.adapter.list_tables
|
25
|
+
true
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/dynamoid/version.rb
CHANGED
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: 1.3.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Symonds
|
@@ -20,20 +20,34 @@ authors:
|
|
20
20
|
autorequire:
|
21
21
|
bindir: exe
|
22
22
|
cert_chain: []
|
23
|
-
date:
|
23
|
+
date: 2017-03-27 00:00:00.000000000 Z
|
24
24
|
dependencies:
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: activemodel
|
27
27
|
requirement: !ruby/object:Gem::Requirement
|
28
28
|
requirements:
|
29
|
-
- - "
|
29
|
+
- - ">="
|
30
30
|
- !ruby/object:Gem::Version
|
31
31
|
version: '4'
|
32
32
|
type: :runtime
|
33
33
|
prerelease: false
|
34
34
|
version_requirements: !ruby/object:Gem::Requirement
|
35
35
|
requirements:
|
36
|
-
- - "
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '4'
|
39
|
+
- !ruby/object:Gem::Dependency
|
40
|
+
name: activesupport
|
41
|
+
requirement: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '4'
|
46
|
+
type: :development
|
47
|
+
prerelease: false
|
48
|
+
version_requirements: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
37
51
|
- !ruby/object:Gem::Version
|
38
52
|
version: '4'
|
39
53
|
- !ruby/object:Gem::Dependency
|
@@ -65,91 +79,91 @@ dependencies:
|
|
65
79
|
- !ruby/object:Gem::Version
|
66
80
|
version: '1.0'
|
67
81
|
- !ruby/object:Gem::Dependency
|
68
|
-
name:
|
82
|
+
name: pry
|
69
83
|
requirement: !ruby/object:Gem::Requirement
|
70
84
|
requirements:
|
71
|
-
- - "
|
85
|
+
- - "~>"
|
72
86
|
- !ruby/object:Gem::Version
|
73
|
-
version: '10'
|
87
|
+
version: '0.10'
|
74
88
|
type: :development
|
75
89
|
prerelease: false
|
76
90
|
version_requirements: !ruby/object:Gem::Requirement
|
77
91
|
requirements:
|
78
|
-
- - "
|
92
|
+
- - "~>"
|
79
93
|
- !ruby/object:Gem::Version
|
80
|
-
version: '10'
|
94
|
+
version: '0.10'
|
81
95
|
- !ruby/object:Gem::Dependency
|
82
96
|
name: bundler
|
83
97
|
requirement: !ruby/object:Gem::Requirement
|
84
98
|
requirements:
|
85
99
|
- - "~>"
|
86
100
|
- !ruby/object:Gem::Version
|
87
|
-
version: '1.
|
101
|
+
version: '1.14'
|
88
102
|
type: :development
|
89
103
|
prerelease: false
|
90
104
|
version_requirements: !ruby/object:Gem::Requirement
|
91
105
|
requirements:
|
92
106
|
- - "~>"
|
93
107
|
- !ruby/object:Gem::Version
|
94
|
-
version: '1.
|
108
|
+
version: '1.14'
|
95
109
|
- !ruby/object:Gem::Dependency
|
96
|
-
name:
|
110
|
+
name: rake
|
97
111
|
requirement: !ruby/object:Gem::Requirement
|
98
112
|
requirements:
|
99
|
-
- - "
|
113
|
+
- - "~>"
|
100
114
|
- !ruby/object:Gem::Version
|
101
|
-
version: '
|
115
|
+
version: '12.0'
|
102
116
|
type: :development
|
103
117
|
prerelease: false
|
104
118
|
version_requirements: !ruby/object:Gem::Requirement
|
105
119
|
requirements:
|
106
|
-
- - "
|
120
|
+
- - "~>"
|
107
121
|
- !ruby/object:Gem::Version
|
108
|
-
version: '
|
122
|
+
version: '12.0'
|
109
123
|
- !ruby/object:Gem::Dependency
|
110
|
-
name:
|
124
|
+
name: rspec
|
111
125
|
requirement: !ruby/object:Gem::Requirement
|
112
126
|
requirements:
|
113
|
-
- - "
|
127
|
+
- - "~>"
|
114
128
|
- !ruby/object:Gem::Version
|
115
|
-
version: '0'
|
129
|
+
version: '3.0'
|
116
130
|
type: :development
|
117
131
|
prerelease: false
|
118
132
|
version_requirements: !ruby/object:Gem::Requirement
|
119
133
|
requirements:
|
120
|
-
- - "
|
134
|
+
- - "~>"
|
121
135
|
- !ruby/object:Gem::Version
|
122
|
-
version: '0'
|
136
|
+
version: '3.0'
|
123
137
|
- !ruby/object:Gem::Dependency
|
124
|
-
name:
|
138
|
+
name: appraisal
|
125
139
|
requirement: !ruby/object:Gem::Requirement
|
126
140
|
requirements:
|
127
|
-
- - "
|
141
|
+
- - "~>"
|
128
142
|
- !ruby/object:Gem::Version
|
129
|
-
version: '
|
143
|
+
version: '2.1'
|
130
144
|
type: :development
|
131
145
|
prerelease: false
|
132
146
|
version_requirements: !ruby/object:Gem::Requirement
|
133
147
|
requirements:
|
134
|
-
- - "
|
148
|
+
- - "~>"
|
135
149
|
- !ruby/object:Gem::Version
|
136
|
-
version: '
|
150
|
+
version: '2.1'
|
137
151
|
- !ruby/object:Gem::Dependency
|
138
|
-
name:
|
152
|
+
name: wwtd
|
139
153
|
requirement: !ruby/object:Gem::Requirement
|
140
154
|
requirements:
|
141
|
-
- - "
|
155
|
+
- - "~>"
|
142
156
|
- !ruby/object:Gem::Version
|
143
|
-
version: '
|
157
|
+
version: '1.3'
|
144
158
|
type: :development
|
145
159
|
prerelease: false
|
146
160
|
version_requirements: !ruby/object:Gem::Requirement
|
147
161
|
requirements:
|
148
|
-
- - "
|
162
|
+
- - "~>"
|
149
163
|
- !ruby/object:Gem::Version
|
150
|
-
version: '
|
164
|
+
version: '1.3'
|
151
165
|
- !ruby/object:Gem::Dependency
|
152
|
-
name:
|
166
|
+
name: yard
|
153
167
|
requirement: !ruby/object:Gem::Requirement
|
154
168
|
requirements:
|
155
169
|
- - ">="
|
@@ -163,7 +177,7 @@ dependencies:
|
|
163
177
|
- !ruby/object:Gem::Version
|
164
178
|
version: '0'
|
165
179
|
- !ruby/object:Gem::Dependency
|
166
|
-
name:
|
180
|
+
name: coveralls
|
167
181
|
requirement: !ruby/object:Gem::Requirement
|
168
182
|
requirements:
|
169
183
|
- - ">="
|
@@ -177,19 +191,19 @@ dependencies:
|
|
177
191
|
- !ruby/object:Gem::Version
|
178
192
|
version: '0'
|
179
193
|
- !ruby/object:Gem::Dependency
|
180
|
-
name:
|
194
|
+
name: rspec-retry
|
181
195
|
requirement: !ruby/object:Gem::Requirement
|
182
196
|
requirements:
|
183
|
-
- - "
|
197
|
+
- - ">="
|
184
198
|
- !ruby/object:Gem::Version
|
185
|
-
version: '
|
199
|
+
version: '0'
|
186
200
|
type: :development
|
187
201
|
prerelease: false
|
188
202
|
version_requirements: !ruby/object:Gem::Requirement
|
189
203
|
requirements:
|
190
|
-
- - "
|
204
|
+
- - ">="
|
191
205
|
- !ruby/object:Gem::Version
|
192
|
-
version: '
|
206
|
+
version: '0'
|
193
207
|
description: Dynamoid is an ORM for Amazon's DynamoDB that supports offline development,
|
194
208
|
associations, querying, and everything else you'd expect from an ActiveRecord-style
|
195
209
|
replacement.
|
@@ -206,12 +220,21 @@ files:
|
|
206
220
|
- ".gitignore"
|
207
221
|
- ".rspec"
|
208
222
|
- ".travis.yml"
|
223
|
+
- Appraisals
|
209
224
|
- CHANGELOG.md
|
210
225
|
- Gemfile
|
211
226
|
- LICENSE.txt
|
212
227
|
- README.md
|
213
228
|
- Rakefile
|
214
229
|
- dynamoid.gemspec
|
230
|
+
- gemfiles/rails_4_0.gemfile
|
231
|
+
- gemfiles/rails_4_0.gemfile.lock
|
232
|
+
- gemfiles/rails_4_1.gemfile
|
233
|
+
- gemfiles/rails_4_1.gemfile.lock
|
234
|
+
- gemfiles/rails_4_2.gemfile
|
235
|
+
- gemfiles/rails_4_2.gemfile.lock
|
236
|
+
- gemfiles/rails_5_0.gemfile
|
237
|
+
- gemfiles/rails_5_0.gemfile.lock
|
215
238
|
- lib/dynamoid.rb
|
216
239
|
- lib/dynamoid/adapter.rb
|
217
240
|
- lib/dynamoid/adapter_plugin/aws_sdk_v2.rb
|
@@ -237,6 +260,9 @@ files:
|
|
237
260
|
- lib/dynamoid/indexes.rb
|
238
261
|
- lib/dynamoid/middleware/identity_map.rb
|
239
262
|
- lib/dynamoid/persistence.rb
|
263
|
+
- lib/dynamoid/railtie.rb
|
264
|
+
- lib/dynamoid/tasks/database.rake
|
265
|
+
- lib/dynamoid/tasks/database.rb
|
240
266
|
- lib/dynamoid/validations.rb
|
241
267
|
- lib/dynamoid/version.rb
|
242
268
|
homepage: http://github.com/Dynamoid/Dynamoid
|
@@ -259,7 +285,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
259
285
|
version: '0'
|
260
286
|
requirements: []
|
261
287
|
rubyforge_project:
|
262
|
-
rubygems_version: 2.
|
288
|
+
rubygems_version: 2.6.8
|
263
289
|
signing_key:
|
264
290
|
specification_version: 4
|
265
291
|
summary: Dynamoid is an ORM for Amazon's DynamoDB
|