Class: Exits::Rules

Inherits:
Object
  • Object
show all
Defined in:
lib/exits/rules.rb,
lib/exits/rules/user.rb,
lib/exits/rules/controller.rb

Defined Under Namespace

Classes: ConfusingRulesError, Controller, Unauthorized, User

Instance Method Summary collapse

Constructor Details

#initializeRules

Returns a new instance of Rules.



8
9
10
# File 'lib/exits/rules.rb', line 8

def initialize
  @controllers = Hash.new
end

Instance Method Details

#add(controller_class, klass, *actions) ⇒ Object



12
13
14
15
# File 'lib/exits/rules.rb', line 12

def add(controller_class, klass, *actions)
  @controllers[controller_class] ||= Exits::Rules::Controller.new
  @controllers[controller_class][klass] = actions.flatten
end

#authorized?(controller_class, klass, action) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
# File 'lib/exits/rules.rb', line 17

def authorized?(controller_class, klass, action)
  return true if klass.eql?(NilClass)
  controller = @controllers.fetch(controller_class, {})
  return false if controller.nil?
  controller.authorized? klass, action
end