# encoding: utf-8

module Policy

  module Follower

    # An exception to be risen when a policy name is not followed by a follower
    class NameError < RuntimeError

      # @!scope class
      # @!method new(follower, name)
      # Constructs an exception for the follower class and the policy name
      #
      # @param [Class] follower
      # @param [#to_sym] name
      #
      # @return [Policy::Follower::NameError]
      def initialize(follower, name)
        @follower = follower
        @name = name.to_sym
      end

      # @!attribute [r] follower
      # The follower class that doesn't follow given policy
      #
      # @return [Class]
      attr_reader :follower

      # @!attribute [r] name
      # The name of the policy that is not followed by the follower
      #
      # @return [String]
      attr_reader :name

      # The human-readable exception message
      #
      # @return [String]
      def message
        "#{ follower.inspect } hasn't registered the policy \"#{ name }\""
      end

      # The human-readable description for the exception
      #
      # @return [String]
      def inspect
        "#<#{ self }: #{ message }>"
      end

    end # class NameError

  end # module Follower

end # module Policy