Class: Authoritah::Controller::PermissionSet

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

Instance Method Summary collapse

Instance Method Details

#<<(permission_hash) ⇒ Object



82
83
84
85
# File 'lib/authoritah.rb', line 82

def <<(permission_hash)
  permission_hash[:actions] = [:all] unless permission_hash[:actions]
  permissions << permission_hash
end

#firstObject



91
92
93
# File 'lib/authoritah.rb', line 91

def first
  permissions.first
end

#permissionsObject



109
110
111
# File 'lib/authoritah.rb', line 109

def permissions
  @permissions ||= []
end

#permits?(controller, action) ⇒ Boolean

Returns:

  • (Boolean)


95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/authoritah.rb', line 95

def permits?(controller, action)
  permitted, on_reject_action = apply_rule_chain(:permit, controller, action)
  if permitted
    return true
  else
    if on_reject_action.is_a?(Proc)
      controller.instance_eval(&on_reject_action)
    else
      controller.send(on_reject_action)
    end
    return false
  end
end

#sizeObject



87
88
89
# File 'lib/authoritah.rb', line 87

def size
  permissions.size
end