Sha256: 37312af45888a91feae79167934061eb292c37992a5b6e5ccaf69f026cc2b1fa

Contents?: true

Size: 1.9 KB

Versions: 2

Compression:

Stored size: 1.9 KB

Contents

module FlexibleAccessibility
  class FlexibleAccessibilityException < StandardError
    attr_reader :action, :subject

    def initialize(action = nil, subject = nil)
      @action = action
      @subject = subject
    end

    def to_s
      message || default_message || @subject
    end

    def message
      @subject || nil
    end

    private
    def default_message
      'An exception is occurred'
    end
  end

	class AccessDeniedException < FlexibleAccessibilityException

    def message
      I18n.t('flexible_accessibility.errors.access_denied', :action => @action)
    end

    private
    def default_message
		  "The access for resource #{@action} is denied"
    end
	end

  class UserNotLoggedInException < FlexibleAccessibilityException

    def message
      I18n.t('flexible_accessibility.errors.user_is_not_logged_in')
    end

    private
    def default_message
      'Current user is not logged in'
    end
  end

  class NoWayToDetectLoggerUserException < FlexibleAccessibilityException

    def message
      I18n.t('flexible_accessibility.errors.no_way_to_detect_logged_user')
    end

    private
    def default_message
      'No way to detect a logged user - may you have forgot to define a current_user helper'
    end
  end
 
  class UnknownUserException < FlexibleAccessibilityException

    def message
      I18n.t('flexible_accessibility.errors.unknown_user')
    end

    private
    def default_message
      'Probably you have forgot to send a user in has_access?'
    end
  end

  class ActionsValueException < FlexibleAccessibilityException

    def message
      I18n.t('flexible_accessibility.errors.incorrect_value_of_actions')
    end

    private
    def default_message
      'The value of any \'authorize\' macro argument should be declared as Array'
    end
  end

  class IncorrectArgumentException < FlexibleAccessibilityException

    private
    def default_message
      nil
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
flexible_accessibility-0.3.4 lib/flexible_accessibility/exceptions.rb
flexible_accessibility-0.3.3 lib/flexible_accessibility/exceptions.rb