Sha256: b6f7094d3248657973108a6259fa845a302cf1cd84c617af64ef715374528daa

Contents?: true

Size: 1.13 KB

Versions: 11

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

module Remocon
  module Command
    class Create
      include Remocon::InterpreterHelper

      attr_reader :config, :cmd_opts

      def initialize(opts)
        @config = Remocon::Config.new(opts)
        @cmd_opts = { validate_only: false }
      end

      def require_parameters_file_path
        config.parameters_file_path
      end

      def require_conditions_file_path
        config.conditions_file_path
      end

      def run
        validate_options

        artifact = {
          conditions: condition_array,
          parameters: parameter_hash
        }.skip_nil_values.stringify_values

        File.open(config.config_json_file_path, "w+") do |f|
          # remote config allows only string values ;(
          f.write(JSON.pretty_generate(artifact))
          f.flush
        end

        artifact
      end

      private

      def validate_options
        raise ValidationError, "A condition file must exist" unless File.exist?(config.conditions_file_path)
        raise ValidationError, "A parameter file must exist" unless File.exist?(config.parameters_file_path)
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
remocon-0.5.1 lib/remocon/command/create_command.rb
remocon-0.5.0 lib/remocon/command/create_command.rb
remocon-0.4.4 lib/remocon/command/create_command.rb
remocon-0.4.3 lib/remocon/command/create_command.rb
remocon-0.4.2 lib/remocon/command/create_command.rb
remocon-0.4.1 lib/remocon/command/create_command.rb
remocon-0.4.0 lib/remocon/command/create_command.rb
remocon-0.4.0.pre.1 lib/remocon/command/create_command.rb
remocon-0.3.1 lib/remocon/command/create_command.rb
remocon-0.3.0 lib/remocon/command/create_command.rb
remocon-0.2.0 lib/remocon/command/create_command.rb