action_authorization 0.3.0 → 0.3.2

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: 54416a7e815288367cea967a9198f197cc2fe10e76e35fcac702406c8b5f8215
4
- data.tar.gz: 6097c18236273bf1ebce5439813ae6383805a2a66f264321fac402d64792aa2d
3
+ metadata.gz: b488de453a34ffee8f9f686af35f9a4221fed24ee7dea3a56475efc295b70f5a
4
+ data.tar.gz: 384e891ca0486d7952121c45941eaea65eddae2e40812259da09a373358aba89
5
5
  SHA512:
6
- metadata.gz: e3274dbb63f416cd663a7f47f817d7551fe3abdabaa222d0c067c2fad8e7503a074347a469a43c311c018b949d5bff0bbc36253381d38dc045ac92288295a7d1
7
- data.tar.gz: f6fb7dbb58d0933b4c96623093fda6c8b902b5af769b2c2298ac35e053e39da9a659ea8bc86c8d1b4bb3b3d5ad188a7e4894c3f7a8603cb4f38fb7d56f5bdc61
6
+ metadata.gz: 6a2579a9fec0b4115fc9980b535f549fd1b5c31f9ca4180f57d1b7d726d72cb0b78caedd683fca501ffa10ce52e1cf1e873e429cb703e58e2a7d7c3cf57418a0
7
+ data.tar.gz: 8c889dc5dd44b874a5d22a9b8b4225b4b5b7c5a8dc01530ac80df8c2fb31830e1115433a2f7d156bb12191430d9e73ddc214d26fe4209d0e88a5b944f776f6a4
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/setup"
2
4
 
3
5
  require "bundler/gem_tasks"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActionAuthorization
2
4
  class AuthorizationFailure < StandardError
3
5
  end
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActionAuthorization
2
4
  class BasePolicy
3
5
  attr_accessor :user, :object
4
6
 
5
7
  def self.type
6
- name.gsub('Policy', '')
8
+ name.delete_suffix("Policy")
7
9
  end
8
10
 
9
11
  def self.type_class
@@ -14,13 +16,14 @@ module ActionAuthorization
14
16
 
15
17
  delegate :type, :type_class, to: :class
16
18
 
17
- def initialize(user, object)
19
+ def initialize(user, object = nil)
18
20
  self.user = user
19
21
  self.object = object
20
22
  end
21
23
 
22
24
  # create alias to object from subclass name
23
25
  def self.inherited(klass)
26
+ super
24
27
  klass.send(:alias_method, klass.type.underscore, :object)
25
28
  end
26
29
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActionAuthorization
2
- VERSION = "0.3.0"
4
+ VERSION = "0.3.2"
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support/core_ext/module/delegation"
2
4
  require "active_support/core_ext/string/inflections"
3
5
  require "action_authorization/version"
@@ -14,11 +16,9 @@ module ActionAuthorization
14
16
  protected
15
17
 
16
18
  def authorize(object, action: action_name, policy_class: nil)
17
- if policy(object, policy_class).send("#{action}?")
18
- object
19
- else
20
- raise ActionAuthorization::AuthorizationFailure
21
- end
19
+ raise AuthorizationFailure unless policy(object, policy_class).public_send(:"#{action}?")
20
+
21
+ object
22
22
  end
23
23
 
24
24
  def policy(object, policy_class = nil)
@@ -26,6 +26,6 @@ module ActionAuthorization
26
26
  end
27
27
 
28
28
  def policy_class_for(object)
29
- "#{object.class.name}Policy".constantize
29
+ "#{object.model_name}Policy".constantize
30
30
  end
31
31
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: action_authorization
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Baldwin
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-01-30 00:00:00.000000000 Z
12
+ date: 2024-09-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -45,7 +45,6 @@ licenses:
45
45
  - MIT
46
46
  metadata:
47
47
  homepage_uri: https://github.com/wwidea/action_authorization
48
- source_code_uri: https://github.com/wwidea/action_authorization
49
48
  rubygems_mfa_required: 'true'
50
49
  post_install_message:
51
50
  rdoc_options: []
@@ -55,14 +54,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
55
54
  requirements:
56
55
  - - ">="
57
56
  - !ruby/object:Gem::Version
58
- version: 2.7.0
57
+ version: 3.1.0
59
58
  required_rubygems_version: !ruby/object:Gem::Requirement
60
59
  requirements:
61
60
  - - ">="
62
61
  - !ruby/object:Gem::Version
63
62
  version: '0'
64
63
  requirements: []
65
- rubygems_version: 3.4.5
64
+ rubygems_version: 3.5.11
66
65
  signing_key:
67
66
  specification_version: 4
68
67
  summary: Rails controller object-level action authorization.