controller_policies 0.2.0 → 1.0.1

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: fa53cf4c7f5bfddf09fdf955300af7495177f5d3410983a43202733504d6169b
4
- data.tar.gz: 68c2cc086cb3cf7c49cc711a08f39ffa3ef3708bdb18add637a76e2e562b6e80
3
+ metadata.gz: 6bce0f759505e11b5f05fd9d220d1f8553a1b1a281f50a40b51533a160a225fd
4
+ data.tar.gz: e5f9d53c8bfe61e53e546c760fe0eba07d298717f5306f99575da4c8f60c4fb5
5
5
  SHA512:
6
- metadata.gz: c36da060a6497a6655e4affc6404142d29055830819a67ffd441aabe401b4ce6fb3c72061b9905e5a7485c9ebfc68cb1451caf5fef64a3ea7dc333d8c4ef4839
7
- data.tar.gz: c37a343a64bacc653e06420be3e1c3e5f1563692d996326de1112da645770dca5258cd145038d456c41705b2e79bc4110cc6ae3683db83647a540b72d8acaa69
6
+ metadata.gz: 2b25df0839fdc02faf866a769f1102175ecda41fbf6e018ea735c981c712354270768af5770dc266cc9fc998cddc0ae6316c90b54570fb5faa4abf06c8c43d8b
7
+ data.tar.gz: da0373ebea81108926b63a898b0b9955aff0a9383a2fd4e49d7da0ea67c6784429550edb9d1312c34534a50aa4bc531bc1002f5f606b796431e773fa494f7827
data/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  Add this line to your application's Gemfile:
6
6
 
7
7
  ```ruby
8
- gem 'controller_policies', '~> 0.1'
8
+ gem 'controller_policies', '~> 1.0'
9
9
  ```
10
10
 
11
11
  ## Usage
@@ -29,13 +29,15 @@ The `actions` key is an array of strings that contain a list of supported contro
29
29
  For example, you have this definition:
30
30
 
31
31
  ```ruby
32
- module Base
33
- DEFINITIONS = {
34
- code: 'policy_code',
35
- name: 'Policy Name',
36
- description: 'I am a policy.',
37
- actions: ['feature_app/users', 'data_app/products#index', 'subscriptions']
38
- }
32
+ module Policies
33
+ module Base
34
+ DEFINITIONS = {
35
+ code: 'policy_code',
36
+ name: 'Policy Name',
37
+ description: 'I am a policy.',
38
+ actions: ['feature_app/users', 'data_app/products#index', 'subscriptions']
39
+ }
40
+ end
39
41
  end
40
42
  ```
41
43
 
@@ -122,7 +124,11 @@ Ability.all_codes
122
124
  Filter abilities based on namespace. `queries` can be an array of Strings, Modules or Classes.
123
125
 
124
126
  ```ruby
125
- Ability.where(FeatureOne, FeatureTwo, FeatureOne::SubFeatureA)
127
+ Ability.where(Policies::FeatureOne, Policies::FeatureTwo, Policies::FeatureOne::SubFeatureA)
128
+ ```
129
+
130
+ ```ruby
131
+ Ability.where('/feature_one', '/feature_two', '/feature_one/sub_feature_a')
126
132
  ```
127
133
 
128
134
  #### #match(expression)
@@ -130,7 +136,7 @@ Ability.where(FeatureOne, FeatureTwo, FeatureOne::SubFeatureA)
130
136
  Match abilities based on a matching string or regex. The matcher is based on the namespace. `expression` can be a Regexp or String.
131
137
 
132
138
  ```ruby
133
- Ability.match(/FeatureOne(::)?(.)*/)
139
+ Ability.match(/Policies::FeatureOne(::)?(.)*/)
134
140
  ```
135
141
 
136
142
  ### Instance Methods
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
27
27
  spec.require_paths = ['lib']
28
28
 
29
29
  # Uncomment to register a new dependency of your gem
30
- spec.add_dependency 'rails', '~> 7'
30
+ spec.add_dependency 'rails', '>= 7', '< 9'
31
31
 
32
32
  # For more information and examples about making a new gem, check out our
33
33
  # guide at: https://bundler.io/guides/creating_gem.html
data/lib/ability.rb CHANGED
@@ -38,7 +38,7 @@ class Ability
38
38
  queries.each do |query|
39
39
  case query.class.to_s
40
40
  when 'String'
41
- results += all.select { |ability| ability.namespace.to_s == trim(query).camelize }
41
+ results += all.select { |ability| ability.namespace.to_s == "Policies::#{trim(query).camelize}" }
42
42
  when 'Module', 'Class'
43
43
  results += all.select { |ability| ability.namespace == query }
44
44
  end
@@ -82,7 +82,7 @@ class Ability
82
82
  end
83
83
 
84
84
  def definition_files_post_processing(file_path)
85
- module_constant = convert_namespace(file_path)
85
+ module_constant = "Policies::#{convert_namespace(file_path)}".constantize
86
86
  policy_definitions = module_constant::DEFINITIONS
87
87
  policy_definitions.map do |policy_definition|
88
88
  policy_definition[:namespace] = module_constant
@@ -101,7 +101,7 @@ class Ability
101
101
  end
102
102
 
103
103
  def convert_namespace(file_path)
104
- trim(file_path[policy_path.to_s.length..-4].split('/')[0...-1].join('/')).camelize.constantize
104
+ trim(file_path[policy_path.to_s.length..-4].split('/')[0...-1].join('/')).camelize
105
105
  end
106
106
  end
107
107
  end
@@ -10,5 +10,9 @@ module ControllerPolicies
10
10
 
11
11
  define_method(:ability?, &block)
12
12
  end
13
+
14
+ def no_enforced_policies(arguments = {})
15
+ skip_before_action :check_abilities_by_definition, arguments
16
+ end
13
17
  end
14
18
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ControllerPolicies
4
- VERSION = '0.2.0'
4
+ VERSION = '1.0.1'
5
5
  end
@@ -1,22 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module <%= name.camelize %>
4
- DEFINITIONS = [
5
- {
6
- # Used as identifier for the policy.
7
- code: 'Policy-Code',
8
- # Readable name for the policy.
9
- name: 'Readable Policy Name',
10
- # Readable description for the policy.
11
- description: 'Short description of what this policy allows',
12
- # Controller actions the policy applies to. It works as matchers based on routes.
13
- # It can be empty for manual policy checking.
14
- actions: ['feature_app/users', 'data_app/products#index', 'subscriptions']
15
- },
16
- {
17
- code: 'Another-Policy-Code',
18
- name: 'Another Policy',
19
- description: 'Long description.',
20
- }
21
- ].freeze
3
+ module Policies
4
+ module <%= name.camelize %>
5
+ DEFINITIONS = [
6
+ {
7
+ # Used as identifier for the policy.
8
+ code: 'Policy-Code',
9
+ # Readable name for the policy.
10
+ name: 'Readable Policy Name',
11
+ # Readable description for the policy.
12
+ description: 'Short description of what this policy allows',
13
+ # Controller actions the policy applies to. It works as matchers based on routes.
14
+ # It can be empty for manual policy checking.
15
+ actions: ['feature_app/users', 'data_app/products#index', 'subscriptions']
16
+ },
17
+ {
18
+ code: 'Another-Policy-Code',
19
+ name: 'Another Policy',
20
+ description: 'Long description.',
21
+ }
22
+ ].freeze
23
+ end
22
24
  end
metadata CHANGED
@@ -1,30 +1,34 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: controller_policies
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tien
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-05-07 00:00:00.000000000 Z
10
+ date: 2025-03-03 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: rails
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
- - - "~>"
16
+ - - ">="
18
17
  - !ruby/object:Gem::Version
19
18
  version: '7'
19
+ - - "<"
20
+ - !ruby/object:Gem::Version
21
+ version: '9'
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
23
25
  requirements:
24
- - - "~>"
26
+ - - ">="
25
27
  - !ruby/object:Gem::Version
26
28
  version: '7'
27
- description:
29
+ - - "<"
30
+ - !ruby/object:Gem::Version
31
+ version: '9'
28
32
  email:
29
33
  - tieeeeen1994@gmail.com
30
34
  executables: []
@@ -50,7 +54,6 @@ licenses:
50
54
  metadata:
51
55
  homepage_uri: https://github.com/tieeeeen1994/rails-controller-policies
52
56
  rubygems_mfa_required: 'true'
53
- post_install_message:
54
57
  rdoc_options: []
55
58
  require_paths:
56
59
  - lib
@@ -65,8 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
68
  - !ruby/object:Gem::Version
66
69
  version: '0'
67
70
  requirements: []
68
- rubygems_version: 3.5.3
69
- signing_key:
71
+ rubygems_version: 3.6.5
70
72
  specification_version: 4
71
73
  summary: Allows the developer to define policies for controllers.
72
74
  test_files: []