ii_policy 1.1.0 → 2.0.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: 62f7efd3ac2e7db1c4c9532e987e3ed592083cec2e00f5cca700c5c5a5bab4e6
4
- data.tar.gz: e6df72f0fae98ff640ff6f87bc8bf3a1297c4470c64c45e5449b9ab439c96bdc
3
+ metadata.gz: 12f75fa515f57c1d7cb21138025c5fea4f8202ecfdde800abec38451c54c9604
4
+ data.tar.gz: 5b52a7b58ed0eb07e3ff42165518e3be2b79f41846a6d34c92a0c4090c90b51a
5
5
  SHA512:
6
- metadata.gz: 928646d051e6296eff7dcb3330f8080c36fba6949ffd706165e598f8849d1cf5d6084a4eaf15daab013f289783087a1406c3417c6fb096c963ffd858e4f0c8dc
7
- data.tar.gz: e21fbbf89718aa908b42acd332b85178cfe7ab8ca9c5b11525b1c0454f6475df77820e4604bc3c275f46359ac32ac9d800107444973b95bc785593d72a6d37a2
6
+ metadata.gz: '0933c5f001415a5c54ab3a89d3485d62579f0a7c0cb4a4519934dc68a17843eed920feeb44356c7f4d0e04203fd8e28f8541211ce448aa7c468de51fda0a13d8'
7
+ data.tar.gz: 73b0729f99bfd3ed83a13fa4ffda3ec091934b03b834f6a522667dacd822ffac4294ad11ea332cc40f5de53dabd58cd61e6726dcc1a62619fa80aaf9c131e67d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 2.0.0
4
+
5
+ * Replace chain feature with coactive.
6
+
3
7
  ## 1.1.0
4
8
 
5
9
  * Support method and block for `chain`.
data/README.md CHANGED
@@ -175,9 +175,9 @@ class ItemPolicy < IIPolicy::Base
175
175
  end
176
176
  ```
177
177
 
178
- #### Policy chain
178
+ #### Coactors
179
179
 
180
- You can chain shared policies to base policy by using `chain` as follows:
180
+ You can define multiple coactors by using `coact` as follows:
181
181
 
182
182
  ```ruby
183
183
  # shared policy
@@ -189,7 +189,7 @@ end
189
189
 
190
190
  # base policy
191
191
  class ItemPolicy < IIPolicy::Base
192
- chain SharedPolicy
192
+ coact SharedPolicy
193
193
 
194
194
  def show?
195
195
  @item.status != 'deleted'
@@ -203,22 +203,7 @@ policy.allowed(:show?)
203
203
 
204
204
  In this example, `policy.allowed(:show?)` is evaluated by `SharedPolicy#show? && ItemPolicy#show?`.
205
205
 
206
- You can also use method or block to find policy class dynamically:
207
-
208
- ```ruby
209
- class ItemPolicy < IIPolicy::Base
210
- chain -> { SharedPolicy }
211
- end
212
-
213
- class ItemPolicy < IIPolicy::Base
214
- chain :chain_policy
215
-
216
- def chain_policy
217
- SharedPolicy
218
- end
219
- end
220
- ```
221
-
206
+ See [coactive](https://github.com/kanety/coactive) for more `coact` examples:
222
207
 
223
208
  ### Lookup for policy
224
209
 
data/ii_policy.gemspec CHANGED
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.require_paths = ["lib"]
19
19
 
20
20
  spec.add_dependency "activesupport", ">= 5.0"
21
+ spec.add_dependency "coactive", ">= 0.1"
21
22
 
22
23
  spec.add_development_dependency "rails", ">= 5.0"
23
24
  spec.add_development_dependency "sqlite3"
@@ -5,7 +5,7 @@ require_relative 'core'
5
5
  require_relative 'callbacks'
6
6
  require_relative 'instrumentation'
7
7
  require_relative 'lookup'
8
- require_relative 'chain'
8
+ require_relative 'coactors'
9
9
 
10
10
  module IIPolicy
11
11
  class Base
@@ -13,6 +13,6 @@ module IIPolicy
13
13
  include Callbacks
14
14
  include Instrumentation
15
15
  include Lookup
16
- include Chain
16
+ include Coactors
17
17
  end
18
18
  end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IIPolicy
4
+ module Coactors
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ include Coactive::Base
9
+
10
+ configure_coactive do |config|
11
+ config.load_paths = ['app/policies']
12
+ config.class_suffix = 'Policy'
13
+ config.use_cache = true
14
+ config.lookup_superclass_until = ['ActiveRecord::Base', 'ActiveModel::Base']
15
+ end
16
+
17
+ class << self
18
+ alias_method :chain, :coact
19
+ end
20
+ end
21
+
22
+ def call(action)
23
+ coactors.each do |policy|
24
+ return false unless policy.new(@context).call(action)
25
+ end
26
+ super
27
+ end
28
+ end
29
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IIPolicy
4
- VERSION = '1.1.0'
4
+ VERSION = '2.0.0'
5
5
  end
data/lib/ii_policy.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'active_support'
2
+ require 'coactive'
2
3
 
3
4
  require 'ii_policy/version'
4
5
  require 'ii_policy/config'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ii_policy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yoshikazu Kaneta
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-07-19 00:00:00.000000000 Z
11
+ date: 2021-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '5.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: coactive
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0.1'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rails
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -120,7 +134,7 @@ files:
120
134
  - lib/ii_policy.rb
121
135
  - lib/ii_policy/base.rb
122
136
  - lib/ii_policy/callbacks.rb
123
- - lib/ii_policy/chain.rb
137
+ - lib/ii_policy/coactors.rb
124
138
  - lib/ii_policy/config.rb
125
139
  - lib/ii_policy/context.rb
126
140
  - lib/ii_policy/controller.rb
@@ -150,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
164
  - !ruby/object:Gem::Version
151
165
  version: '0'
152
166
  requirements: []
153
- rubygems_version: 3.1.2
167
+ rubygems_version: 3.0.3
154
168
  signing_key:
155
169
  specification_version: 4
156
170
  summary: A base policy to support management of authorization logic
@@ -1,38 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module IIPolicy
4
- module Chain
5
- extend ActiveSupport::Concern
6
-
7
- included do
8
- class_attribute :_chains
9
- self._chains = []
10
- end
11
-
12
- def call(action)
13
- lookup.each do |policy|
14
- return false unless policy.new(@context).call(action)
15
- end
16
- super
17
- end
18
-
19
- def lookup
20
- self.class._chains.map do |policy|
21
- if policy.is_a?(Symbol) && respond_to?(policy, true)
22
- send(policy)
23
- elsif policy.is_a?(Proc)
24
- instance_exec(&policy)
25
- else
26
- policy
27
- end
28
- end.flatten.compact
29
- end
30
-
31
- class_methods do
32
- def chain(*policies, &block)
33
- self._chains = _chains + policies
34
- self._chains << block if block
35
- end
36
- end
37
- end
38
- end