Class: Shikashi::Privileges::AllowedMethods

Inherits:
Object
  • Object
show all
Defined in:
lib/shikashi/privileges.rb

Overview

Used in Privileges to store information about specified method permissions

Instance Method Summary collapse

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_allObject

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

Returns:

  • (Boolean)


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