dyna_model 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -1
- data/lib/dyna_model/adapters/carrierwave/dyna_model.rb +33 -0
- data/lib/dyna_model/document.rb +11 -0
- data/lib/dyna_model/persistence.rb +11 -11
- data/lib/dyna_model/table.rb +13 -4
- data/lib/dyna_model/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 28909cf001a45617ccab2dd172777e7fc30da156
|
4
|
+
data.tar.gz: 558bab75c352c91888ad15dc1efb9c11242bca4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a86fff50cdefb2e16b1d0d490b4b595615a3d3c58b56ff8de283b87379f0696719fa6a0de9c37be7062173b7328854529e2ef4dea36377eae6c63951e1dd753
|
7
|
+
data.tar.gz: 10b9bd47c3694eeba33bfc7b29ac493bbfbfb4f982d23f492c1245709efe5602f7596d7ad74ebded563e2668daa7800ea4ec66925934a0efd0253f95c62bcabb
|
data/README.md
CHANGED
@@ -86,6 +86,15 @@ class Item
|
|
86
86
|
end
|
87
87
|
```
|
88
88
|
|
89
|
-
|
89
|
+
## CarrierWave compatible adapter
|
90
|
+
```
|
91
|
+
require "dyna_model/adapters/carrierwave/dyna_model"
|
92
|
+
class Item
|
93
|
+
include DynaModel::Document
|
94
|
+
mount_uploader :favicon, FaviconUploader
|
95
|
+
end
|
96
|
+
```
|
97
|
+
|
98
|
+
## AWS::Record
|
90
99
|
* http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/Record.html
|
91
100
|
* https://github.com/aws/aws-sdk-ruby/blob/master/lib/aws/record/abstract_base.rb
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'carrierwave'
|
2
|
+
require 'carrierwave/validations/active_model'
|
3
|
+
|
4
|
+
module CarrierWave
|
5
|
+
module DynaModel
|
6
|
+
include CarrierWave::Mount
|
7
|
+
|
8
|
+
def mount_uploader(column, uploader, options={}, &block)
|
9
|
+
options[:mount_on] ||= "#{column}_identifier"
|
10
|
+
string_attr options[:mount_on].to_sym
|
11
|
+
|
12
|
+
super
|
13
|
+
|
14
|
+
alias_method :read_uploader, :[]
|
15
|
+
alias_method :write_uploader, :[]=
|
16
|
+
public :read_uploader
|
17
|
+
public :write_uploader
|
18
|
+
|
19
|
+
include CarrierWave::Validations::ActiveModel
|
20
|
+
|
21
|
+
validates_integrity_of column if uploader_option(column.to_sym, :validate_integrity)
|
22
|
+
validates_processing_of column if uploader_option(column.to_sym, :validate_processing)
|
23
|
+
|
24
|
+
after_save "store_#{column}!".to_sym
|
25
|
+
before_save "write_#{column}_identifier".to_sym
|
26
|
+
after_destroy "remove_#{column}!".to_sym
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
DynaModel::Document::ClassMethods.send(:include, CarrierWave::DynaModel)
|
data/lib/dyna_model/document.rb
CHANGED
@@ -45,6 +45,17 @@ module DynaModel
|
|
45
45
|
hash.merge(attr_name => __send__(attr_name))
|
46
46
|
end
|
47
47
|
end
|
48
|
+
|
49
|
+
# OVERRIDE
|
50
|
+
# https://github.com/aws/aws-sdk-ruby/blob/master/lib/aws/record/abstract_base.rb#L273
|
51
|
+
# AWS::Record::AbstractBase to trigger update even without changes (for callbacks etc)
|
52
|
+
private
|
53
|
+
def update
|
54
|
+
#return unless changed?
|
55
|
+
touch_timestamps('updated_at')
|
56
|
+
increment_optimistic_lock_value
|
57
|
+
update_storage
|
58
|
+
end
|
48
59
|
end
|
49
60
|
|
50
61
|
include ActiveModel::Conversion
|
@@ -27,19 +27,19 @@ module DynaModel
|
|
27
27
|
def update_storage
|
28
28
|
# Only enumerating dirty (i.e. changed) attributes. Empty
|
29
29
|
# (nil and empty set) values are deleted, the others are replaced.
|
30
|
-
attr_updates = {}
|
31
|
-
changed.each do |attr_name|
|
32
|
-
attribute = self.class.attribute_for(attr_name)
|
33
|
-
value = serialize_attribute(attribute, @_data[attr_name])
|
34
|
-
if value.nil? or value == []
|
35
|
-
attr_updates[attr_name] = nil
|
36
|
-
else
|
37
|
-
attr_updates[attr_name] = value
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
30
|
run_callbacks :save do
|
42
31
|
run_callbacks :update do
|
32
|
+
attr_updates = {}
|
33
|
+
changed.each do |attr_name|
|
34
|
+
attribute = self.class.attribute_for(attr_name)
|
35
|
+
value = serialize_attribute(attribute, @_data[attr_name])
|
36
|
+
if value.nil? or value == []
|
37
|
+
attr_updates[attr_name] = nil
|
38
|
+
else
|
39
|
+
attr_updates[attr_name] = value
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
43
|
self.class.dynamo_db_table.write(attr_updates, {
|
44
44
|
update_item: dynamo_db_item_key_values,
|
45
45
|
shard_name: self.shard
|
data/lib/dyna_model/table.rb
CHANGED
@@ -168,7 +168,8 @@ module DynaModel
|
|
168
168
|
def get_item(hash_key, options={})
|
169
169
|
options[:consistent_read] = false unless options[:consistent_read]
|
170
170
|
options[:return_consumed_capacity] ||= :none # "NONE" # || "TOTAL"
|
171
|
-
options[:select] ||= []
|
171
|
+
options[:select] ||= [] # no :projected option, always an array or :all
|
172
|
+
raise ArgumentError, "Invalid :select. GetItem :select must be an Array (blank for :all)" unless options[:select].is_a?(Array)
|
172
173
|
|
173
174
|
get_item_request = {
|
174
175
|
table_name: @model.dynamo_db_table_name(options[:shard_name]),
|
@@ -176,7 +177,11 @@ module DynaModel
|
|
176
177
|
consistent_read: options[:consistent_read],
|
177
178
|
return_consumed_capacity: RETURNED_CONSUMED_CAPACITY[options[:return_consumed_capacity]]
|
178
179
|
}
|
179
|
-
|
180
|
+
if options[:select].blank?
|
181
|
+
options[:select] = :all # for obj_from_attrs
|
182
|
+
else
|
183
|
+
get_item_request.merge!( attributes_to_get: [options[:select]].flatten )
|
184
|
+
end
|
180
185
|
@model.dynamo_db_client.get_item(get_item_request)
|
181
186
|
end
|
182
187
|
|
@@ -273,7 +278,7 @@ module DynaModel
|
|
273
278
|
|
274
279
|
def batch_get_item(keys, options={})
|
275
280
|
options[:return_consumed_capacity] ||= :none
|
276
|
-
options[:select] ||= []
|
281
|
+
options[:select] ||= [] # no :projected option, always an array or :all
|
277
282
|
options[:consistent_read] = false unless options[:consistent_read]
|
278
283
|
|
279
284
|
raise ArgumentError, "must include between 1 - 100 keys" if keys.size == 0 || keys.size > 100
|
@@ -295,7 +300,11 @@ module DynaModel
|
|
295
300
|
|
296
301
|
request_items_request = {}
|
297
302
|
request_items_request.merge!( keys: keys_request )
|
298
|
-
|
303
|
+
if options[:select].blank?
|
304
|
+
options[:select] = :all # for obj_from_attrs
|
305
|
+
else
|
306
|
+
request_items_request.merge!( attributes_to_get: [options[:select]].flatten )
|
307
|
+
end
|
299
308
|
request_items_request.merge!( consistent_read: options[:consistent_read] ) if options[:consistent_read]
|
300
309
|
batch_get_item_request = {
|
301
310
|
request_items: { @model.dynamo_db_table_name(options[:shard_name]) => request_items_request },
|
data/lib/dyna_model/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dyna_model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cary Dunn
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -136,6 +136,7 @@ files:
|
|
136
136
|
- Rakefile
|
137
137
|
- dyna_model.gemspec
|
138
138
|
- lib/dyna_model.rb
|
139
|
+
- lib/dyna_model/adapters/carrierwave/dyna_model.rb
|
139
140
|
- lib/dyna_model/adapters/elasticsearch/dyna_model_adapter.rb
|
140
141
|
- lib/dyna_model/attributes.rb
|
141
142
|
- lib/dyna_model/aws/record/attributes/serialized_attr.rb
|