Sha256: ad99529370fef918a8519cd3ec19faeddb82e9e6c7ed958c53978417017c9245

Contents?: true

Size: 1.31 KB

Versions: 1

Compression:

Stored size: 1.31 KB

Contents

# encoding: utf-8

module Policy

  module Follower

    # An exception to be risen when a follower violates its policy
    class ViolationError < RuntimeError

      # @!scope class
      # @!method new(follower, policy)
      # Constructs an exception for the policy violated by the follower
      #
      # @param [Object] follower
      # @param [#errors] policy
      #
      # @return [Policy::ViolationError]
      def initialize(follower, policy)
        @follower = follower
        @policy = policy
      end

      # @!attribute [r] follower
      # The follower object that causes the exception
      #
      # @return [Object]
      attr_reader :follower

      # @!attribute [r] policy
      # The violated policy object
      #
      # @return [Policy::Base]
      attr_reader :policy

      # Returns the list of policy errors
      #
      # @return [ActiveModel::Errors]
      def errors
        policy.errors
      end

      # The human-readable exception message
      #
      # @return [String]
      def message
        "#{ follower.inspect } violates the policy #{ policy }"
      end

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

    end # class ViolationError

  end # module Follower

end # module Policy

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
policy-2.0.0 lib/policy/follower/violation_error.rb