Exception: Grant::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/grant/error.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Error

Returns a new instance of Error.



5
6
7
8
9
10
11
# File 'lib/grant/error.rb', line 5

def initialize(*args)
  if args.size == 3
    @user, @action, @model = args
  else
    @message = args[0]
  end
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



3
4
5
# File 'lib/grant/error.rb', line 3

def action
  @action
end

#modelObject (readonly)

Returns the value of attribute model.



3
4
5
# File 'lib/grant/error.rb', line 3

def model
  @model
end

#userObject (readonly)

Returns the value of attribute user.



3
4
5
# File 'lib/grant/error.rb', line 3

def user
  @user
end

Instance Method Details

#to_sObject



13
14
15
16
17
18
19
20
# File 'lib/grant/error.rb', line 13

def to_s
  if @message
    @message
  else
    user_str = user == nil ? 'Anonymous' : "#{user.class.name}:#{user.id}"
    "#{action} permission not granted to #{user_str} for resource #{model.class.name}:#{model.id}"
  end
end