dynamini 1.10.4 → 1.11.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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/dynamini.gemspec +1 -1
- data/lib/dynamini/base.rb +19 -11
- data/spec/dynamini/base_spec.rb +18 -0
- metadata +23 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dab1531824d1cd003429a7abbae63ee2ca5f059f
|
4
|
+
data.tar.gz: f9c99348fc0f13d9b5aa38f9ead4af354cb9dfcf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f6f990e17451bf03705f5d15c1c0d2dd783430590b55b5de24ec1e731af8373d3c9e5d74d55db2fd5eac58c4a0313589fcbe0e14f000ba83af75b7c8b16be48
|
7
|
+
data.tar.gz: d84f6c09af62a8b4d8ed8dd3a80b45222b86b29999e45fe44e9bfac3c8957bf558c37ff0ef2743a700435b03a3dfc522745a9b8307b655c5574e143dca9dbd8e
|
data/Gemfile.lock
CHANGED
data/dynamini.gemspec
CHANGED
data/lib/dynamini/base.rb
CHANGED
@@ -9,6 +9,7 @@ module Dynamini
|
|
9
9
|
# Core db interface class.
|
10
10
|
class Base
|
11
11
|
include ActiveModel::Validations
|
12
|
+
extend ActiveModel::Callbacks
|
12
13
|
extend Dynamini::BatchOperations
|
13
14
|
extend Dynamini::Querying
|
14
15
|
include Dynamini::ClientInterface
|
@@ -21,10 +22,12 @@ module Dynamini
|
|
21
22
|
class_attribute :handles
|
22
23
|
|
23
24
|
self.handles = {
|
24
|
-
created_at: {
|
25
|
-
updated_at: {
|
25
|
+
created_at: {format: :time, options: {}},
|
26
|
+
updated_at: {format: :time, options: {}}
|
26
27
|
}
|
27
28
|
|
29
|
+
define_model_callbacks :save
|
30
|
+
|
28
31
|
class << self
|
29
32
|
|
30
33
|
attr_reader :range_key
|
@@ -97,17 +100,22 @@ module Dynamini
|
|
97
100
|
end
|
98
101
|
|
99
102
|
def save(options = {})
|
100
|
-
|
103
|
+
run_callbacks :save do
|
104
|
+
@changes.empty? || (valid? && trigger_save(options))
|
105
|
+
end
|
101
106
|
end
|
102
107
|
|
103
108
|
def save!(options = {})
|
104
|
-
|
109
|
+
run_callbacks :save do
|
110
|
+
|
111
|
+
options[:validate] = true if options[:validate].nil?
|
105
112
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
113
|
+
unless @changes.empty?
|
114
|
+
if (options[:validate] && valid?) || !options[:validate]
|
115
|
+
trigger_save(options)
|
116
|
+
else
|
117
|
+
raise StandardError, errors.full_messages
|
118
|
+
end
|
111
119
|
end
|
112
120
|
end
|
113
121
|
end
|
@@ -148,13 +156,13 @@ module Dynamini
|
|
148
156
|
end
|
149
157
|
|
150
158
|
def key
|
151
|
-
key_hash = {
|
159
|
+
key_hash = {self.class.hash_key => @attributes[self.class.hash_key]}
|
152
160
|
key_hash[self.class.range_key] = @attributes[self.class.range_key] if self.class.range_key
|
153
161
|
key_hash
|
154
162
|
end
|
155
163
|
|
156
164
|
def self.create_key_hash(hash_value, range_value = nil)
|
157
|
-
key_hash = {
|
165
|
+
key_hash = {self.hash_key => hash_value}
|
158
166
|
key_hash[self.range_key] = range_value if self.range_key
|
159
167
|
key_hash
|
160
168
|
end
|
data/spec/dynamini/base_spec.rb
CHANGED
@@ -19,6 +19,12 @@ describe Dynamini::Base do
|
|
19
19
|
handle :bar, :integer
|
20
20
|
end
|
21
21
|
|
22
|
+
class TestClassWithCallbacks < Dynamini::Base
|
23
|
+
self.in_memory = true
|
24
|
+
before_save :before_callback
|
25
|
+
after_save :after_callback
|
26
|
+
end
|
27
|
+
|
22
28
|
before do
|
23
29
|
model.save
|
24
30
|
end
|
@@ -62,6 +68,7 @@ describe Dynamini::Base do
|
|
62
68
|
|
63
69
|
context 'when creating a subclass' do
|
64
70
|
class Foo < Dynamini::Base
|
71
|
+
Foo.in_memory = true
|
65
72
|
end
|
66
73
|
|
67
74
|
it 'should return the object as an instance of the subclass' do
|
@@ -145,6 +152,11 @@ describe Dynamini::Base do
|
|
145
152
|
end
|
146
153
|
|
147
154
|
describe '#save' do
|
155
|
+
it 'should run before and after save callbacks' do
|
156
|
+
expect_any_instance_of(TestClassWithCallbacks).to receive(:before_callback)
|
157
|
+
expect_any_instance_of(TestClassWithCallbacks).to receive(:after_callback)
|
158
|
+
TestClassWithCallbacks.new.save
|
159
|
+
end
|
148
160
|
|
149
161
|
context 'when passing validation' do
|
150
162
|
it 'should return true' do
|
@@ -264,6 +276,12 @@ describe Dynamini::Base do
|
|
264
276
|
|
265
277
|
describe '#save!' do
|
266
278
|
|
279
|
+
it 'should run before and after save callbacks' do
|
280
|
+
expect_any_instance_of(TestClassWithCallbacks).to receive(:before_callback)
|
281
|
+
expect_any_instance_of(TestClassWithCallbacks).to receive(:after_callback)
|
282
|
+
TestClassWithCallbacks.new.save!
|
283
|
+
end
|
284
|
+
|
267
285
|
context 'hash key only' do
|
268
286
|
class TestValidation < Dynamini::Base
|
269
287
|
set_hash_key :bar
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dynamini
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Greg Ward
|
@@ -21,104 +21,104 @@ dependencies:
|
|
21
21
|
name: activemodel
|
22
22
|
requirement: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '3'
|
27
|
-
- -
|
27
|
+
- - <
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '5.0'
|
30
30
|
type: :runtime
|
31
31
|
prerelease: false
|
32
32
|
version_requirements: !ruby/object:Gem::Requirement
|
33
33
|
requirements:
|
34
|
-
- -
|
34
|
+
- - '>='
|
35
35
|
- !ruby/object:Gem::Version
|
36
36
|
version: '3'
|
37
|
-
- -
|
37
|
+
- - <
|
38
38
|
- !ruby/object:Gem::Version
|
39
39
|
version: '5.0'
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: aws-sdk
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
|
-
- -
|
44
|
+
- - ~>
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '2'
|
47
47
|
type: :runtime
|
48
48
|
prerelease: false
|
49
49
|
version_requirements: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
|
-
- -
|
51
|
+
- - ~>
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
version: '2'
|
54
54
|
- !ruby/object:Gem::Dependency
|
55
55
|
name: rspec
|
56
56
|
requirement: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
|
-
- -
|
58
|
+
- - ~>
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '3'
|
61
61
|
type: :development
|
62
62
|
prerelease: false
|
63
63
|
version_requirements: !ruby/object:Gem::Requirement
|
64
64
|
requirements:
|
65
|
-
- -
|
65
|
+
- - ~>
|
66
66
|
- !ruby/object:Gem::Version
|
67
67
|
version: '3'
|
68
68
|
- !ruby/object:Gem::Dependency
|
69
69
|
name: pry
|
70
70
|
requirement: !ruby/object:Gem::Requirement
|
71
71
|
requirements:
|
72
|
-
- -
|
72
|
+
- - ~>
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '0'
|
75
75
|
type: :development
|
76
76
|
prerelease: false
|
77
77
|
version_requirements: !ruby/object:Gem::Requirement
|
78
78
|
requirements:
|
79
|
-
- -
|
79
|
+
- - ~>
|
80
80
|
- !ruby/object:Gem::Version
|
81
81
|
version: '0'
|
82
82
|
- !ruby/object:Gem::Dependency
|
83
83
|
name: fuubar
|
84
84
|
requirement: !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|
86
|
-
- -
|
86
|
+
- - ~>
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: '2'
|
89
89
|
type: :development
|
90
90
|
prerelease: false
|
91
91
|
version_requirements: !ruby/object:Gem::Requirement
|
92
92
|
requirements:
|
93
|
-
- -
|
93
|
+
- - ~>
|
94
94
|
- !ruby/object:Gem::Version
|
95
95
|
version: '2'
|
96
96
|
- !ruby/object:Gem::Dependency
|
97
97
|
name: guard-rspec
|
98
98
|
requirement: !ruby/object:Gem::Requirement
|
99
99
|
requirements:
|
100
|
-
- -
|
100
|
+
- - '>='
|
101
101
|
- !ruby/object:Gem::Version
|
102
102
|
version: '0'
|
103
103
|
type: :development
|
104
104
|
prerelease: false
|
105
105
|
version_requirements: !ruby/object:Gem::Requirement
|
106
106
|
requirements:
|
107
|
-
- -
|
107
|
+
- - '>='
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: '0'
|
110
110
|
- !ruby/object:Gem::Dependency
|
111
111
|
name: guard-shell
|
112
112
|
requirement: !ruby/object:Gem::Requirement
|
113
113
|
requirements:
|
114
|
-
- -
|
114
|
+
- - '>='
|
115
115
|
- !ruby/object:Gem::Version
|
116
116
|
version: '0'
|
117
117
|
type: :development
|
118
118
|
prerelease: false
|
119
119
|
version_requirements: !ruby/object:Gem::Requirement
|
120
120
|
requirements:
|
121
|
-
- -
|
121
|
+
- - '>='
|
122
122
|
- !ruby/object:Gem::Version
|
123
123
|
version: '0'
|
124
124
|
description: |-
|
@@ -130,9 +130,9 @@ executables: []
|
|
130
130
|
extensions: []
|
131
131
|
extra_rdoc_files: []
|
132
132
|
files:
|
133
|
-
-
|
134
|
-
-
|
135
|
-
-
|
133
|
+
- .gitignore
|
134
|
+
- .rspec
|
135
|
+
- .travis.yml
|
136
136
|
- Gemfile
|
137
137
|
- Gemfile.lock
|
138
138
|
- Guardfile
|
@@ -170,17 +170,17 @@ require_paths:
|
|
170
170
|
- lib
|
171
171
|
required_ruby_version: !ruby/object:Gem::Requirement
|
172
172
|
requirements:
|
173
|
-
- -
|
173
|
+
- - '>='
|
174
174
|
- !ruby/object:Gem::Version
|
175
175
|
version: '0'
|
176
176
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
177
177
|
requirements:
|
178
|
-
- -
|
178
|
+
- - '>='
|
179
179
|
- !ruby/object:Gem::Version
|
180
180
|
version: '0'
|
181
181
|
requirements: []
|
182
182
|
rubyforge_project:
|
183
|
-
rubygems_version: 2.
|
183
|
+
rubygems_version: 2.2.2
|
184
184
|
signing_key:
|
185
185
|
specification_version: 4
|
186
186
|
summary: DynamoDB interface
|