Class: Shikashi::Privileges::AllowedMethods
- Inherits:
-
Object
- Object
- Shikashi::Privileges::AllowedMethods
- Defined in:
- lib/shikashi/privileges.rb
Overview
Used in Privileges to store information about specified method permissions
Instance Method Summary collapse
-
#allow(*method_names) ⇒ Object
Specifies that a method or list of methods are allowed Example.
-
#allow_all ⇒ Object
Specifies that any method is allowed.
-
#allowed?(method_name) ⇒ Boolean
return true if the method named method_name is allowed Example.
-
#initialize(privileges = nil) ⇒ AllowedMethods
constructor
A new instance of AllowedMethods.
Constructor Details
#initialize(privileges = nil) ⇒ AllowedMethods
Returns a new instance of AllowedMethods.
43 44 45 46 47 48 |
# File 'lib/shikashi/privileges.rb', line 43 def initialize(privileges = nil) @privileges = privileges @allowed_methods = Array.new @redirect_hash = Hash.new @all = false end |
Instance Method Details
#allow(*method_names) ⇒ Object
Specifies that a method or list of methods are allowed Example
allowed_methods = AllowedMethods.new allowed_methods.allow :foo allowed_methods.allow :foo, :bar allowed_methods.allow :foo, :bar, :test
78 79 80 81 82 83 84 |
# File 'lib/shikashi/privileges.rb', line 78 def allow(*method_names) method_names.each do |mn| @allowed_methods << mn end @privileges end |
#allow_all ⇒ Object
Specifies that any method is allowed
87 88 89 90 91 |
# File 'lib/shikashi/privileges.rb', line 87 def allow_all @all = true @privileges end |
#allowed?(method_name) ⇒ Boolean
return true if the method named method_name is allowed Example
allowed_methods = AllowedMethods.new allowed_methods.allowed? :foo # => false allowed_methods.allow :foo allowed_methods.allowed? :foo # => true allowed_methods.allow_all allowed_methods.allowed? :bar # => true
Privileges#instance_of, Privileges#methods_of and Privileges#object returns the corresponding instance of AllowedMethods
62 63 64 65 66 67 68 |
# File 'lib/shikashi/privileges.rb', line 62 def allowed?(method_name) if @all true else @allowed_methods.include?(method_name) end end |