Sha256: 4ffdaadb86452668920755a610833845a32fb1f4c1522c9f2feb9f249bf50fb3

Contents?: true

Size: 800 Bytes

Versions: 3

Compression:

Stored size: 800 Bytes

Contents

# frozen_string_literal: true

module Aserto
  class Error < StandardError; end

  class AccessDenied < Error
    attr_reader :action, :conditions
    attr_writer :default_message

    def initialize(message = nil, action = nil, conditions = nil)
      @message = message
      @action = action
      @conditions = conditions
      @default_message = I18n.t(:"unauthorized.default", default: "You are not authorized to access this page.")
      super()
    end

    def to_s
      @message || @default_message
    end

    def inspect
      details = %i[action conditions message].filter_map do |attribute|
        value = instance_variable_get "@#{attribute}"
        "#{attribute}: #{value.inspect}" if value.present?
      end.join(", ")
      "#<#{self.class.name} #{details}>"
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
aserto-0.0.4 lib/aserto/errors.rb
aserto-0.0.3 lib/aserto/errors.rb
aserto-0.0.2 lib/aserto/errors.rb