snfoil 0.9.0 → 1.0.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/CHANGELOG.md +5 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +201 -0
- data/README.md +95 -505
- data/docs/build-context.md +56 -0
- data/docs/create-context.md +109 -0
- data/docs/destroy-context.md +102 -0
- data/docs/index-context.md +70 -0
- data/docs/show-context.md +71 -0
- data/docs/update-context.md +107 -0
- data/lib/{sn_foil → snfoil}/adapters/orms/active_record.rb +14 -0
- data/lib/{sn_foil → snfoil}/adapters/orms/base_adapter.rb +15 -1
- data/lib/snfoil/crud/build_context.rb +49 -0
- data/lib/snfoil/crud/change_context.rb +48 -0
- data/lib/snfoil/crud/context.rb +41 -0
- data/lib/snfoil/crud/create_context.rb +45 -0
- data/lib/snfoil/crud/destroy_context.rb +57 -0
- data/lib/snfoil/crud/index_context.rb +46 -0
- data/lib/snfoil/crud/setup_context.rb +90 -0
- data/lib/snfoil/crud/show_context.rb +52 -0
- data/lib/snfoil/crud/update_context.rb +60 -0
- data/lib/snfoil/version.rb +19 -0
- data/lib/snfoil.rb +69 -0
- data/snfoil.gemspec +47 -0
- metadata +100 -33
- data/Rakefile +0 -4
- data/lib/sn_foil/context.rb +0 -24
- data/lib/sn_foil/contexts/build_context.rb +0 -67
- data/lib/sn_foil/contexts/change_context.rb +0 -101
- data/lib/sn_foil/contexts/create_context.rb +0 -158
- data/lib/sn_foil/contexts/destroy_context.rb +0 -164
- data/lib/sn_foil/contexts/index_context.rb +0 -64
- data/lib/sn_foil/contexts/setup_context.rb +0 -119
- data/lib/sn_foil/contexts/show_context.rb +0 -61
- data/lib/sn_foil/contexts/update_context.rb +0 -168
- data/lib/sn_foil/policy.rb +0 -55
- data/lib/sn_foil/searcher.rb +0 -123
- data/lib/sn_foil/version.rb +0 -5
- data/lib/sn_foil.rb +0 -49
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: snfoil
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Howes
|
8
8
|
- Danny Murphy
|
9
9
|
- Cliff Campbell
|
10
|
-
autorequire:
|
11
|
-
bindir:
|
10
|
+
autorequire:
|
11
|
+
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2022-05-18 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
@@ -55,19 +55,61 @@ dependencies:
|
|
55
55
|
- !ruby/object:Gem::Version
|
56
56
|
version: '2.0'
|
57
57
|
- !ruby/object:Gem::Dependency
|
58
|
-
name:
|
58
|
+
name: snfoil-context
|
59
59
|
requirement: !ruby/object:Gem::Requirement
|
60
60
|
requirements:
|
61
61
|
- - "~>"
|
62
62
|
- !ruby/object:Gem::Version
|
63
|
-
version: '
|
63
|
+
version: '1.0'
|
64
|
+
type: :runtime
|
65
|
+
prerelease: false
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - "~>"
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '1.0'
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: snfoil-policy
|
73
|
+
requirement: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - "~>"
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '1.0'
|
78
|
+
type: :runtime
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - "~>"
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '1.0'
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: snfoil-searcher
|
87
|
+
requirement: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - "~>"
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '1.0'
|
92
|
+
type: :runtime
|
93
|
+
prerelease: false
|
94
|
+
version_requirements: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - "~>"
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '1.0'
|
99
|
+
- !ruby/object:Gem::Dependency
|
100
|
+
name: bundle-audit
|
101
|
+
requirement: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - "~>"
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: 0.1.0
|
64
106
|
type: :development
|
65
107
|
prerelease: false
|
66
108
|
version_requirements: !ruby/object:Gem::Requirement
|
67
109
|
requirements:
|
68
110
|
- - "~>"
|
69
111
|
- !ruby/object:Gem::Version
|
70
|
-
version:
|
112
|
+
version: 0.1.0
|
71
113
|
- !ruby/object:Gem::Dependency
|
72
114
|
name: dry-struct
|
73
115
|
requirement: !ruby/object:Gem::Requirement
|
@@ -82,6 +124,20 @@ dependencies:
|
|
82
124
|
- - "~>"
|
83
125
|
- !ruby/object:Gem::Version
|
84
126
|
version: '1.0'
|
127
|
+
- !ruby/object:Gem::Dependency
|
128
|
+
name: fasterer
|
129
|
+
requirement: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - "~>"
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: 0.10.0
|
134
|
+
type: :development
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - "~>"
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: 0.10.0
|
85
141
|
- !ruby/object:Gem::Dependency
|
86
142
|
name: pry-byebug
|
87
143
|
requirement: !ruby/object:Gem::Requirement
|
@@ -130,14 +186,14 @@ dependencies:
|
|
130
186
|
requirements:
|
131
187
|
- - "~>"
|
132
188
|
- !ruby/object:Gem::Version
|
133
|
-
version: '1.
|
189
|
+
version: '1.29'
|
134
190
|
type: :development
|
135
191
|
prerelease: false
|
136
192
|
version_requirements: !ruby/object:Gem::Requirement
|
137
193
|
requirements:
|
138
194
|
- - "~>"
|
139
195
|
- !ruby/object:Gem::Version
|
140
|
-
version: '1.
|
196
|
+
version: '1.29'
|
141
197
|
- !ruby/object:Gem::Dependency
|
142
198
|
name: rubocop-performance
|
143
199
|
requirement: !ruby/object:Gem::Requirement
|
@@ -166,7 +222,7 @@ dependencies:
|
|
166
222
|
- - "~>"
|
167
223
|
- !ruby/object:Gem::Version
|
168
224
|
version: '2.4'
|
169
|
-
description:
|
225
|
+
description: A collection of SnFoil gems and additional helper classes
|
170
226
|
email:
|
171
227
|
- howeszy@gmail.com
|
172
228
|
- dmurph24@gmail.com
|
@@ -175,30 +231,41 @@ executables: []
|
|
175
231
|
extensions: []
|
176
232
|
extra_rdoc_files: []
|
177
233
|
files:
|
234
|
+
- CHANGELOG.md
|
178
235
|
- CODE_OF_CONDUCT.md
|
236
|
+
- Gemfile
|
237
|
+
- LICENSE.txt
|
179
238
|
- README.md
|
180
|
-
- Rakefile
|
181
239
|
- TODO.md
|
182
|
-
-
|
183
|
-
-
|
184
|
-
-
|
185
|
-
-
|
186
|
-
-
|
187
|
-
-
|
188
|
-
- lib/
|
189
|
-
- lib/
|
190
|
-
- lib/
|
191
|
-
- lib/
|
192
|
-
- lib/
|
193
|
-
- lib/
|
194
|
-
- lib/
|
195
|
-
- lib/
|
196
|
-
- lib/
|
240
|
+
- docs/build-context.md
|
241
|
+
- docs/create-context.md
|
242
|
+
- docs/destroy-context.md
|
243
|
+
- docs/index-context.md
|
244
|
+
- docs/show-context.md
|
245
|
+
- docs/update-context.md
|
246
|
+
- lib/snfoil.rb
|
247
|
+
- lib/snfoil/adapters/orms/active_record.rb
|
248
|
+
- lib/snfoil/adapters/orms/base_adapter.rb
|
249
|
+
- lib/snfoil/crud/build_context.rb
|
250
|
+
- lib/snfoil/crud/change_context.rb
|
251
|
+
- lib/snfoil/crud/context.rb
|
252
|
+
- lib/snfoil/crud/create_context.rb
|
253
|
+
- lib/snfoil/crud/destroy_context.rb
|
254
|
+
- lib/snfoil/crud/index_context.rb
|
255
|
+
- lib/snfoil/crud/setup_context.rb
|
256
|
+
- lib/snfoil/crud/show_context.rb
|
257
|
+
- lib/snfoil/crud/update_context.rb
|
258
|
+
- lib/snfoil/version.rb
|
259
|
+
- snfoil.gemspec
|
197
260
|
homepage: https://github.com/limited-effort/snfoil
|
198
261
|
licenses:
|
199
|
-
-
|
200
|
-
metadata:
|
201
|
-
|
262
|
+
- Apache-2.0
|
263
|
+
metadata:
|
264
|
+
homepage_uri: https://github.com/limited-effort/snfoil
|
265
|
+
source_code_uri: https://github.com/limited-effort/snfoil
|
266
|
+
changelog_uri: https://github.com/limited-effort/snfoil/blob/main/CHANGELOG.md
|
267
|
+
rubygems_mfa_required: 'true'
|
268
|
+
post_install_message:
|
202
269
|
rdoc_options: []
|
203
270
|
require_paths:
|
204
271
|
- lib
|
@@ -206,15 +273,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
206
273
|
requirements:
|
207
274
|
- - ">="
|
208
275
|
- !ruby/object:Gem::Version
|
209
|
-
version: 2.
|
276
|
+
version: '2.7'
|
210
277
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
211
278
|
requirements:
|
212
279
|
- - ">="
|
213
280
|
- !ruby/object:Gem::Version
|
214
281
|
version: '0'
|
215
282
|
requirements: []
|
216
|
-
rubygems_version: 3.
|
217
|
-
signing_key:
|
283
|
+
rubygems_version: 3.1.6
|
284
|
+
signing_key:
|
218
285
|
specification_version: 4
|
219
|
-
summary: A
|
286
|
+
summary: A Toolbox of Context Behaviors
|
220
287
|
test_files: []
|
data/Rakefile
DELETED
data/lib/sn_foil/context.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'active_support/concern'
|
4
|
-
require_relative 'contexts/build_context'
|
5
|
-
require_relative 'contexts/index_context'
|
6
|
-
require_relative 'contexts/show_context'
|
7
|
-
require_relative 'contexts/create_context'
|
8
|
-
require_relative 'contexts/update_context'
|
9
|
-
require_relative 'contexts/destroy_context'
|
10
|
-
|
11
|
-
module SnFoil
|
12
|
-
module Context
|
13
|
-
extend ActiveSupport::Concern
|
14
|
-
|
15
|
-
included do
|
16
|
-
include Contexts::BuildContext
|
17
|
-
include Contexts::IndexContext
|
18
|
-
include Contexts::ShowContext
|
19
|
-
include Contexts::CreateContext
|
20
|
-
include Contexts::UpdateContext
|
21
|
-
include Contexts::DestroyContext
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,67 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'active_support/concern'
|
4
|
-
require_relative './setup_context'
|
5
|
-
|
6
|
-
module SnFoil
|
7
|
-
module Contexts
|
8
|
-
module BuildContext
|
9
|
-
extend ActiveSupport::Concern
|
10
|
-
|
11
|
-
included do
|
12
|
-
include SetupContext
|
13
|
-
end
|
14
|
-
|
15
|
-
class_methods do
|
16
|
-
attr_reader :i_setup_build_hooks
|
17
|
-
|
18
|
-
def build(params:, entity: nil, **options)
|
19
|
-
new(entity).build(**options, params: params)
|
20
|
-
end
|
21
|
-
|
22
|
-
def setup_build(method = nil, **options, &block)
|
23
|
-
raise ArgumentError, '#setup_build requires either a method name or a block' if method.nil? && block.nil?
|
24
|
-
|
25
|
-
(@i_setup_build_hooks ||= []) << { method: method, block: block, if: options[:if], unless: options[:unless] }
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def setup_build_object(params: {}, object: nil, **options)
|
30
|
-
object = if object
|
31
|
-
wrap_object(object)
|
32
|
-
else
|
33
|
-
klass = options.fetch(:model) { model }
|
34
|
-
wrap_object(klass).new
|
35
|
-
end
|
36
|
-
|
37
|
-
object.attributes = params
|
38
|
-
options.merge! object: object
|
39
|
-
end
|
40
|
-
|
41
|
-
def build(**options)
|
42
|
-
options[:action] = :build
|
43
|
-
options = before_setup_build_object(**options)
|
44
|
-
options = setup_build_object(**options)
|
45
|
-
authorize(options[:object], options[:authorize], **options) if options[:authorize]
|
46
|
-
unwrap_object(options[:object])
|
47
|
-
end
|
48
|
-
|
49
|
-
def setup_build(**options)
|
50
|
-
options
|
51
|
-
end
|
52
|
-
|
53
|
-
def setup_build_hooks
|
54
|
-
self.class.i_setup_build_hooks || []
|
55
|
-
end
|
56
|
-
|
57
|
-
private
|
58
|
-
|
59
|
-
def before_setup_build_object(**options)
|
60
|
-
options = setup(**options)
|
61
|
-
options = setup_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
|
62
|
-
options = setup_build(**options)
|
63
|
-
setup_build_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
@@ -1,101 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'active_support/concern'
|
4
|
-
require_relative './setup_context'
|
5
|
-
|
6
|
-
module SnFoil
|
7
|
-
module Contexts
|
8
|
-
module ChangeContext
|
9
|
-
extend ActiveSupport::Concern
|
10
|
-
|
11
|
-
included do
|
12
|
-
include SetupContext
|
13
|
-
end
|
14
|
-
|
15
|
-
class_methods do # rubocop:disable Metrics/BlockLength
|
16
|
-
attr_reader :i_params, :i_setup_change_hooks, :i_before_change_hooks, :i_after_change_hooks,
|
17
|
-
:i_after_change_success_hooks, :i_after_change_failure_hooks
|
18
|
-
|
19
|
-
def params(*permitted_params)
|
20
|
-
@i_params ||= []
|
21
|
-
@i_params |= permitted_params
|
22
|
-
end
|
23
|
-
|
24
|
-
def setup_change(method = nil, **options, &block)
|
25
|
-
raise ArgumentError, '#setup_change requires either a method name or a block' if method.nil? && block.nil?
|
26
|
-
|
27
|
-
(@i_setup_change_hooks ||= []) << { method: method, block: block, if: options[:if], unless: options[:unless] }
|
28
|
-
end
|
29
|
-
|
30
|
-
def before_change(method = nil, **options, &block)
|
31
|
-
raise ArgumentError, '#before_change requires either a method name or a block' if method.nil? && block.nil?
|
32
|
-
|
33
|
-
(@i_before_change_hooks ||= []) << { method: method, block: block, if: options[:if], unless: options[:unless] }
|
34
|
-
end
|
35
|
-
|
36
|
-
def after_change(method = nil, **options, &block)
|
37
|
-
raise ArgumentError, '#after_change requires either a method name or a block' if method.nil? && block.nil?
|
38
|
-
|
39
|
-
(@i_after_change_hooks ||= []) << { method: method, block: block, if: options[:if], unless: options[:unless] }
|
40
|
-
end
|
41
|
-
|
42
|
-
def after_change_success(method = nil, **options, &block)
|
43
|
-
raise ArgumentError, '#after_change_success requires either a method name or a block' if method.nil? && block.nil?
|
44
|
-
|
45
|
-
(@i_after_change_success_hooks ||= []) << { method: method, block: block, if: options[:if], unless: options[:unless] }
|
46
|
-
end
|
47
|
-
|
48
|
-
def after_change_failure(method = nil, **options, &block)
|
49
|
-
raise ArgumentError, '#after_change_failure requires either a method name or a block' if method.nil? && block.nil?
|
50
|
-
|
51
|
-
(@i_after_change_failure_hooks ||= []) << { method: method, block: block, if: options[:if], unless: options[:unless] }
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def param_names
|
56
|
-
@param_names ||= self.class.i_params
|
57
|
-
end
|
58
|
-
|
59
|
-
def setup_change(**options)
|
60
|
-
options[:params] = options[:params].select { |params| param_names.include?(params) } if param_names
|
61
|
-
options
|
62
|
-
end
|
63
|
-
|
64
|
-
def before_change(**options)
|
65
|
-
options
|
66
|
-
end
|
67
|
-
|
68
|
-
def after_change(**options)
|
69
|
-
options
|
70
|
-
end
|
71
|
-
|
72
|
-
def after_change_success(**options)
|
73
|
-
options
|
74
|
-
end
|
75
|
-
|
76
|
-
def after_change_failure(**options)
|
77
|
-
options
|
78
|
-
end
|
79
|
-
|
80
|
-
def setup_change_hooks
|
81
|
-
self.class.i_setup_change_hooks || []
|
82
|
-
end
|
83
|
-
|
84
|
-
def before_change_hooks
|
85
|
-
self.class.i_before_change_hooks || []
|
86
|
-
end
|
87
|
-
|
88
|
-
def after_change_hooks
|
89
|
-
self.class.i_after_change_hooks || []
|
90
|
-
end
|
91
|
-
|
92
|
-
def after_change_success_hooks
|
93
|
-
self.class.i_after_change_success_hooks || []
|
94
|
-
end
|
95
|
-
|
96
|
-
def after_change_failure_hooks
|
97
|
-
self.class.i_after_change_failure_hooks || []
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
@@ -1,158 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'active_support/concern'
|
4
|
-
require_relative './change_context'
|
5
|
-
|
6
|
-
module SnFoil
|
7
|
-
module Contexts
|
8
|
-
module CreateContext # rubocop:disable Metrics/ModuleLength
|
9
|
-
extend ActiveSupport::Concern
|
10
|
-
|
11
|
-
included do
|
12
|
-
include BuildContext
|
13
|
-
include ChangeContext
|
14
|
-
|
15
|
-
alias_method :setup_create_object, :setup_build_object
|
16
|
-
end
|
17
|
-
|
18
|
-
class_methods do
|
19
|
-
attr_reader :i_setup_create_hooks, :i_before_create_hooks, :i_after_create_hooks,
|
20
|
-
:i_after_create_success_hooks, :i_after_create_failure_hooks
|
21
|
-
|
22
|
-
def create(params:, entity: nil, **options)
|
23
|
-
new(entity).create(**options, params: params)
|
24
|
-
end
|
25
|
-
|
26
|
-
def setup_create(method = nil, **options, &block)
|
27
|
-
raise ArgumentError, '#setup_create requires either a method name or a block' if method.nil? && block.nil?
|
28
|
-
|
29
|
-
(@i_setup_create_hooks ||= []) << { method: method, block: block, if: options[:if], unless: options[:unless] }
|
30
|
-
end
|
31
|
-
|
32
|
-
def before_create(method = nil, **options, &block)
|
33
|
-
raise ArgumentError, '#before_create requires either a method name or a block' if method.nil? && block.nil?
|
34
|
-
|
35
|
-
(@i_before_create_hooks ||= []) << { method: method, block: block, if: options[:if], unless: options[:unless] }
|
36
|
-
end
|
37
|
-
|
38
|
-
def after_create(method = nil, **options, &block)
|
39
|
-
raise ArgumentError, '#after_create requires either a method name or a block' if method.nil? && block.nil?
|
40
|
-
|
41
|
-
(@i_after_create_hooks ||= []) << { method: method, block: block, if: options[:if], unless: options[:unless] }
|
42
|
-
end
|
43
|
-
|
44
|
-
def after_create_success(method = nil, **options, &block)
|
45
|
-
raise ArgumentError, '#after_create_success requires either a method name or a block' if method.nil? && block.nil?
|
46
|
-
|
47
|
-
(@i_after_create_success_hooks ||= []) << { method: method, block: block, if: options[:if], unless: options[:unless] }
|
48
|
-
end
|
49
|
-
|
50
|
-
def after_create_failure(method = nil, **options, &block)
|
51
|
-
raise ArgumentError, '#after_create_failure requires either a method name or a block' if method.nil? && block.nil?
|
52
|
-
|
53
|
-
(@i_after_create_failure_hooks ||= []) << { method: method, block: block, if: options[:if], unless: options[:unless] }
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def create(**options)
|
58
|
-
options[:action] = :create
|
59
|
-
options = before_setup_build_object(**options)
|
60
|
-
options = before_setup_create_object(**options)
|
61
|
-
options = setup_create_object(**options)
|
62
|
-
authorize(options[:object], options.fetch(:authorize, :create?), **options)
|
63
|
-
options = create_hooks(**options)
|
64
|
-
options[:object]
|
65
|
-
end
|
66
|
-
|
67
|
-
def setup_create(**options)
|
68
|
-
options
|
69
|
-
end
|
70
|
-
|
71
|
-
def before_create(**options)
|
72
|
-
options
|
73
|
-
end
|
74
|
-
|
75
|
-
def after_create(**options)
|
76
|
-
options
|
77
|
-
end
|
78
|
-
|
79
|
-
def after_create_success(**options)
|
80
|
-
options
|
81
|
-
end
|
82
|
-
|
83
|
-
def after_create_failure(**options)
|
84
|
-
options
|
85
|
-
end
|
86
|
-
|
87
|
-
def setup_create_hooks
|
88
|
-
self.class.i_setup_create_hooks || []
|
89
|
-
end
|
90
|
-
|
91
|
-
def before_create_hooks
|
92
|
-
self.class.i_before_create_hooks || []
|
93
|
-
end
|
94
|
-
|
95
|
-
def after_create_hooks
|
96
|
-
self.class.i_after_create_hooks || []
|
97
|
-
end
|
98
|
-
|
99
|
-
def after_create_success_hooks
|
100
|
-
self.class.i_after_create_success_hooks || []
|
101
|
-
end
|
102
|
-
|
103
|
-
def after_create_failure_hooks
|
104
|
-
self.class.i_after_create_failure_hooks || []
|
105
|
-
end
|
106
|
-
|
107
|
-
private
|
108
|
-
|
109
|
-
def before_setup_create_object(**options)
|
110
|
-
options = setup_change(**options)
|
111
|
-
options = setup_change_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
|
112
|
-
options = setup_create(**options)
|
113
|
-
setup_create_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
|
114
|
-
end
|
115
|
-
|
116
|
-
# This method is private to help protect the order of execution of hooks
|
117
|
-
def create_hooks(options)
|
118
|
-
options = before_create_save(**options)
|
119
|
-
save_successful = options[:object].save
|
120
|
-
options[:object] = unwrap_object(options[:object])
|
121
|
-
options = if save_successful
|
122
|
-
after_create_save_success(**options)
|
123
|
-
else
|
124
|
-
after_create_save_failure(**options)
|
125
|
-
end
|
126
|
-
after_create_save(**options)
|
127
|
-
end
|
128
|
-
|
129
|
-
def before_create_save(**options)
|
130
|
-
options = before_change(**options)
|
131
|
-
options = before_change_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
|
132
|
-
options = before_create(**options)
|
133
|
-
before_create_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
|
134
|
-
end
|
135
|
-
|
136
|
-
def after_create_save(**options)
|
137
|
-
options = after_change(**options)
|
138
|
-
options = after_change_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
|
139
|
-
options = after_create(**options)
|
140
|
-
after_create_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
|
141
|
-
end
|
142
|
-
|
143
|
-
def after_create_save_success(**options)
|
144
|
-
options = after_change_success(**options)
|
145
|
-
options = after_change_success_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
|
146
|
-
options = after_create_success(**options)
|
147
|
-
after_create_success_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
|
148
|
-
end
|
149
|
-
|
150
|
-
def after_create_save_failure(**options)
|
151
|
-
options = after_change_failure(**options)
|
152
|
-
options = after_change_failure_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
|
153
|
-
options = after_create_failure(**options)
|
154
|
-
after_create_failure_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
|
155
|
-
end
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|