controller_policies 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fa53cf4c7f5bfddf09fdf955300af7495177f5d3410983a43202733504d6169b
4
- data.tar.gz: 68c2cc086cb3cf7c49cc711a08f39ffa3ef3708bdb18add637a76e2e562b6e80
3
+ metadata.gz: 77ea62355c4991dfc6d3aa1da19d75bbb231e170c6451ed11cc43cb38d53f158
4
+ data.tar.gz: be3d3097f5385f681016c8fd7ee415fc3a6fbdf21acc1320ce6d8891c4f723d7
5
5
  SHA512:
6
- metadata.gz: c36da060a6497a6655e4affc6404142d29055830819a67ffd441aabe401b4ce6fb3c72061b9905e5a7485c9ebfc68cb1451caf5fef64a3ea7dc333d8c4ef4839
7
- data.tar.gz: c37a343a64bacc653e06420be3e1c3e5f1563692d996326de1112da645770dca5258cd145038d456c41705b2e79bc4110cc6ae3683db83647a540b72d8acaa69
6
+ metadata.gz: 289d8b06bca9542f79799779f2fba6444434ce41b85725e0c89cea6a182f5add24c5a32dbfbd9ed52aae4607cd36c9cd830db4b780fecf050075d1c15b94bd4a
7
+ data.tar.gz: 0d06f4170f6d708f487ce08e4533b93aaaac9916e342fa7a58eaeae3a86be0fde188459ea2299819cc6cc4c553402fc8d80373a00d2c98a3136f6a86ffc3513d
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
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.0'
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,14 +1,14 @@
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.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tien
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-07 00:00:00.000000000 Z
11
+ date: 2024-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -65,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
65
  - !ruby/object:Gem::Version
66
66
  version: '0'
67
67
  requirements: []
68
- rubygems_version: 3.5.3
68
+ rubygems_version: 3.5.11
69
69
  signing_key:
70
70
  specification_version: 4
71
71
  summary: Allows the developer to define policies for controllers.