snfoil 0.8.5 → 0.9.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4928d412e07ea8d2b871bbfafd71e430b6d3e9c31cb9e88779efcd567db0217c
4
- data.tar.gz: d46e69bde8bcd3c5480d18773868d9c28f24e35ef2ed92f3e1e153f47ff655c5
3
+ metadata.gz: 9305e42cc7834940ece8bf069f7c5bf8679cec9637bb30b0d8ff5fcb5b6f39f4
4
+ data.tar.gz: 35d137221f8a63b51890d203077e8a2d0639ec56b0644e7e980e6fea4fc4d72c
5
5
  SHA512:
6
- metadata.gz: ad4e04abe56529ede7e5c1e911f1d123367b0329d350dba3387f233d97e25d04886ee361272a22222671980b89999370e1b4af72b7a859ee99dd4bdb8b1b4b17
7
- data.tar.gz: 6ea04352aff4d71af5cb9c724289825f1be838217c4cd2517612ca4dc6e2f0cc1308efe87311d7ff3124d575d60628471f02ca71236053c55087bc340ce318c8
6
+ metadata.gz: e7ef5d7fb7dba65e461124bf025fb2a15645d020fde9a8495b9784223d1108b8b27c7367177bec4b7defe2def5c68af10d9e5f8b680770f65a128759732cd82a
7
+ data.tar.gz: f02ac14a8f0550324eed27c7b19b6a1500ae8e2329106a8903647b6fc7ab983c685be1b5d6d8ddd50c50a697c00e58536017441595dc02f5a567a80a74d295c4
@@ -6,7 +6,7 @@ module SnFoil
6
6
  module Adapters
7
7
  module ORMs
8
8
  class BaseAdapter < SimpleDelegator
9
- def new(**_params)
9
+ def new(*_params)
10
10
  raise NotImplementedError, '#new not implemented in adapter'
11
11
  end
12
12
 
@@ -35,8 +35,7 @@ module SnFoil
35
35
  end
36
36
 
37
37
  object.attributes = params
38
- options[:object] = object
39
- options
38
+ options.merge! object: object
40
39
  end
41
40
 
42
41
  def build(**options)
@@ -59,9 +58,9 @@ module SnFoil
59
58
 
60
59
  def before_setup_build_object(**options)
61
60
  options = setup(**options)
62
- options = setup_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
61
+ options = setup_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
63
62
  options = setup_build(**options)
64
- setup_build_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
63
+ setup_build_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
65
64
  end
66
65
  end
67
66
  end
@@ -108,9 +108,9 @@ module SnFoil
108
108
 
109
109
  def before_setup_create_object(**options)
110
110
  options = setup_change(**options)
111
- options = setup_change_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
111
+ options = setup_change_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
112
112
  options = setup_create(**options)
113
- setup_create_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
113
+ setup_create_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
114
114
  end
115
115
 
116
116
  # This method is private to help protect the order of execution of hooks
@@ -128,30 +128,30 @@ module SnFoil
128
128
 
129
129
  def before_create_save(**options)
130
130
  options = before_change(**options)
131
- options = before_change_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
131
+ options = before_change_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
132
132
  options = before_create(**options)
133
- before_create_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
133
+ before_create_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
134
134
  end
135
135
 
136
136
  def after_create_save(**options)
137
137
  options = after_change(**options)
138
- options = after_change_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
138
+ options = after_change_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
139
139
  options = after_create(**options)
140
- after_create_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
140
+ after_create_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
141
141
  end
142
142
 
143
143
  def after_create_save_success(**options)
144
144
  options = after_change_success(**options)
145
- options = after_change_success_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
145
+ options = after_change_success_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
146
146
  options = after_create_success(**options)
147
- after_create_success_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
147
+ after_create_success_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
148
148
  end
149
149
 
150
150
  def after_create_save_failure(**options)
151
151
  options = after_change_failure(**options)
152
- options = after_change_failure_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
152
+ options = after_change_failure_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
153
153
  options = after_create_failure(**options)
154
- after_create_failure_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
154
+ after_create_failure_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
155
155
  end
156
156
  end
157
157
  end
@@ -56,8 +56,7 @@ module SnFoil
56
56
  def setup_destroy_object(id: nil, object: nil, **options)
57
57
  raise ArgumentError, 'one of the following keywords is required: id, object' unless id || object
58
58
 
59
- options[:object] = wrap_object(object || scope.resolve.find(id))
60
- options
59
+ options.merge! object: wrap_object(object || scope.resolve.find(id))
61
60
  end
62
61
 
63
62
  def destroy(**options)
@@ -113,11 +112,11 @@ module SnFoil
113
112
 
114
113
  def before_setup_destroy_object(**options)
115
114
  options = setup(**options)
116
- options = setup_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
115
+ options = setup_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
117
116
  options = setup_change(**options)
118
- options = setup_change_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
117
+ options = setup_change_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
119
118
  options = setup_destroy(**options)
120
- setup_destroy_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
119
+ setup_destroy_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
121
120
  end
122
121
 
123
122
  # This method is private to help protect the order of execution of hooks
@@ -55,9 +55,9 @@ module SnFoil
55
55
 
56
56
  def before_setup_index(**options)
57
57
  options = setup(**options)
58
- options = setup_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
58
+ options = setup_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
59
59
  options = setup_index(**options)
60
- setup_index_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
60
+ setup_index_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
61
61
  end
62
62
  end
63
63
  end
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'pundit'
4
3
  require 'active_support/concern'
5
4
  require 'active_support/core_ext/string/inflections'
6
5
 
@@ -91,7 +90,7 @@ module SnFoil
91
90
 
92
91
  return send(hook[:method], **options) if hook[:method]
93
92
 
94
- instance_exec options, &hook[:block]
93
+ instance_exec **options, &hook[:block]
95
94
  end
96
95
 
97
96
  def hook_valid?(hook, **options)
@@ -105,11 +104,10 @@ module SnFoil
105
104
 
106
105
  def lookup_policy(object, options)
107
106
  lookup = if options[:policy]
108
- options[:policy].new(entity, object, options: options)
107
+ options[:policy].new(entity, object)
109
108
  elsif policy
110
- policy.new(entity, object, options: options)
109
+ policy.new(entity, object)
111
110
  else
112
- SnFoil.logger.debug 'No policy found. Looking up policy using Pundit. `options` will not be passed to policy'
113
111
  Pundit.policy!(entity, object)
114
112
  end
115
113
 
@@ -29,8 +29,7 @@ module SnFoil
29
29
  def setup_show_object(id: nil, object: nil, **options)
30
30
  raise ArgumentError, 'one of the following keywords is required: id, object' unless id || object
31
31
 
32
- options[:object] = wrap_object(object || scope.resolve.find(id))
33
- options
32
+ options.merge! object: wrap_object(object || scope.resolve.find(id))
34
33
  end
35
34
 
36
35
  def setup_show_hooks
@@ -53,9 +52,9 @@ module SnFoil
53
52
 
54
53
  def before_setup_show(**options)
55
54
  options = setup(**options)
56
- options = setup_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
55
+ options = setup_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
57
56
  options = setup_show(**options)
58
- setup_show_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
57
+ setup_show_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
59
58
  end
60
59
  end
61
60
  end
@@ -19,7 +19,7 @@ module SnFoil
19
19
  :i_after_update_success_hooks, :i_after_update_failure_hooks
20
20
 
21
21
  def update(id:, params:, entity: nil, **options)
22
- new(entity).update(**options, id: id, params: params)
22
+ new(entity).update(id: id, **options, params: params)
23
23
  end
24
24
 
25
25
  def setup_update(method = nil, **options, &block)
@@ -60,8 +60,7 @@ module SnFoil
60
60
  authorize(object, options.fetch(:authorize, :update?), **options)
61
61
 
62
62
  object.attributes = params
63
- options[:object] = object
64
- options
63
+ options.merge! object: object
65
64
  end
66
65
 
67
66
  def update(**options)
@@ -117,11 +116,11 @@ module SnFoil
117
116
 
118
117
  def before_setup_update_object(**options)
119
118
  options = setup(**options)
120
- options = setup_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
119
+ options = setup_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
121
120
  options = setup_change(**options)
122
- options = setup_change_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
121
+ options = setup_change_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
123
122
  options = setup_update(**options)
124
- setup_update_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) }
123
+ setup_update_hooks.reduce(options) { |opts, hook| run_hook(hook, **opts) }
125
124
  end
126
125
 
127
126
  # This method is private to help protect the order of execution of hooks
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SnFoil
4
- VERSION = '0.8.5'
4
+ VERSION = '0.9.0'
5
5
  end
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.8.5
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Howes
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2021-09-19 00:00:00.000000000 Z
13
+ date: 2023-02-20 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -213,7 +213,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
213
213
  - !ruby/object:Gem::Version
214
214
  version: '0'
215
215
  requirements: []
216
- rubygems_version: 3.1.6
216
+ rubygems_version: 3.4.7
217
217
  signing_key:
218
218
  specification_version: 4
219
219
  summary: A boilerplate gem for providing basic contexts