Class | Shikashi::Privileges::AllowedMethods |
In: |
lib/shikashi/privileges.rb
|
Parent: | Object |
Used in Privileges to store information about specified method permissions
# File lib/shikashi/privileges.rb, line 43 def initialize(privileges = nil) @privileges = privileges @allowed_methods = Array.new @redirect_hash = Hash.new @all = false end
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
# File lib/shikashi/privileges.rb, line 78 def allow(*method_names) method_names.each do |mn| @allowed_methods << mn end @privileges end
Specifies that any method is allowed
# File lib/shikashi/privileges.rb, line 87 def allow_all @all = true @privileges end
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
# File lib/shikashi/privileges.rb, line 62 def allowed?(method_name) if @all true else @allowed_methods.include?(method_name) end end