Class: Strongbolt::Unauthorized

Inherits:
StrongboltError
  • Object
show all
Defined in:
lib/strongbolt/errors.rb

Overview

Copy & Paste of Grant Error

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Unauthorized

Returns a new instance of Unauthorized.



10
11
12
13
14
15
16
# File 'lib/strongbolt/errors.rb', line 10

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.



8
9
10
# File 'lib/strongbolt/errors.rb', line 8

def action
  @action
end

#modelObject (readonly)

Returns the value of attribute model.



8
9
10
# File 'lib/strongbolt/errors.rb', line 8

def model
  @model
end

#userObject (readonly)

Returns the value of attribute user.



8
9
10
# File 'lib/strongbolt/errors.rb', line 8

def user
  @user
end

Instance Method Details

#to_sObject



18
19
20
21
22
23
24
25
26
# File 'lib/strongbolt/errors.rb', line 18

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