Module: Cannie::Permissions

Included in:
Permissions
Defined in:
lib/cannie/permissions.rb

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#userObject (readonly)

Returns the value of attribute user.



44
45
46
# File 'lib/cannie/permissions.rb', line 44

def user
  @user
end

Class Method Details

.included(base) ⇒ Object



3
4
5
# File 'lib/cannie/permissions.rb', line 3

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#can?(action, subject) ⇒ Boolean

Checks if at least one rule for specified action add subject is present

Parameters:

  • action (Symbol)
  • subject (String, Symbol)

Returns:

  • (Boolean)


55
56
57
# File 'lib/cannie/permissions.rb', line 55

def can?(action, subject)
  rules_for(action, subject).present?
end

#initialize(user) ⇒ Object



46
47
48
# File 'lib/cannie/permissions.rb', line 46

def initialize(user)
  @user = user
end

#permit!(action, subject) ⇒ Object

Raises error Cannie::ActionForbidden if there is no rules for specified action and subject

Parameters:

  • action (Symbol)
  • subject (String, Symbol)

Raises:



63
64
65
# File 'lib/cannie/permissions.rb', line 63

def permit!(action, subject)
  raise Cannie::ActionForbidden unless can?(action, subject)
end