Sha256: 7fcb08511648d045551234c4facc39313a64693a98098e385f01e5b5992480fe

Contents?: true

Size: 1.11 KB

Versions: 2

Compression:

Stored size: 1.11 KB

Contents

# encoding: utf-8

module Attestor

  module Policy

    # The base class for composite policies
    #
    # @api private
    class Node
      include Attestor::Policy
      include Enumerable

      # @!scope class
      # @!method new(*branches)
      # Creates the node with branches
      #
      # @param [<Attestor::Policy>, Array<Attestor::Policy>] branches
      #
      # @return [Policy::Base::Node]

      # @private
      def initialize(*branches)
        @branches = branches.flatten
        freeze
      end

      # @!attribute [r] branches
      # The branches of the node
      #
      # @return [Array<Policy::Base>]
      attr_reader :branches

      # Validates the policy as invalid
      #
      # To be reloaded by subclasses (And, Or, Xor, Not)
      #
      # @raise [Policy::InvalidError]
      #
      # @return [undefined]
      def validate
        invalid :base
      end

      # Iterates throught branches
      #
      # @return [Enumerator]
      def each
        block_given? ? branches.each { |item| yield(item) } : to_enum
      end

    end # class Node

  end # module Base

end # module Policy

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
attestor-1.0.0 lib/attestor/policy/node.rb
attestor-0.4.0 lib/attestor/policy/node.rb