rails-acu 4.0.2 → 4.1.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: 488e37dbff4014ce568d5483945250b297566ed6d476f9960baad19550fa6007
4
- data.tar.gz: fe8e0459c7f6c299414e38f6a4c15f9a16e61d4a42635e6aef1ef18bd814bbb4
3
+ metadata.gz: aa060e6c65c50e57346ca8ebfa92ba09f54bc758049ae2555e20376079b4ab02
4
+ data.tar.gz: 97de2a8dc8d18ea01dfecd20ede4384f8c5b329c03dceee9a2d70f5f34ebca44
5
5
  SHA512:
6
- metadata.gz: 3dbae57aa24057b748775922ce69847d870f2b85cf4582b61c9ea28092e16a84108a3918c40cede0fa41237486710065878a859c25519e96c108a34f383cb005
7
- data.tar.gz: e087cd36811128dc9f6a6b0730c49313ea450930abdc7327f861f21b733d1f5e3adf8727427a09256de5b4af1335ed53ebb65a283b182b98f761ee9e69a549a6
6
+ metadata.gz: 3d5d20fb6f6abcdcec9298fab2fb3d5b609bb3a242123aaf8321a4a136f511a44dde2bca5e68d8eb8475734f7220151057b27e144f8d781915e43f4995a43fa5
7
+ data.tar.gz: 31dfb7aa93101eb1253b2f845793293b968d43f4a5a3b83eadf8739dff002879cdf1edcdd73ec437c427360b93a252b48d94381e858a745efcd5b29920b28338
@@ -21,7 +21,7 @@ GIT
21
21
  PATH
22
22
  remote: .
23
23
  specs:
24
- rails-acu (4.0.1)
24
+ rails-acu (4.1.0)
25
25
  rails (~> 6.0, >= 6.0.0)
26
26
 
27
27
  GEM
data/README.md CHANGED
@@ -92,7 +92,7 @@ Acu::Rules.define do
92
92
  end
93
93
 
94
94
  # nested namespace (since v3.0.0)
95
- namespace :admin do
95
+ namespace :admin do
96
96
  namespace :chat do
97
97
  allow :client
98
98
  end
@@ -148,7 +148,25 @@ acu_as [:admin, :client] do
148
148
  end
149
149
 
150
150
  # DO NOT execute the block if current user identified as `:guest`
151
- acu_except [:guest] do
151
+ acu_except [:guest] do
152
+ puts 'Except `:guest`s anyone else can execute this code'
153
+ end
154
+
155
+ # [since version v4.1.0]
156
+ # alias checking:
157
+ # passing dynamic params to check if the passed params identify as an entity or not!
158
+ # NOTE: the passed arguments should match the entity definition arguments
159
+
160
+ # checks if the given user is an `admin` entity or not?
161
+ acu_is? :admin, user: User.find_by_username('username')
162
+ # checks if the given user is an `admin` OR a `client` entity or not?
163
+ acu_is? [:admin, :client], user: User.find_by_username('username')
164
+ # execute the block if the passed user is an `admin`
165
+ acu_as :admin, user: User.find_by_username('username') do
166
+ puts 'The `username` is an `admin`'
167
+ end
168
+ # DO NOT execute the block if passed user identified as `:guest`
169
+ acu_except [:guest], user: User.find_by_username('username') do
152
170
  puts 'Except `:guest`s anyone else can execute this code'
153
171
  end
154
172
  ```
@@ -237,7 +255,7 @@ class Acu::Errors::MissingController < MissingData
237
255
  class Acu::Errors::MissingNamespace < MissingData
238
256
  ```
239
257
 
240
- ## Known contributions subjects to work on
258
+ ## Known contributions subjects to work on
241
259
 
242
260
  ### Implementing to overriding the rules in inner loops:
243
261
  Consider we have to give the everyone to access the default namespace except `:profile` controller which will only allow by signed in users, although there are tools provided
@@ -279,4 +297,4 @@ In order contributing to this project:
279
297
  4. Make a pull request to the `develop` branch
280
298
 
281
299
  ## License
282
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
300
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -1,19 +1,19 @@
1
- def acu_is? *symbol
1
+ def acu_is? *symbol, **args
2
2
  flag = false
3
- [symbol].flatten.each do |s|
3
+ [symbol].flatten.each do |s|
4
4
  if s.to_s =~ /\Anot_/
5
- flag |= not(Acu::Monitor.valid_for?(s.to_s.gsub(/\Anot_/, "").to_sym))
5
+ flag |= not(Acu::Monitor.valid_for?(s.to_s.gsub(/\Anot_/, "").to_sym, args))
6
6
  else
7
- flag |= Acu::Monitor.valid_for? s
7
+ flag |= Acu::Monitor.valid_for? s, args
8
8
  end
9
9
  end
10
10
  flag
11
11
  end
12
12
 
13
- def acu_as *symbol
14
- yield if acu_is? symbol
13
+ def acu_as *symbol, **args
14
+ yield if acu_is? symbol, args
15
15
  end
16
16
 
17
- def acu_except *symbol
18
- yield if not acu_is? symbol
19
- end
17
+ def acu_except *symbol, **args
18
+ yield if not acu_is? symbol, args
19
+ end
@@ -39,7 +39,7 @@ module Acu
39
39
  t = -1
40
40
  # either mentioned explicitly
41
41
  if cond[current] and not cond[current].empty?
42
- # hierarchical match `_info[current]` with `cond[current]` to support nested namespace (since v3.0.0)
42
+ # hierarchical match `_info[current]` with `cond[current]` to support nested namespace (since v3.0.0)
43
43
  cond[current].map { |c| c[:name].to_s }.each.with_index do |c, index|
44
44
  t = (c == eval("_info.#{current}")[index].to_s) ? 1 : 0
45
45
  break if t == 0
@@ -54,7 +54,7 @@ module Acu
54
54
  tag_list = cond[parent].map { |c| c[tag] }.flatten - [nil]
55
55
  # if any tag is present?
56
56
  if not tag_list.empty? and tag_list.any?
57
- # if `current` is mentioned in `tag_list`?
57
+ # if `current` is mentioned in `tag_list`?
58
58
  case not (tag_list.map(&:to_s) & eval("_info.#{current}").map(&:to_s)).empty?
59
59
  when true
60
60
  t = val[:on_true]
@@ -96,7 +96,7 @@ module Acu
96
96
  end
97
97
  end
98
98
  end
99
-
99
+
100
100
  # if the access is granted? i.e if all the rules are satisfied with the request
101
101
  return if _granted == 1 and access_granted _info, _entitled_entities
102
102
  # if the access is denied? i.e at least one of rules are NOT satisfied with the request
@@ -106,13 +106,17 @@ module Acu
106
106
  access_granted _info, [:__ACU_BY_DEFAULT__], by_default: true
107
107
  end
108
108
 
109
- def valid_for? entity
109
+ def valid_for? entity, **args
110
110
  # check for existance
111
111
  raise Errors::MissingEntity.new("whois(:#{entity})?") if not Rules.entities[entity]
112
112
  # fetch the entity's identity
113
113
  e = Rules.entities[entity]
114
+ # set default argument set
115
+ wargs = @kwargs
116
+ # set externals if any argument is provided from outside?
117
+ wargs = args unless args.blank?
114
118
  # fetch the related args to the entity from the `kwargs`
115
- kwargs = @kwargs.reject { |x| !e[:args].include?(x) }
119
+ kwargs = wargs.reject { |x| !e[:args].include?(x) }
116
120
  # if fetched args and pre-defined arg didn't match?
117
121
  raise Errors::MissingData.new("at least one of arguments for `whois(:#{entity})` is not provided!") if kwargs.length != e[:args].length
118
122
  # send varibles in order the have defined
@@ -223,4 +227,4 @@ module Acu
223
227
  end # /class << self
224
228
  end # /class Monitor
225
229
 
226
- end # /module Acu
230
+ end # /module Acu
@@ -1,3 +1,3 @@
1
1
  module Acu
2
- VERSION = '4.0.2'
2
+ VERSION = '4.1.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-acu
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.2
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dariush Hasanpour