Sha256: 6950e08fd683f5468d6622b803b5992b90ade2c5603e75ba85a0d17854f127cc

Contents?: true

Size: 1.71 KB

Versions: 10

Compression:

Stored size: 1.71 KB

Contents

module Rundock
  module Builder
    class TargetBuilder < Base
      TargetNoSupportError = Class.new(NotImplementedError)
      TargetGroupNotFoundError = Class.new(StandardError)

      attr_accessor :parsed_node_options

      def build(target_name, target_info)
        # host type specified if target not found.
        if target_info.nil? ||
           !target_info.key?(target_name.to_sym) ||
           !target_info[target_name.to_sym].key?(:target_type) ||
           target_info[target_name.to_sym][:target_type] == 'host'

          backend_builder = BackendBuilder.new(@options, target_name, target_info)
          backend = backend_builder.build
          @parsed_node_options = { target_name.to_sym => backend_builder.parsed_options }

          return Node.new(target_name, backend)
        else
          raise TargetNoSupportError
        end
      end

      def build_group(target_group_name, target_info)
        if !target_info.nil? &&
           target_info.key?(target_group_name.to_sym) &&
           target_info[target_group_name.to_sym][:target_type] == 'group' &&
           target_info[target_group_name.to_sym].key?(:targets) &&
           target_info[target_group_name.to_sym][:targets].is_a?(Array)

          targets = target_info[target_group_name.to_sym][:targets]
          nodes = []
          @parsed_node_options = {}

          targets.each do |n|
            backend_builder = BackendBuilder.new(@options, n, target_info)
            backend = backend_builder.build

            @parsed_node_options[n.to_sym] = backend_builder.parsed_options
            nodes << Node.new(n, backend)
          end

          nodes
        else
          raise TargetGroupNotFoundError
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
rundock-1.0.5 lib/rundock/builder/target_builder.rb
rundock-1.0.4 lib/rundock/builder/target_builder.rb
rundock-1.0.2 lib/rundock/builder/target_builder.rb
rundock-1.0.1 lib/rundock/builder/target_builder.rb
rundock-1.0.0 lib/rundock/builder/target_builder.rb
rundock-0.5.8 lib/rundock/builder/target_builder.rb
rundock-0.5.7 lib/rundock/builder/target_builder.rb
rundock-0.5.4 lib/rundock/builder/target_builder.rb
rundock-0.5.3 lib/rundock/builder/target_builder.rb
rundock-0.5.2 lib/rundock/builder/target_builder.rb