snfoil 0.8.4 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/Gemfile +6 -0
  4. data/LICENSE.txt +201 -0
  5. data/README.md +95 -505
  6. data/docs/build-context.md +56 -0
  7. data/docs/create-context.md +109 -0
  8. data/docs/destroy-context.md +102 -0
  9. data/docs/index-context.md +70 -0
  10. data/docs/show-context.md +71 -0
  11. data/docs/update-context.md +107 -0
  12. data/lib/{sn_foil → snfoil}/adapters/orms/active_record.rb +14 -0
  13. data/lib/{sn_foil → snfoil}/adapters/orms/base_adapter.rb +14 -0
  14. data/lib/snfoil/crud/build_context.rb +49 -0
  15. data/lib/snfoil/crud/change_context.rb +48 -0
  16. data/lib/snfoil/crud/context.rb +41 -0
  17. data/lib/snfoil/crud/create_context.rb +45 -0
  18. data/lib/snfoil/crud/destroy_context.rb +57 -0
  19. data/lib/snfoil/crud/index_context.rb +46 -0
  20. data/lib/snfoil/crud/setup_context.rb +90 -0
  21. data/lib/snfoil/crud/show_context.rb +52 -0
  22. data/lib/snfoil/crud/update_context.rb +60 -0
  23. data/lib/snfoil/version.rb +19 -0
  24. data/lib/snfoil.rb +69 -0
  25. data/snfoil.gemspec +47 -0
  26. metadata +124 -39
  27. data/Rakefile +0 -4
  28. data/lib/sn_foil/context.rb +0 -24
  29. data/lib/sn_foil/contexts/build_context.rb +0 -68
  30. data/lib/sn_foil/contexts/change_context.rb +0 -101
  31. data/lib/sn_foil/contexts/create_context.rb +0 -158
  32. data/lib/sn_foil/contexts/destroy_context.rb +0 -165
  33. data/lib/sn_foil/contexts/index_context.rb +0 -64
  34. data/lib/sn_foil/contexts/setup_context.rb +0 -120
  35. data/lib/sn_foil/contexts/show_context.rb +0 -62
  36. data/lib/sn_foil/contexts/update_context.rb +0 -169
  37. data/lib/sn_foil/policy.rb +0 -55
  38. data/lib/sn_foil/searcher.rb +0 -123
  39. data/lib/sn_foil/version.rb +0 -5
  40. 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.8.4
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Howes
8
8
  - Danny Murphy
9
9
  - Cliff Campbell
10
10
  autorequire:
11
- bindir: bin
11
+ bindir: exe
12
12
  cert_chain: []
13
- date: 2021-09-17 00:00:00.000000000 Z
13
+ date: 2022-08-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -55,19 +55,79 @@ dependencies:
55
55
  - !ruby/object:Gem::Version
56
56
  version: '2.0'
57
57
  - !ruby/object:Gem::Dependency
58
- name: bundler
58
+ name: snfoil-context
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 1.0.1
64
+ - - "<"
65
+ - !ruby/object:Gem::Version
66
+ version: '2.0'
67
+ type: :runtime
68
+ prerelease: false
69
+ version_requirements: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: 1.0.1
74
+ - - "<"
75
+ - !ruby/object:Gem::Version
76
+ version: '2.0'
77
+ - !ruby/object:Gem::Dependency
78
+ name: snfoil-policy
79
+ requirement: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: 1.0.1
84
+ - - "<"
85
+ - !ruby/object:Gem::Version
86
+ version: '2.0'
87
+ type: :runtime
88
+ prerelease: false
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: 1.0.1
94
+ - - "<"
95
+ - !ruby/object:Gem::Version
96
+ version: '2.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: snfoil-searcher
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: 1.0.1
104
+ - - "<"
105
+ - !ruby/object:Gem::Version
106
+ version: '2.0'
107
+ type: :runtime
108
+ prerelease: false
109
+ version_requirements: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: 1.0.1
114
+ - - "<"
115
+ - !ruby/object:Gem::Version
116
+ version: '2.0'
117
+ - !ruby/object:Gem::Dependency
118
+ name: bundle-audit
59
119
  requirement: !ruby/object:Gem::Requirement
60
120
  requirements:
61
121
  - - "~>"
62
122
  - !ruby/object:Gem::Version
63
- version: '2.2'
123
+ version: 0.1.0
64
124
  type: :development
65
125
  prerelease: false
66
126
  version_requirements: !ruby/object:Gem::Requirement
67
127
  requirements:
68
128
  - - "~>"
69
129
  - !ruby/object:Gem::Version
70
- version: '2.2'
130
+ version: 0.1.0
71
131
  - !ruby/object:Gem::Dependency
72
132
  name: dry-struct
73
133
  requirement: !ruby/object:Gem::Requirement
@@ -82,6 +142,20 @@ dependencies:
82
142
  - - "~>"
83
143
  - !ruby/object:Gem::Version
84
144
  version: '1.0'
145
+ - !ruby/object:Gem::Dependency
146
+ name: fasterer
147
+ requirement: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - "~>"
150
+ - !ruby/object:Gem::Version
151
+ version: 0.10.0
152
+ type: :development
153
+ prerelease: false
154
+ version_requirements: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - "~>"
157
+ - !ruby/object:Gem::Version
158
+ version: 0.10.0
85
159
  - !ruby/object:Gem::Dependency
86
160
  name: pry-byebug
87
161
  requirement: !ruby/object:Gem::Requirement
@@ -128,45 +202,45 @@ dependencies:
128
202
  name: rubocop
129
203
  requirement: !ruby/object:Gem::Requirement
130
204
  requirements:
131
- - - "~>"
205
+ - - '='
132
206
  - !ruby/object:Gem::Version
133
- version: '1.18'
207
+ version: '1.33'
134
208
  type: :development
135
209
  prerelease: false
136
210
  version_requirements: !ruby/object:Gem::Requirement
137
211
  requirements:
138
- - - "~>"
212
+ - - '='
139
213
  - !ruby/object:Gem::Version
140
- version: '1.18'
214
+ version: '1.33'
141
215
  - !ruby/object:Gem::Dependency
142
216
  name: rubocop-performance
143
217
  requirement: !ruby/object:Gem::Requirement
144
218
  requirements:
145
- - - "~>"
219
+ - - '='
146
220
  - !ruby/object:Gem::Version
147
- version: '1.11'
221
+ version: 1.14.3
148
222
  type: :development
149
223
  prerelease: false
150
224
  version_requirements: !ruby/object:Gem::Requirement
151
225
  requirements:
152
- - - "~>"
226
+ - - '='
153
227
  - !ruby/object:Gem::Version
154
- version: '1.11'
228
+ version: 1.14.3
155
229
  - !ruby/object:Gem::Dependency
156
230
  name: rubocop-rspec
157
231
  requirement: !ruby/object:Gem::Requirement
158
232
  requirements:
159
- - - "~>"
233
+ - - '='
160
234
  - !ruby/object:Gem::Version
161
- version: '2.4'
235
+ version: 2.12.1
162
236
  type: :development
163
237
  prerelease: false
164
238
  version_requirements: !ruby/object:Gem::Requirement
165
239
  requirements:
166
- - - "~>"
240
+ - - '='
167
241
  - !ruby/object:Gem::Version
168
- version: '2.4'
169
- description:
242
+ version: 2.12.1
243
+ description: A collection of SnFoil gems and additional helper classes
170
244
  email:
171
245
  - howeszy@gmail.com
172
246
  - dmurph24@gmail.com
@@ -175,29 +249,40 @@ executables: []
175
249
  extensions: []
176
250
  extra_rdoc_files: []
177
251
  files:
252
+ - CHANGELOG.md
178
253
  - CODE_OF_CONDUCT.md
254
+ - Gemfile
255
+ - LICENSE.txt
179
256
  - README.md
180
- - Rakefile
181
257
  - TODO.md
182
- - lib/sn_foil.rb
183
- - lib/sn_foil/adapters/orms/active_record.rb
184
- - lib/sn_foil/adapters/orms/base_adapter.rb
185
- - lib/sn_foil/context.rb
186
- - lib/sn_foil/contexts/build_context.rb
187
- - lib/sn_foil/contexts/change_context.rb
188
- - lib/sn_foil/contexts/create_context.rb
189
- - lib/sn_foil/contexts/destroy_context.rb
190
- - lib/sn_foil/contexts/index_context.rb
191
- - lib/sn_foil/contexts/setup_context.rb
192
- - lib/sn_foil/contexts/show_context.rb
193
- - lib/sn_foil/contexts/update_context.rb
194
- - lib/sn_foil/policy.rb
195
- - lib/sn_foil/searcher.rb
196
- - lib/sn_foil/version.rb
258
+ - docs/build-context.md
259
+ - docs/create-context.md
260
+ - docs/destroy-context.md
261
+ - docs/index-context.md
262
+ - docs/show-context.md
263
+ - docs/update-context.md
264
+ - lib/snfoil.rb
265
+ - lib/snfoil/adapters/orms/active_record.rb
266
+ - lib/snfoil/adapters/orms/base_adapter.rb
267
+ - lib/snfoil/crud/build_context.rb
268
+ - lib/snfoil/crud/change_context.rb
269
+ - lib/snfoil/crud/context.rb
270
+ - lib/snfoil/crud/create_context.rb
271
+ - lib/snfoil/crud/destroy_context.rb
272
+ - lib/snfoil/crud/index_context.rb
273
+ - lib/snfoil/crud/setup_context.rb
274
+ - lib/snfoil/crud/show_context.rb
275
+ - lib/snfoil/crud/update_context.rb
276
+ - lib/snfoil/version.rb
277
+ - snfoil.gemspec
197
278
  homepage: https://github.com/limited-effort/snfoil
198
279
  licenses:
199
- - MIT
200
- metadata: {}
280
+ - Apache-2.0
281
+ metadata:
282
+ homepage_uri: https://github.com/limited-effort/snfoil
283
+ source_code_uri: https://github.com/limited-effort/snfoil
284
+ changelog_uri: https://github.com/limited-effort/snfoil/blob/main/CHANGELOG.md
285
+ rubygems_mfa_required: 'true'
201
286
  post_install_message:
202
287
  rdoc_options: []
203
288
  require_paths:
@@ -206,7 +291,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
206
291
  requirements:
207
292
  - - ">="
208
293
  - !ruby/object:Gem::Version
209
- version: 2.5.0
294
+ version: '2.6'
210
295
  required_rubygems_version: !ruby/object:Gem::Requirement
211
296
  requirements:
212
297
  - - ">="
@@ -216,5 +301,5 @@ requirements: []
216
301
  rubygems_version: 3.1.6
217
302
  signing_key:
218
303
  specification_version: 4
219
- summary: A boilerplate gem for providing basic contexts
304
+ summary: A Toolbox of Context Behaviors
220
305
  test_files: []
data/Rakefile DELETED
@@ -1,4 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'bundler/gem_tasks'
4
- task default: :spec
@@ -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,68 +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[:object] = object
39
- options
40
- end
41
-
42
- def build(**options)
43
- options[:action] = :build
44
- options = before_setup_build_object(**options)
45
- options = setup_build_object(**options)
46
- authorize(options[:object], options[:authorize], **options) if options[:authorize]
47
- unwrap_object(options[:object])
48
- end
49
-
50
- def setup_build(**options)
51
- options
52
- end
53
-
54
- def setup_build_hooks
55
- self.class.i_setup_build_hooks || []
56
- end
57
-
58
- private
59
-
60
- def before_setup_build_object(**options)
61
- options = setup(**options)
62
- options = setup_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
63
- options = setup_build(**options)
64
- setup_build_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
65
- end
66
- end
67
- end
68
- 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