Sha256: 4e4abe11105a7049ae02e6731122b6c26e071efc68ec60ca3eb040f7b034eef3

Contents?: true

Size: 1.24 KB

Versions: 1

Compression:

Stored size: 1.24 KB

Contents

# encoding: utf-8

module Policy

  module Base

    # Composes a policy with an argument of its {#not} method
    #
    # @api private
    class Negator

      # @!scope class
      # @!method new(policy, composer)
      # Creates the negator object, expecting {#not} method call
      #
      # @param [Policy::Base] policy
      #   the policy to be composed with negations of other policies
      # @param [Class] composer
      #   the composer for policies
      #
      # @return [Policy::Base::Negator]
      def initialize(policy, composer)
        @policy   = policy
        @composer = composer
      end

      # Returns a composition of the {#policy} with negations of other policies
      #
      # @param [Policy::Base, Array<Policy::Base>] policies
      #
      # @return [Policy::Base]
      def not(*policies)
        composer.new policy, *policies.flat_map(&Not.method(:new))
      end

      # @!attribute [r] policy
      # The the policy to be composed with negations of other policies
      #
      # @return [Policy::Base]
      attr_reader :policy

      # @!attribute [r] composer
      # The the composer for policies
      #
      # @return [Class]
      attr_reader :composer

    end # class Negator

  end # module Base

end # module Policy

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
policy-2.0.0 lib/policy/base/negator.rb