Class: Acu::Rules
Class Attribute Summary collapse
-
.DENY_SYMBOL ⇒ Object
readonly
Returns the value of attribute DENY_SYMBOL.
-
.entities ⇒ Object
readonly
Returns the value of attribute entities.
-
.GRANT_SYMBOL ⇒ Object
readonly
Returns the value of attribute GRANT_SYMBOL.
-
.rules ⇒ Object
readonly
Returns the value of attribute rules.
Class Method Summary collapse
- .action(*names) ⇒ Object
-
.allow(*symbol, on: []) ⇒ Object
the ops ###################### at this point we assign the class varible rules #.
-
.controller(*names, except: nil, only: nil) ⇒ Object
only: only the defined
actionsin thecontrollerexcept: except the definedactionsin thecontroller. - .define(&block) ⇒ Object
- .deny(*symbol, on: []) ⇒ Object
- .initialize ⇒ Object
-
.lock ⇒ Object
locks the rules to be read-only.
-
.namespace(*names, except: nil, only: nil) ⇒ Object
only: only the defined
controllersin thenamespaceexcept: except the definedcontrollersin thenamespace. - .override(*symbol, with:, on: []) ⇒ Object
- .reset ⇒ Object
- .whois(symbol, args: nil, &block) ⇒ Object
Class Attribute Details
.DENY_SYMBOL ⇒ Object (readonly)
Returns the value of attribute DENY_SYMBOL.
18 19 20 |
# File 'lib/acu/rules.rb', line 18 def DENY_SYMBOL @DENY_SYMBOL end |
.entities ⇒ Object (readonly)
Returns the value of attribute entities.
16 17 18 |
# File 'lib/acu/rules.rb', line 16 def entities @entities end |
.GRANT_SYMBOL ⇒ Object (readonly)
Returns the value of attribute GRANT_SYMBOL.
17 18 19 |
# File 'lib/acu/rules.rb', line 17 def GRANT_SYMBOL @GRANT_SYMBOL end |
.rules ⇒ Object (readonly)
Returns the value of attribute rules.
15 16 17 |
# File 'lib/acu/rules.rb', line 15 def rules @rules end |
Class Method Details
.action(*names) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/acu/rules.rb', line 63 def action *names names = [names].flatten if name raise Errors::InvalidSyntax.new("nested actions are not allowed!") if @_params[:action] and not @_params[:action].empty? raise Errors::AmbiguousRule.new("at least one of the parent `controller` or `namespace` needs to be defined for the this action") if not (@_params[:namespace] || @_params[:controller]) raise Errors::AmbiguousRule.new("there is already an `except` or `only` constraints defined in container controller(s) `#{@_params[:controller].map { |i| i[:name] }.join('::')}`") if @_params[:controller] and @_params[:controller].find { |n| n[:except] or n[:only] } names.each do |name| pass action: { name: name.downcase } do yield end end end |
.allow(*symbol, on: []) ⇒ Object
the ops ###################### at this point we assign the class varible rules #
96 97 98 |
# File 'lib/acu/rules.rb', line 96 def allow *symbol, on: [] op *symbol, @GRANT_SYMBOL, on end |
.controller(*names, except: nil, only: nil) ⇒ Object
only: only the defined actions in the controller
except: except the defined actions in the controller
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/acu/rules.rb', line 49 def controller *names, except: nil, only: nil names = [names].flatten if name only = nil if only and not (only.kind_of?(Array) or only.length == 0) except = nil if except and not (except.kind_of?(Array) or except.length == 0) raise Errors::InvalidSyntax.new("nested controllers are not allowed!") if @_params[:controller] and not @_params[:controller].empty? raise Errors::AmbiguousRule.new("there is already an `except` or `only` constraints defined in container namespace `#{@_params[:namespace].map { |i| i[:name] }.join('::')}`") if @_params[:namespace] and @_params[:namespace].find { |n| n[:except] or n[:only] } raise Errors::AmbiguousRule.new('cannot have both `only` and `except` options at the same time for controller(s) `%s`' %names.join(', ')) if only and except names.each do |name| pass controller: { name: name.downcase, except: except, only: only } do yield end end end |
.define(&block) ⇒ Object
75 76 77 78 |
# File 'lib/acu/rules.rb', line 75 def define(&block) helper_initialize self.instance_eval(&block) end |
.deny(*symbol, on: []) ⇒ Object
100 101 102 |
# File 'lib/acu/rules.rb', line 100 def deny *symbol, on: [] op *symbol, @DENY_SYMBOL, on end |
.initialize ⇒ Object
22 23 24 |
# File 'lib/acu/rules.rb', line 22 def initialize reset end |
.lock ⇒ Object
locks the rules to be read-only
81 82 83 |
# File 'lib/acu/rules.rb', line 81 def lock self.freeze end |
.namespace(*names, except: nil, only: nil) ⇒ Object
only: only the defined controllers in the namespace
except: except the defined controllers in the namespace
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/acu/rules.rb', line 34 def namespace *names, except: nil, only: nil names = [nil] if names.empty? only = nil if only and not (only.kind_of?(Array) or only.length == 0) except = nil if except and not (except.kind_of?(Array) or except.length == 0) raise Errors::AmbiguousRule.new("there is already an `except` or `only` constraints defined in container namespace `#{@_params[:namespace].map { |i| i[:name] }.join('::')}`") if (except or only) and @_params[:namespace] and @_params[:namespace].find { |n| n[:except] or n[:only] } raise Errors::AmbiguousRule.new('cannot have both `only` and `except` options at the same time for namespace(s) `%s`' %names.join(', ')) if only and except names.each do |name| pass namespace: { name: name ? name.downcase : name, except: except, only: only } do yield end end end |
.override(*symbol, with:, on: []) ⇒ Object
104 105 106 |
# File 'lib/acu/rules.rb', line 104 def override *symbol, with:, on: [] raise Exception.new('not implemented!'); end |
.reset ⇒ Object
26 27 28 29 30 |
# File 'lib/acu/rules.rb', line 26 def reset @rules = { } @_params = { } @entities = { } end |
.whois(symbol, args: nil, &block) ⇒ Object
85 86 87 88 89 90 |
# File 'lib/acu/rules.rb', line 85 def whois(symbol, args: nil, &block) @entities[symbol] = { args: [args || []].flatten, callback: block } end |