snfoil 0.4.0 → 0.5.3

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: '08550dd2ea79c81a206bd765375d240a28ff5fadc734c279cbace455ae617650'
4
- data.tar.gz: 934a30ee35d2c6e07f739e0e01c219efcbb6e9bb782b341477a70b06f51a60fd
3
+ metadata.gz: f6aa27a0dd5398b8e3abea471b5e8d3548aa4ff5239edabe7ee229306bde4787
4
+ data.tar.gz: 358b5e5b46347c30768272c5f50c08aa8f61a3fb44a016f26504a700f82c2c11
5
5
  SHA512:
6
- metadata.gz: 96ac100420b4276442ccc955cfb5b35f93ea60bd11af4fdb4725b0e6a0a307e67391016dbab97cdeffc3af0532d419526138cb3770d76c1e8ed4388813fbc66a
7
- data.tar.gz: f8d3cb25b57174aeea76be073d9a37b6fb12862cd0e6b5986468d33051038e84412315221db13a26d5a5f1b9e5b61d4143afcd10620045f69bb8a00420ad30b9
6
+ metadata.gz: cf0c36ee0cf32bdf2f43503aec6076f8115df1f84e9cb0b954c7d58d0ea2583236d2dd7dd9dcab14f2ccb7680b8e004ae43fdcfcfc0df627681d2c1e365b077c
7
+ data.tar.gz: 613b3ce470d9c567d4fa06c915a1610e8b3ad35d26691f69455dc4e95cad874497bcbf21ca40f7f717df506730f7ecbc8b0f0a297393b6dbd166c7cdf1c76d6c
@@ -15,8 +15,8 @@ module SnFoil
15
15
  end
16
16
 
17
17
  class_methods do
18
- def build(params:, user: nil, **options)
19
- new(user).build(**options, params: params)
18
+ def build(params:, entity: nil, **options)
19
+ new(entity).build(**options, params: params)
20
20
  end
21
21
  end
22
22
 
@@ -17,8 +17,8 @@ module SnFoil
17
17
  class_methods do
18
18
  attr_reader :i_setup_create_hooks, :i_before_create_hooks, :i_after_create_hooks,
19
19
  :i_after_create_success_hooks, :i_after_create_failure_hooks
20
- def create(params:, user: nil, **options)
21
- new(user).create(**options, params: params)
20
+ def create(params:, entity: nil, **options)
21
+ new(entity).create(**options, params: params)
22
22
  end
23
23
 
24
24
  def setup_create(method = nil, **options, &block)
@@ -17,8 +17,8 @@ module SnFoil
17
17
  class_methods do
18
18
  attr_reader :i_setup_destroy_hooks, :i_before_destroy_hooks, :i_after_destroy_hooks,
19
19
  :i_after_destroy_success_hooks, :i_after_destroy_failure_hooks
20
- def destroy(id:, user: nil, **options)
21
- new(user).destroy(**options, id: id)
20
+ def destroy(id:, entity: nil, **options)
21
+ new(entity).destroy(**options, id: id)
22
22
  end
23
23
 
24
24
  def setup_destroy(method = nil, **options, &block)
@@ -15,8 +15,8 @@ module SnFoil
15
15
  class_methods do
16
16
  attr_reader :i_searcher, :i_setup_index_hooks
17
17
 
18
- def index(params: {}, user: nil, **options)
19
- new(user).index(**options, params: params)
18
+ def index(params: {}, entity: nil, **options)
19
+ new(entity).index(**options, params: params)
20
20
  end
21
21
 
22
22
  def searcher(klass = nil)
@@ -38,13 +38,13 @@ module SnFoil
38
38
  self.class.i_setup_index_hooks || []
39
39
  end
40
40
 
41
- def index(params:, **options)
41
+ def index(**options)
42
42
  options[:action] = :index
43
43
  options = before_setup_index(**options)
44
44
  authorize(nil, :index?, **options)
45
45
  options.fetch(:searcher) { searcher }
46
46
  .new(scope: scope.resolve)
47
- .search(params: params)
47
+ .search(options.fetch(:params) { {} })
48
48
  end
49
49
 
50
50
  def setup_index(**options)
@@ -42,13 +42,13 @@ module SnFoil
42
42
  self.class.i_setup_hooks || []
43
43
  end
44
44
 
45
- attr_reader :user
46
- def initialize(user = nil)
47
- @user = user
45
+ attr_reader :entity
46
+ def initialize(entity = nil)
47
+ @entity = entity
48
48
  end
49
49
 
50
50
  def authorize(object, action, **options)
51
- return unless user # Add logging
51
+ return unless entity # Add logging
52
52
 
53
53
  policy = lookup_policy(object, options)
54
54
  raise Pundit::NotAuthorizedError, query: action, record: object, policy: policy unless policy.public_send(action)
@@ -59,7 +59,7 @@ module SnFoil
59
59
  def scope(object_class = nil, **options)
60
60
  object_class ||= model
61
61
  policy_name = lookup_policy(object_class, options).class.name
62
- "#{policy_name}::Scope".safe_constantize.new(wrap_object(object_class), user)
62
+ "#{policy_name}::Scope".safe_constantize.new(wrap_object(object_class), entity)
63
63
  end
64
64
 
65
65
  def wrap_object(object)
@@ -103,11 +103,11 @@ module SnFoil
103
103
 
104
104
  def lookup_policy(object, options)
105
105
  lookup = if options[:policy]
106
- options[:policy].new(user, object)
106
+ options[:policy].new(entity, object)
107
107
  elsif policy
108
- policy.new(user, object)
108
+ policy.new(entity, object)
109
109
  else
110
- Pundit.policy!(user, object)
110
+ Pundit.policy!(entity, object)
111
111
  end
112
112
 
113
113
  lookup.options = options if lookup.respond_to? :options=
@@ -15,8 +15,8 @@ module SnFoil
15
15
  class_methods do
16
16
  attr_reader :i_setup_show_hooks
17
17
 
18
- def show(id:, user: nil, **options)
19
- new(user).show(**options, id: id)
18
+ def show(id:, entity: nil, **options)
19
+ new(entity).show(**options, id: id)
20
20
  end
21
21
 
22
22
  def setup_show(method = nil, **options, &block)
@@ -17,8 +17,8 @@ module SnFoil
17
17
  class_methods do
18
18
  attr_reader :i_setup_update_hooks, :i_before_update_hooks, :i_after_update_hooks,
19
19
  :i_after_update_success_hooks, :i_after_update_failure_hooks
20
- def update(id:, params:, user: nil, **options)
21
- new(user).update(**options, id: id, params: params)
20
+ def update(id:, params:, entity: nil, **options)
21
+ new(entity).update(**options, id: id, params: params)
22
22
  end
23
23
 
24
24
  def setup_update(method = nil, **options, &block)
@@ -63,7 +63,7 @@ module SnFoil
63
63
  if setup.is_a?(Symbol) || setup.is_a?(String)
64
64
  send(setup, filtered_scope, params)
65
65
  else
66
- setup.call(filtered_scope, params)
66
+ instance_exec filtered_scope, params, &setup
67
67
  end
68
68
  end
69
69
 
@@ -78,7 +78,7 @@ module SnFoil
78
78
 
79
79
  return send(i_filter[:method], filtered_scope, params) if i_filter[:method]
80
80
 
81
- i_filter[:block].call(filtered_scope, params)
81
+ instance_exec filtered_scope, params, &i_filter[:block]
82
82
  end
83
83
 
84
84
  def filter_valid?(i_filter, params)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SnFoil
4
- VERSION = '0.4.0'
4
+ VERSION = '0.5.3'
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.4.0
4
+ version: 0.5.3
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: 2020-03-04 00:00:00.000000000 Z
12
+ date: 2020-06-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: '5.1'
20
+ version: 5.2.4.3
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: '5.1'
27
+ version: 5.2.4.3
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: logger
30
30
  requirement: !ruby/object:Gem::Requirement