snfoil 0.5.3 → 0.8.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/TODO.md +5 -0
- data/lib/sn_foil.rb +2 -0
- data/lib/sn_foil/adapters/orms/active_record.rb +9 -3
- data/lib/sn_foil/adapters/orms/base_adapter.rb +4 -2
- data/lib/sn_foil/contexts/build_context.rb +31 -7
- data/lib/sn_foil/contexts/create_context.rb +23 -33
- data/lib/sn_foil/contexts/destroy_context.rb +21 -19
- data/lib/sn_foil/contexts/index_context.rb +3 -3
- data/lib/sn_foil/contexts/show_context.rb +3 -3
- data/lib/sn_foil/contexts/update_context.rb +23 -20
- data/lib/sn_foil/searcher.rb +23 -5
- data/lib/sn_foil/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5029787f4c700bd7cd9e96bab7a1dc4e7b6b026d6ccef0da1bc180c3430b72cf
|
4
|
+
data.tar.gz: d699faeb7386a4d84f04d5df66802c08ee8f788008fa5d4c9331823417c20420
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f42e51e0d446fb0c6eee95dde45ea50da55e41c0a1a610fb95d3145531c2ebdd41be922485d71b5c5747a42e68814526c8a5973a41ed0604b0555e2affd7db80
|
7
|
+
data.tar.gz: 85fd3b571c33e1b48efd189b13c66654bca2e5b847250b11395e0855680150924223a209adc4b46135b18cdb13c9dd4ab62e2839975c0f95cf6f183cefea3d42
|
data/TODO.md
ADDED
data/lib/sn_foil.rb
CHANGED
@@ -10,6 +10,8 @@ require_relative 'sn_foil/contexts/destroy_context'
|
|
10
10
|
require_relative 'sn_foil/context'
|
11
11
|
require_relative 'sn_foil/policy'
|
12
12
|
require_relative 'sn_foil/searcher'
|
13
|
+
require_relative 'sn_foil/adapters/orms/base_adapter'
|
14
|
+
require_relative 'sn_foil/adapters/orms/active_record'
|
13
15
|
require 'active_support/core_ext/module/attribute_accessors'
|
14
16
|
require 'logger'
|
15
17
|
|
@@ -1,11 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative 'base_adapter'
|
4
|
+
|
3
5
|
module SnFoil
|
4
6
|
module Adapters
|
5
7
|
module ORMs
|
6
8
|
class ActiveRecord < SnFoil::Adapters::ORMs::BaseAdapter
|
7
|
-
def new(
|
8
|
-
self.class.new(__getobj__.new(
|
9
|
+
def new(**params)
|
10
|
+
self.class.new(__getobj__.new(params))
|
9
11
|
end
|
10
12
|
|
11
13
|
def all
|
@@ -21,9 +23,13 @@ module SnFoil
|
|
21
23
|
__getobj__.destroyed?
|
22
24
|
end
|
23
25
|
|
24
|
-
def attributes=(
|
26
|
+
def attributes=(attributes)
|
25
27
|
__getobj__.attributes = attributes
|
26
28
|
end
|
29
|
+
|
30
|
+
def is_a?(klass)
|
31
|
+
__getobj__.class.object_id == klass.object_id
|
32
|
+
end
|
27
33
|
end
|
28
34
|
end
|
29
35
|
end
|
@@ -1,10 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'delegate'
|
4
|
+
|
3
5
|
module SnFoil
|
4
6
|
module Adapters
|
5
7
|
module ORMs
|
6
8
|
class BaseAdapter < SimpleDelegator
|
7
|
-
def new(
|
9
|
+
def new(**_params)
|
8
10
|
raise NotImplementedError, '#new not implemented in adapter'
|
9
11
|
end
|
10
12
|
|
@@ -20,7 +22,7 @@ module SnFoil
|
|
20
22
|
raise NotImplementedError, '#destroy not implemented in adapter'
|
21
23
|
end
|
22
24
|
|
23
|
-
def attributes=(
|
25
|
+
def attributes=(_attributes)
|
24
26
|
raise NotImplementedError, '#attributes= not implemented in adapter'
|
25
27
|
end
|
26
28
|
end
|
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
require 'active_support/concern'
|
4
4
|
require_relative './setup_context'
|
5
|
-
require_relative './change_context'
|
6
5
|
|
7
6
|
module SnFoil
|
8
7
|
module Contexts
|
@@ -11,33 +10,58 @@ module SnFoil
|
|
11
10
|
|
12
11
|
included do
|
13
12
|
include SetupContext
|
14
|
-
include ChangeContext
|
15
13
|
end
|
16
14
|
|
17
15
|
class_methods do
|
16
|
+
attr_reader :i_setup_build_hooks
|
17
|
+
|
18
18
|
def build(params:, entity: nil, **options)
|
19
19
|
new(entity).build(**options, params: params)
|
20
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
|
21
27
|
end
|
22
28
|
|
23
29
|
def setup_build_object(params: {}, object: nil, **options)
|
24
|
-
|
25
|
-
|
30
|
+
object = if object
|
31
|
+
wrap_object(object)
|
32
|
+
else
|
33
|
+
klass = options.fetch(:model) { model }
|
34
|
+
wrap_object(klass).new
|
35
|
+
end
|
26
36
|
|
27
|
-
|
28
|
-
options.merge! object:
|
37
|
+
object.attributes = params
|
38
|
+
options.merge! object: object
|
29
39
|
end
|
30
40
|
|
31
41
|
def build(**options)
|
32
42
|
options[:action] = :build
|
33
|
-
options =
|
43
|
+
options = before_setup_build_object(**options)
|
34
44
|
options = setup_build_object(**options)
|
45
|
+
authorize(options[:object], options[:authorize], **options) if options[:authorize]
|
35
46
|
unwrap_object(options[:object])
|
36
47
|
end
|
37
48
|
|
38
49
|
def setup_build(**options)
|
39
50
|
options
|
40
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
|
41
65
|
end
|
42
66
|
end
|
43
67
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'active_support/concern'
|
4
|
-
require_relative './setup_context'
|
5
4
|
require_relative './change_context'
|
6
5
|
|
7
6
|
module SnFoil
|
@@ -10,8 +9,10 @@ module SnFoil
|
|
10
9
|
extend ActiveSupport::Concern
|
11
10
|
|
12
11
|
included do
|
13
|
-
include
|
12
|
+
include BuildContext
|
14
13
|
include ChangeContext
|
14
|
+
|
15
|
+
alias_method :setup_create_object, :setup_build_object
|
15
16
|
end
|
16
17
|
|
17
18
|
class_methods do
|
@@ -52,25 +53,14 @@ module SnFoil
|
|
52
53
|
end
|
53
54
|
end
|
54
55
|
|
55
|
-
def setup_create_object(params: {}, object: nil, **options)
|
56
|
-
object = if object
|
57
|
-
wrap_object(object)
|
58
|
-
else
|
59
|
-
klass = options.fetch(:model) { model }
|
60
|
-
wrap_object(klass).new
|
61
|
-
end
|
62
|
-
|
63
|
-
object.attributes = params
|
64
|
-
options.merge! object: object
|
65
|
-
end
|
66
|
-
|
67
56
|
def create(**options)
|
68
57
|
options[:action] = :create
|
58
|
+
options = before_setup_build_object(**options)
|
69
59
|
options = before_setup_create_object(**options)
|
70
60
|
options = setup_create_object(**options)
|
71
|
-
authorize(options[:object], :create
|
61
|
+
authorize(options[:object], options.fetch(:authorize) { :create? }, **options)
|
72
62
|
options = create_hooks(**options)
|
73
|
-
|
63
|
+
options[:object]
|
74
64
|
end
|
75
65
|
|
76
66
|
def setup_create(**options)
|
@@ -116,18 +106,18 @@ module SnFoil
|
|
116
106
|
private
|
117
107
|
|
118
108
|
def before_setup_create_object(**options)
|
119
|
-
options = setup_create(**options)
|
120
|
-
options = setup_create_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
|
121
109
|
options = setup_change(**options)
|
122
110
|
options = setup_change_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
|
123
|
-
options =
|
124
|
-
|
111
|
+
options = setup_create(**options)
|
112
|
+
setup_create_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
|
125
113
|
end
|
126
114
|
|
127
115
|
# This method is private to help protect the order of execution of hooks
|
128
116
|
def create_hooks(options)
|
129
117
|
options = before_create_save(**options)
|
130
|
-
|
118
|
+
save_successful = options[:object].save
|
119
|
+
options.merge!(object: unwrap_object(options[:object]))
|
120
|
+
options = if save_successful
|
131
121
|
after_create_save_success(**options)
|
132
122
|
else
|
133
123
|
after_create_save_failure(**options)
|
@@ -136,31 +126,31 @@ module SnFoil
|
|
136
126
|
end
|
137
127
|
|
138
128
|
def before_create_save(**options)
|
139
|
-
options = before_create(**options)
|
140
|
-
options = before_create_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
|
141
129
|
options = before_change(**options)
|
142
|
-
before_change_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
|
130
|
+
options = before_change_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
|
131
|
+
options = before_create(**options)
|
132
|
+
before_create_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
|
143
133
|
end
|
144
134
|
|
145
135
|
def after_create_save(**options)
|
146
|
-
options = after_create(**options)
|
147
|
-
options = after_create_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
|
148
136
|
options = after_change(**options)
|
149
|
-
after_change_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
|
137
|
+
options = after_change_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
|
138
|
+
options = after_create(**options)
|
139
|
+
after_create_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
|
150
140
|
end
|
151
141
|
|
152
142
|
def after_create_save_success(**options)
|
153
|
-
options = after_create_success(**options)
|
154
|
-
options = after_create_success_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
|
155
143
|
options = after_change_success(**options)
|
156
|
-
after_change_success_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
|
144
|
+
options = after_change_success_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
|
145
|
+
options = after_create_success(**options)
|
146
|
+
after_create_success_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
|
157
147
|
end
|
158
148
|
|
159
149
|
def after_create_save_failure(**options)
|
160
|
-
options = after_create_failure(**options)
|
161
|
-
options = after_create_failure_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
|
162
150
|
options = after_change_failure(**options)
|
163
|
-
after_change_failure_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
|
151
|
+
options = after_change_failure_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
|
152
|
+
options = after_create_failure(**options)
|
153
|
+
after_create_failure_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
|
164
154
|
end
|
165
155
|
end
|
166
156
|
end
|
@@ -62,9 +62,9 @@ module SnFoil
|
|
62
62
|
options[:action] = :destroy
|
63
63
|
options = before_setup_destroy_object(**options)
|
64
64
|
options = setup_destroy_object(**options)
|
65
|
-
authorize(options[:object], :destroy
|
65
|
+
authorize(options[:object], options.fetch(:authorize) { :destroy? }, **options)
|
66
66
|
options = destroy_hooks(**options)
|
67
|
-
|
67
|
+
options[:object]
|
68
68
|
end
|
69
69
|
|
70
70
|
def setup_destroy(**options)
|
@@ -110,18 +110,20 @@ module SnFoil
|
|
110
110
|
private
|
111
111
|
|
112
112
|
def before_setup_destroy_object(**options)
|
113
|
-
options =
|
114
|
-
options =
|
113
|
+
options = setup(**options)
|
114
|
+
options = setup_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
|
115
115
|
options = setup_change(**options)
|
116
116
|
options = setup_change_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
|
117
|
-
options =
|
118
|
-
|
117
|
+
options = setup_destroy(**options)
|
118
|
+
setup_destroy_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
|
119
119
|
end
|
120
120
|
|
121
121
|
# This method is private to help protect the order of execution of hooks
|
122
122
|
def destroy_hooks(options)
|
123
123
|
options = before_destroy_save(options)
|
124
|
-
|
124
|
+
destroy_successful = options[:object].destroy
|
125
|
+
options.merge!(object: unwrap_object(options[:object]))
|
126
|
+
options = if destroy_successful
|
125
127
|
after_destroy_save_success(options)
|
126
128
|
else
|
127
129
|
after_destroy_save_failure(options)
|
@@ -130,31 +132,31 @@ module SnFoil
|
|
130
132
|
end
|
131
133
|
|
132
134
|
def before_destroy_save(options)
|
133
|
-
options = before_destroy(**options)
|
134
|
-
options = before_destroy_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
|
135
135
|
options = before_change(**options)
|
136
|
-
before_change_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
|
136
|
+
options = before_change_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
|
137
|
+
options = before_destroy(**options)
|
138
|
+
before_destroy_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
|
137
139
|
end
|
138
140
|
|
139
141
|
def after_destroy_save(options)
|
140
|
-
options = after_destroy(**options)
|
141
|
-
options = after_destroy_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
|
142
142
|
options = after_change(**options)
|
143
|
-
after_change_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
|
143
|
+
options = after_change_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
|
144
|
+
options = after_destroy(**options)
|
145
|
+
after_destroy_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
|
144
146
|
end
|
145
147
|
|
146
148
|
def after_destroy_save_success(options)
|
147
|
-
options = after_destroy_success(**options)
|
148
|
-
options = after_destroy_success_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
|
149
149
|
options = after_change_success(**options)
|
150
|
-
after_change_success_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
|
150
|
+
options = after_change_success_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
|
151
|
+
options = after_destroy_success(**options)
|
152
|
+
after_destroy_success_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
|
151
153
|
end
|
152
154
|
|
153
155
|
def after_destroy_save_failure(options)
|
154
|
-
options = after_destroy_failure(**options)
|
155
|
-
options = after_destroy_failure_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
|
156
156
|
options = after_change_failure(**options)
|
157
|
-
after_change_failure_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
|
157
|
+
options = after_change_failure_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
|
158
|
+
options = after_destroy_failure(**options)
|
159
|
+
after_destroy_failure_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
|
158
160
|
end
|
159
161
|
end
|
160
162
|
end
|
@@ -54,10 +54,10 @@ module SnFoil
|
|
54
54
|
private
|
55
55
|
|
56
56
|
def before_setup_index(**options)
|
57
|
-
options = setup_index(**options)
|
58
|
-
options = setup_index_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
|
59
57
|
options = setup(**options)
|
60
|
-
setup_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
|
58
|
+
options = setup_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
|
59
|
+
options = setup_index(**options)
|
60
|
+
setup_index_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
|
61
61
|
end
|
62
62
|
end
|
63
63
|
end
|
@@ -51,10 +51,10 @@ module SnFoil
|
|
51
51
|
private
|
52
52
|
|
53
53
|
def before_setup_show(**options)
|
54
|
-
options = setup_show(**options)
|
55
|
-
options = setup_show_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
|
56
54
|
options = setup(**options)
|
57
|
-
setup_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
|
55
|
+
options = setup_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
|
56
|
+
options = setup_show(**options)
|
57
|
+
setup_show_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
|
58
58
|
end
|
59
59
|
end
|
60
60
|
end
|
@@ -56,7 +56,8 @@ module SnFoil
|
|
56
56
|
raise ArgumentError, 'one of the following keywords is required: id, object' unless id || object
|
57
57
|
|
58
58
|
object = wrap_object(object || scope.resolve.find(id))
|
59
|
-
authorize(object, :update
|
59
|
+
authorize(object, options.fetch(:authorize) { :update? }, **options)
|
60
|
+
|
60
61
|
object.attributes = params
|
61
62
|
options.merge! object: object
|
62
63
|
end
|
@@ -65,9 +66,9 @@ module SnFoil
|
|
65
66
|
options[:action] = :update
|
66
67
|
options = before_setup_update_object(**options)
|
67
68
|
options = setup_update_object(**options)
|
68
|
-
authorize(options[:object], :update
|
69
|
+
authorize(options[:object], options.fetch(:authorize) { :update? }, **options)
|
69
70
|
options = update_hooks(**options)
|
70
|
-
|
71
|
+
options[:object]
|
71
72
|
end
|
72
73
|
|
73
74
|
def setup_update(**options)
|
@@ -113,18 +114,20 @@ module SnFoil
|
|
113
114
|
private
|
114
115
|
|
115
116
|
def before_setup_update_object(**options)
|
116
|
-
options =
|
117
|
-
options =
|
117
|
+
options = setup(**options)
|
118
|
+
options = setup_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
|
118
119
|
options = setup_change(**options)
|
119
120
|
options = setup_change_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
|
120
|
-
options =
|
121
|
-
|
121
|
+
options = setup_update(**options)
|
122
|
+
setup_update_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
|
122
123
|
end
|
123
124
|
|
124
125
|
# This method is private to help protect the order of execution of hooks
|
125
126
|
def update_hooks(options)
|
126
127
|
options = before_update_save(options)
|
127
|
-
|
128
|
+
update_successful = options[:object].save
|
129
|
+
options.merge!(object: unwrap_object(options[:object]))
|
130
|
+
options = if update_successful
|
128
131
|
after_update_save_success(options)
|
129
132
|
else
|
130
133
|
after_update_save_failure(options)
|
@@ -133,31 +136,31 @@ module SnFoil
|
|
133
136
|
end
|
134
137
|
|
135
138
|
def before_update_save(options)
|
136
|
-
options = before_update(**options)
|
137
|
-
options = before_update_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
|
138
139
|
options = before_change(**options)
|
139
|
-
before_change_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
|
140
|
+
options = before_change_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
|
141
|
+
options = before_update(**options)
|
142
|
+
before_update_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
|
140
143
|
end
|
141
144
|
|
142
145
|
def after_update_save(options)
|
143
|
-
options = after_update(**options)
|
144
|
-
options = after_update_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
|
145
146
|
options = after_change(**options)
|
146
|
-
after_change_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
|
147
|
+
options = after_change_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
|
148
|
+
options = after_update(**options)
|
149
|
+
after_update_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
|
147
150
|
end
|
148
151
|
|
149
152
|
def after_update_save_success(options)
|
150
|
-
options = after_update_success(**options)
|
151
|
-
options = after_update_success_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
|
152
153
|
options = after_change_success(**options)
|
153
|
-
after_change_success_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
|
154
|
+
options = after_change_success_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
|
155
|
+
options = after_update_success(**options)
|
156
|
+
after_update_success_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
|
154
157
|
end
|
155
158
|
|
156
159
|
def after_update_save_failure(options)
|
157
|
-
options = after_update_failure(**options)
|
158
|
-
options = after_update_failure_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
|
159
160
|
options = after_change_failure(**options)
|
160
|
-
after_change_failure_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
|
161
|
+
options = after_change_failure_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
|
162
|
+
options = after_update_failure(**options)
|
163
|
+
after_update_failure_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
|
161
164
|
end
|
162
165
|
end
|
163
166
|
end
|
data/lib/sn_foil/searcher.rb
CHANGED
@@ -7,7 +7,7 @@ module SnFoil
|
|
7
7
|
extend ActiveSupport::Concern
|
8
8
|
|
9
9
|
class_methods do
|
10
|
-
attr_reader :i_model, :i_setup, :i_filters, :i_search_step
|
10
|
+
attr_reader :i_model, :i_setup, :i_filters, :i_search_step, :i_booleans
|
11
11
|
|
12
12
|
def model(klass = nil)
|
13
13
|
@i_model = klass
|
@@ -27,6 +27,11 @@ module SnFoil
|
|
27
27
|
unless: options[:unless]
|
28
28
|
}
|
29
29
|
end
|
30
|
+
|
31
|
+
def booleans(*fields)
|
32
|
+
@i_booleans ||= []
|
33
|
+
@i_booleans |= fields.map(&:to_sym)
|
34
|
+
end
|
30
35
|
end
|
31
36
|
|
32
37
|
def model
|
@@ -55,6 +60,10 @@ module SnFoil
|
|
55
60
|
self.class.i_filters || []
|
56
61
|
end
|
57
62
|
|
63
|
+
def booleans
|
64
|
+
self.class.i_booleans || []
|
65
|
+
end
|
66
|
+
|
58
67
|
private
|
59
68
|
|
60
69
|
def apply_setup(filtered_scope, params)
|
@@ -90,15 +99,24 @@ module SnFoil
|
|
90
99
|
|
91
100
|
def transform_params_booleans(params)
|
92
101
|
params.map do |key, value|
|
93
|
-
value = if
|
94
|
-
|
95
|
-
elsif value == 'false'
|
96
|
-
false
|
102
|
+
value = if booleans.include?(key.to_sym)
|
103
|
+
value_to_boolean(value)
|
97
104
|
else
|
98
105
|
value
|
99
106
|
end
|
100
107
|
[key, value]
|
101
108
|
end.to_h
|
102
109
|
end
|
110
|
+
|
111
|
+
def value_to_boolean(value)
|
112
|
+
string_val = value.to_s
|
113
|
+
if value == true || %w[true 1].include?(string_val)
|
114
|
+
true
|
115
|
+
elsif value == false || %w[false 0].include?(string_val)
|
116
|
+
false
|
117
|
+
else
|
118
|
+
value
|
119
|
+
end
|
120
|
+
end
|
103
121
|
end
|
104
122
|
end
|
data/lib/sn_foil/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: snfoil
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Howes
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2021-03-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -162,6 +162,7 @@ files:
|
|
162
162
|
- CODE_OF_CONDUCT.md
|
163
163
|
- README.md
|
164
164
|
- Rakefile
|
165
|
+
- TODO.md
|
165
166
|
- lib/sn_foil.rb
|
166
167
|
- lib/sn_foil/adapters/orms/active_record.rb
|
167
168
|
- lib/sn_foil/adapters/orms/base_adapter.rb
|
@@ -196,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
196
197
|
- !ruby/object:Gem::Version
|
197
198
|
version: '0'
|
198
199
|
requirements: []
|
199
|
-
rubygems_version: 3.
|
200
|
+
rubygems_version: 3.1.4
|
200
201
|
signing_key:
|
201
202
|
specification_version: 4
|
202
203
|
summary: A boilerplate gem for providing basic contexts
|