Class: Symphonia::Permissions::Permission
- Defined in:
- lib/symphonia/permissions.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
(also: #id)
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #add(controller, actions = []) ⇒ Object
- #allow_action?(controller, action) ⇒ Boolean
- #allowed?(controller, action) ⇒ Boolean
- #controllers ⇒ Object
-
#initialize(name, options = {}) ⇒ Permission
constructor
actions => [:controller_name => [:action, :action, :action]].
- #remove_actions(controller, actions = []) ⇒ Object
- #remove_controller(controller) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name, options = {}) ⇒ Permission
actions => [:controller_name => [:action, :action, :action]]
50 51 52 53 |
# File 'lib/symphonia/permissions.rb', line 50 def initialize(name, ={}) @name = name @perms = Hash.new { |hash, key| hash[key] = Array.new } end |
Instance Attribute Details
#name ⇒ Object (readonly) Also known as: id
Returns the value of attribute name.
48 49 50 |
# File 'lib/symphonia/permissions.rb', line 48 def name @name end |
Instance Method Details
#add(controller, actions = []) ⇒ Object
64 65 66 |
# File 'lib/symphonia/permissions.rb', line 64 def add(controller, actions=[]) @perms[controller] += actions end |
#allow_action?(controller, action) ⇒ Boolean
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/symphonia/permissions.rb', line 80 def allow_action?(controller, action) controller = controller.to_sym action = action.to_sym if self.controllers.include?(controller) return @perms[controller].include?(action) else return false end end |
#allowed?(controller, action) ⇒ Boolean
60 61 62 |
# File 'lib/symphonia/permissions.rb', line 60 def allowed?(controller, action) Array(@perms[controller.to_sym]).include?(action.to_sym) end |
#controllers ⇒ Object
76 77 78 |
# File 'lib/symphonia/permissions.rb', line 76 def controllers @controllers ||= @perms.keys end |
#remove_actions(controller, actions = []) ⇒ Object
68 69 70 |
# File 'lib/symphonia/permissions.rb', line 68 def remove_actions(controller, actions=[]) @perms[controller] -= actions end |
#remove_controller(controller) ⇒ Object
72 73 74 |
# File 'lib/symphonia/permissions.rb', line 72 def remove_controller(controller) @perms.delete(controller) end |
#to_s ⇒ Object
56 57 58 |
# File 'lib/symphonia/permissions.rb', line 56 def to_s @name.to_s end |