Class: Fib::Permission
- Inherits:
-
Object
- Object
- Fib::Permission
- Extended by:
- Forwardable
- Defined in:
- lib/fib/permission.rb
Instance Attribute Summary collapse
-
#bind ⇒ Object
readonly
Returns the value of attribute bind.
-
#container ⇒ Object
Returns the value of attribute container.
-
#display ⇒ Object
readonly
Returns the value of attribute display.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#package ⇒ Object
readonly
Returns the value of attribute package.
Instance Method Summary collapse
- #bind_packages ⇒ Object
- #bind_permission(*permission_keys) ⇒ Object
- #def_action(controller, action, &block) ⇒ Object
- #def_key(key, &block) ⇒ Object
- #def_url(url, &block) ⇒ Object
- #display_off ⇒ Object
- #display_on ⇒ Object
-
#initialize(key, options = {}) ⇒ Permission
constructor
A new instance of Permission.
- #inject_elements_permission ⇒ Object
Constructor Details
#initialize(key, options = {}) ⇒ Permission
Returns a new instance of Permission.
11 12 13 14 15 16 17 |
# File 'lib/fib/permission.rb', line 11 def initialize key, ={} @key = key.to_sym @name = [:name] || key.to_s @package = [:package] || Fib::ElementPackage.new @bind = [:bind] || [] @display = .key?(:display) ? [:display] : true end |
Instance Attribute Details
#bind ⇒ Object (readonly)
Returns the value of attribute bind.
6 7 8 |
# File 'lib/fib/permission.rb', line 6 def bind @bind end |
#container ⇒ Object
Returns the value of attribute container.
7 8 9 |
# File 'lib/fib/permission.rb', line 7 def container @container end |
#display ⇒ Object (readonly)
Returns the value of attribute display.
6 7 8 |
# File 'lib/fib/permission.rb', line 6 def display @display end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
6 7 8 |
# File 'lib/fib/permission.rb', line 6 def key @key end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/fib/permission.rb', line 6 def name @name end |
#package ⇒ Object (readonly)
Returns the value of attribute package.
6 7 8 |
# File 'lib/fib/permission.rb', line 6 def package @package end |
Instance Method Details
#bind_packages ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/fib/permission.rb', line 19 def bind_packages return [] unless bind.present? || container.present? packages = [] bind.each do |b| p = container..[b] next unless p.present? packages << p.package packages << p.bind_packages end packages.flatten end |
#bind_permission(*permission_keys) ⇒ Object
52 53 54 55 |
# File 'lib/fib/permission.rb', line 52 def * @bind << .flatten.map(&:to_sym) @bind.flatten!.uniq! end |
#def_action(controller, action, &block) ⇒ Object
32 33 34 |
# File 'lib/fib/permission.rb', line 32 def def_action controller, action, &block @package << Fib::Element.create_action(controller, action, &block) end |
#def_key(key, &block) ⇒ Object
40 41 42 |
# File 'lib/fib/permission.rb', line 40 def def_key key, &block @package << Fib::Element.create_key(key, &block) end |
#def_url(url, &block) ⇒ Object
36 37 38 |
# File 'lib/fib/permission.rb', line 36 def def_url url, &block @package << Fib::Element.create_url(url, &block) end |
#display_off ⇒ Object
48 49 50 |
# File 'lib/fib/permission.rb', line 48 def display_off @display = false end |
#display_on ⇒ Object
44 45 46 |
# File 'lib/fib/permission.rb', line 44 def display_on @display = true end |
#inject_elements_permission ⇒ Object
57 58 59 60 61 |
# File 'lib/fib/permission.rb', line 57 def package.origin_elements.values.flatten.each do |e| e. self end end |