Class: Exits::Rules::User

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

Instance Method Summary collapse

Constructor Details

#initializeUser

Returns a new instance of User.



5
6
7
# File 'lib/exits/rules/user.rb', line 5

def initialize
  @actions = []
end

Instance Method Details

#allow(*actions) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/exits/rules/user.rb', line 9

def allow(*actions)
  @actions = @actions | actions.flatten

  if @actions.size > 1 && @actions.include?(:all)
    raise Exits::Rules::ConfusingRulesError, "You have :all and specific actions within the same controller/user rule."
  end
end

#authorized?(action) ⇒ Boolean

Returns:

  • (Boolean)


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

def authorized?(action)
  return true if @actions.include?(:all)
  return @actions.include?(action)
end