active_shotgun 0.0.2 → 0.0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -1
- data/Gemfile.lock +1 -1
- data/lib/active_shotgun/model.rb +0 -151
- data/lib/active_shotgun/model/callbacks.rb +35 -0
- data/lib/active_shotgun/model/delete.rb +18 -0
- data/lib/active_shotgun/model/read.rb +37 -0
- data/lib/active_shotgun/model/validations.rb +16 -0
- data/lib/active_shotgun/model/write.rb +70 -0
- data/lib/active_shotgun/version.rb +1 -1
- metadata +6 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3abb67e7c3b8be946a8f22ed9e4c7829446b3aea28fc40e7c8bafdd1a79d063c
|
4
|
+
data.tar.gz: cf80eac1abcc79a182a88e8bb5850d02554cb51f7fdce66c1231c9d10b010722
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 316e77ebbe27f4c708f8bb1849b4cb79426b79aa319cc9952e42617dedef13841fb0204612c8abed1a5a87e47052441176313945c03199fcf32d0d4beb3c7f83
|
7
|
+
data.tar.gz: b56bbd475751025fa8841281550ab33078bad9a88bfdc58af13157f516bb415c6db545f2286eae049694e403c1ebe0d5f575fff295bc69593d03af752a4cf7a6
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [0.0.2.1] - 2020-12-16
|
10
|
+
### Changed
|
11
|
+
- Not everything is in one big file now
|
12
|
+
|
9
13
|
## [0.0.2] - 2020-12-16
|
10
14
|
### Added
|
11
15
|
- save, create, update, find, delete, revive (and friends)
|
@@ -20,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
20
24
|
### Added
|
21
25
|
- Gem init
|
22
26
|
|
23
|
-
[Unreleased]: https://github.com/zaratan/active_shotgun/compare/v0.0.2...HEAD
|
27
|
+
[Unreleased]: https://github.com/zaratan/active_shotgun/compare/v0.0.2.1...HEAD
|
28
|
+
[0.0.2.1]: https://github.com/zaratan/active_shotgun/releases/tag/v0.0.2.1
|
24
29
|
[0.0.2]: https://github.com/zaratan/active_shotgun/releases/tag/v0.0.2
|
25
30
|
[0.0.1]: https://github.com/zaratan/active_shotgun/releases/tag/v0.0.1
|
data/Gemfile.lock
CHANGED
data/lib/active_shotgun/model.rb
CHANGED
@@ -59,156 +59,5 @@ module ActiveShotgun
|
|
59
59
|
base_class.prepend(Validations)
|
60
60
|
base_class.prepend(Callbacks)
|
61
61
|
end
|
62
|
-
|
63
|
-
module Write
|
64
|
-
def persisted?
|
65
|
-
!!id
|
66
|
-
end
|
67
|
-
|
68
|
-
def save
|
69
|
-
return false unless changed?
|
70
|
-
|
71
|
-
sg_result =
|
72
|
-
if persisted?
|
73
|
-
shotgun_client.update(id, changes.transform_values(&:last))
|
74
|
-
else
|
75
|
-
shotgun_client.create(changes.transform_values(&:last))
|
76
|
-
end
|
77
|
-
override_attributes!(sg_result.attributes.to_h.merge(id: sg_result.id))
|
78
|
-
changes_applied
|
79
|
-
true
|
80
|
-
end
|
81
|
-
alias_method :save!, :save
|
82
|
-
|
83
|
-
def mass_assign(assigned_attributes)
|
84
|
-
assigned_attributes.
|
85
|
-
transform_keys(&:to_sym).
|
86
|
-
slice(*self.class.shotgun_writable_fetched_attributes).
|
87
|
-
each do |k, v|
|
88
|
-
public_send("#{k}=", v)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
def update(updated_attributes)
|
93
|
-
mass_assign(updated_attributes)
|
94
|
-
save
|
95
|
-
end
|
96
|
-
|
97
|
-
def update!(updated_attributes)
|
98
|
-
mass_assign(updated_attributes)
|
99
|
-
save!
|
100
|
-
end
|
101
|
-
|
102
|
-
module ClassMethods
|
103
|
-
def create(create_attributes)
|
104
|
-
new_entity = new
|
105
|
-
new_entity.mass_assign(create_attributes)
|
106
|
-
new_entity.save
|
107
|
-
end
|
108
|
-
|
109
|
-
def create!(create_attributes)
|
110
|
-
new_entity = new
|
111
|
-
new_entity.mass_assign(create_attributes)
|
112
|
-
new_entity.save!
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
private
|
117
|
-
|
118
|
-
def override_attributes!(new_attributes)
|
119
|
-
new_attributes.
|
120
|
-
transform_keys(&:to_sym).
|
121
|
-
slice(*self.class.shotgun_readable_fetched_attributes).
|
122
|
-
each do |k, v|
|
123
|
-
instance_variable_set("@#{k}", v)
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
module Validations
|
129
|
-
def save
|
130
|
-
validate && super
|
131
|
-
end
|
132
|
-
|
133
|
-
def save!
|
134
|
-
validate!
|
135
|
-
super
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
module Callbacks
|
140
|
-
def self.prepended(base)
|
141
|
-
base.define_model_callbacks :destroy
|
142
|
-
base.define_model_callbacks :update
|
143
|
-
base.define_model_callbacks :save
|
144
|
-
base.define_model_callbacks :create
|
145
|
-
base.define_model_callbacks :validation
|
146
|
-
end
|
147
|
-
|
148
|
-
def destroy
|
149
|
-
run_callbacks(:destroy) do
|
150
|
-
super
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
def save
|
155
|
-
run_callbacks(:save) do
|
156
|
-
run_callbacks(persisted? ? :update : :create) do
|
157
|
-
super
|
158
|
-
end
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
def validate
|
163
|
-
run_callbacks(:validation) do
|
164
|
-
super
|
165
|
-
end
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
module Delete
|
170
|
-
def delete
|
171
|
-
shotgun_client.delete(id)
|
172
|
-
end
|
173
|
-
alias_method :destroy, :delete
|
174
|
-
|
175
|
-
module ClassMethods
|
176
|
-
def revive(id)
|
177
|
-
shotgun_client.revive(id)
|
178
|
-
end
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
module Read
|
183
|
-
def attributes
|
184
|
-
self.class.shotgun_readable_fetched_attributes.map do |attribute|
|
185
|
-
[attribute, instance_variable_get("@#{attribute}")]
|
186
|
-
end.to_h
|
187
|
-
end
|
188
|
-
|
189
|
-
def writable_attributes
|
190
|
-
self.class.shotgun_writable_fetched_attributes.map do |attribute|
|
191
|
-
[attribute, instance_variable_get("@#{attribute}")]
|
192
|
-
end.to_h
|
193
|
-
end
|
194
|
-
|
195
|
-
def initialize(new_attributes = {})
|
196
|
-
new_attributes.slice(*self.class.shotgun_readable_fetched_attributes).each do |attribute, value|
|
197
|
-
instance_variable_set("@#{attribute}", value)
|
198
|
-
end
|
199
|
-
end
|
200
|
-
|
201
|
-
module ClassMethods
|
202
|
-
def first
|
203
|
-
sg_result = shotgun_client.first
|
204
|
-
new(sg_result.attributes.to_h.merge(id: sg_result.id))
|
205
|
-
end
|
206
|
-
|
207
|
-
def find(id)
|
208
|
-
sg_result = shotgun_client.find(id)
|
209
|
-
new(sg_result.attributes.to_h.merge(id: sg_result.id))
|
210
|
-
end
|
211
|
-
end
|
212
|
-
end
|
213
62
|
end
|
214
63
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveShotgun
|
4
|
+
module Model
|
5
|
+
module Callbacks
|
6
|
+
def self.prepended(base)
|
7
|
+
base.define_model_callbacks :destroy
|
8
|
+
base.define_model_callbacks :update
|
9
|
+
base.define_model_callbacks :save
|
10
|
+
base.define_model_callbacks :create
|
11
|
+
base.define_model_callbacks :validation
|
12
|
+
end
|
13
|
+
|
14
|
+
def destroy
|
15
|
+
run_callbacks(:destroy) do
|
16
|
+
super
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def save
|
21
|
+
run_callbacks(:save) do
|
22
|
+
run_callbacks(persisted? ? :update : :create) do
|
23
|
+
super
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def validate
|
29
|
+
run_callbacks(:validation) do
|
30
|
+
super
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveShotgun
|
4
|
+
module Model
|
5
|
+
module Delete
|
6
|
+
def delete
|
7
|
+
shotgun_client.delete(id)
|
8
|
+
end
|
9
|
+
alias_method :destroy, :delete
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
def revive(id)
|
13
|
+
shotgun_client.revive(id)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveShotgun
|
4
|
+
module Model
|
5
|
+
module Read
|
6
|
+
def attributes
|
7
|
+
self.class.shotgun_readable_fetched_attributes.map do |attribute|
|
8
|
+
[attribute, instance_variable_get("@#{attribute}")]
|
9
|
+
end.to_h
|
10
|
+
end
|
11
|
+
|
12
|
+
def writable_attributes
|
13
|
+
self.class.shotgun_writable_fetched_attributes.map do |attribute|
|
14
|
+
[attribute, instance_variable_get("@#{attribute}")]
|
15
|
+
end.to_h
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(new_attributes = {})
|
19
|
+
new_attributes.slice(*self.class.shotgun_readable_fetched_attributes).each do |attribute, value|
|
20
|
+
instance_variable_set("@#{attribute}", value)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
module ClassMethods
|
25
|
+
def first
|
26
|
+
sg_result = shotgun_client.first
|
27
|
+
new(sg_result.attributes.to_h.merge(id: sg_result.id))
|
28
|
+
end
|
29
|
+
|
30
|
+
def find(id)
|
31
|
+
sg_result = shotgun_client.find(id)
|
32
|
+
new(sg_result.attributes.to_h.merge(id: sg_result.id))
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveShotgun
|
4
|
+
module Model
|
5
|
+
module Write
|
6
|
+
def persisted?
|
7
|
+
!!id
|
8
|
+
end
|
9
|
+
|
10
|
+
def save
|
11
|
+
return false unless changed?
|
12
|
+
|
13
|
+
sg_result =
|
14
|
+
if persisted?
|
15
|
+
shotgun_client.update(id, changes.transform_values(&:last))
|
16
|
+
else
|
17
|
+
shotgun_client.create(changes.transform_values(&:last))
|
18
|
+
end
|
19
|
+
override_attributes!(sg_result.attributes.to_h.merge(id: sg_result.id))
|
20
|
+
changes_applied
|
21
|
+
true
|
22
|
+
end
|
23
|
+
alias_method :save!, :save
|
24
|
+
|
25
|
+
def mass_assign(assigned_attributes)
|
26
|
+
assigned_attributes.
|
27
|
+
transform_keys(&:to_sym).
|
28
|
+
slice(*self.class.shotgun_writable_fetched_attributes).
|
29
|
+
each do |k, v|
|
30
|
+
public_send("#{k}=", v)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def update(updated_attributes)
|
35
|
+
mass_assign(updated_attributes)
|
36
|
+
save
|
37
|
+
end
|
38
|
+
|
39
|
+
def update!(updated_attributes)
|
40
|
+
mass_assign(updated_attributes)
|
41
|
+
save!
|
42
|
+
end
|
43
|
+
|
44
|
+
module ClassMethods
|
45
|
+
def create(create_attributes)
|
46
|
+
new_entity = new
|
47
|
+
new_entity.mass_assign(create_attributes)
|
48
|
+
new_entity.save
|
49
|
+
end
|
50
|
+
|
51
|
+
def create!(create_attributes)
|
52
|
+
new_entity = new
|
53
|
+
new_entity.mass_assign(create_attributes)
|
54
|
+
new_entity.save!
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def override_attributes!(new_attributes)
|
61
|
+
new_attributes.
|
62
|
+
transform_keys(&:to_sym).
|
63
|
+
slice(*self.class.shotgun_readable_fetched_attributes).
|
64
|
+
each do |k, v|
|
65
|
+
instance_variable_set("@#{k}", v)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_shotgun
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.2
|
4
|
+
version: 0.0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Denis <Zaratan> Pasin
|
@@ -266,6 +266,11 @@ files:
|
|
266
266
|
- lib/active_shotgun/client.rb
|
267
267
|
- lib/active_shotgun/config.rb
|
268
268
|
- lib/active_shotgun/model.rb
|
269
|
+
- lib/active_shotgun/model/callbacks.rb
|
270
|
+
- lib/active_shotgun/model/delete.rb
|
271
|
+
- lib/active_shotgun/model/read.rb
|
272
|
+
- lib/active_shotgun/model/validations.rb
|
273
|
+
- lib/active_shotgun/model/write.rb
|
269
274
|
- lib/active_shotgun/version.rb
|
270
275
|
homepage: https://github.com/zaratan/active_shotgun
|
271
276
|
licenses:
|