Sha256: 4915689db346070e96bd66ee336ee01b45ead69bda888becaf74f2092308a94a

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 KB

Contents

module Orchestra
  class Recording
    # Reader object to expose operations and steps to the outside world
    class Node
      attr :input, :name

      extend Forwardable

      def_delegators :@node, :provisions, :dependencies, :optional_dependencies,
        :required_dependencies

      def initialize step_or_operation, name, input
        @name = name
        @node = step_or_operation
        @input = format_input input
        freeze
      end

      def to_h
        {
          dependencies: dependencies,
          input: input,
          name: name,
          optional_dependencies: optional_dependencies,
          provisions: provisions,
          required_dependencies: required_dependencies,
        }
      end

      def inspect
        params = to_h.each_with_object [] do |(key, val), list|
        list << "#{key}=#{val.inspect}"
        end
        "#<Orchestra::Node #{params.join ', '}>"
      end

      def operation?
        @node.is_a? Operation
      end

      def step?
        not operation?
      end

      private

      def format_input input
        @node.dependencies.each_with_object Hash.new do |dep, hsh|
          hsh[dep] = input[dep] if input.has_key? dep
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ntl-orchestra-0.9.5 lib/orchestra/recording/node.rb