Skip to content

Commit

Permalink
@ lib/acu/helpers/helpers.rb: + ::acu_except
Browse files Browse the repository at this point in the history
  • Loading branch information
alphamarket committed Apr 16, 2017
1 parent c58888c commit 75585f9
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 6 deletions.
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ GIT
PATH
remote: .
specs:
rails-acu (2.1.0)
rails-acu (2.2.0)
rails (~> 5.0.0, >= 5.0.0)

GEM
Expand Down Expand Up @@ -63,8 +63,8 @@ GEM
warden (~> 1.2.3)
diff-lcs (1.3)
erubis (2.7.0)
globalid (0.3.7)
activesupport (>= 4.1.0)
globalid (0.4.0)
activesupport (>= 4.2.0)
i18n (0.8.1)
jquery-rails (4.3.1)
rails-dom-testing (>= 1, < 3)
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ The method `Acu::Monitor.gaurd` accepts a hashed list of agruments named `by`, p

### Some handy helpers
Although you can define a binary allow/deny access rule in the `acu_rules.rb` file but there will be some gray area that neither you can allow _full access_ to the resource nor _no access_.<br />
for those situations you allow the entities to get access but limits their operations in the action/view/layout with the `acu_is?` and `acu_as` helpers, here is some usage example of them:
For those situations you allow the entities to get access but limits their operations in the action/view/layout with the `acu_is?`, `acu_as` and `acu_except` helpers, here is some usage example of them:

```ruby
# return true if the entity `:admin`'s block in `whois :admin` return true, otherwise false
Expand All @@ -128,6 +128,11 @@ end
acu_as [:admin, :client] do
puts 'You are either `admin` or `client`'
end

# DO NOT executes the block if current user identified as either `:guest`
acu_except [:guest] do
puts 'Except `:guest`s anyone else can execute this code'
end
```

### Configurations
Expand Down
4 changes: 4 additions & 0 deletions lib/acu/helpers/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ def acu_is? symbol

def acu_as symbol
yield if acu_is? symbol
end

def acu_except symbol
yield if not acu_is? symbol
end
2 changes: 1 addition & 1 deletion lib/acu/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Acu
VERSION = '2.1.0'
VERSION = '2.2.0'
end
20 changes: 19 additions & 1 deletion spec/dummy/spec/controllers/home_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ def setup **kwargs
expect(acu_is? :everyone).to be true
expect(acu_is? :client).to be false
end
it "acu_do" do
it "acu_as" do
Acu::Rules.define do
whois :everyone { true }
whois :client { false }
Expand All @@ -544,6 +544,24 @@ def setup **kwargs
expect(acu_is? :everyone).to be true
end
end
it "acu_except" do
Acu::Rules.define do
whois :everyone { true }
whois :client { false }
end
acu_except :everyone do
# an invalid syntax, this should never run
expect(true).not_to be true
end
acu_except :client do
# a valid syntax
expect(true).to be true
end
# no-one gets through
acu_except [:client, :everyone] do
expect(true).not_to be true
end
end
end
context 'caching' do
it '[Rails.cache]' do
Expand Down

0 comments on commit 75585f9

Please sign in to comment.