Sha256: e007b14509cfb1c579b96ed7ed74a9195446b033e1243e4f0d2eebb2ceb2dd44

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

require "active_support/core_ext/hash"
require "active_support/core_ext/string"

module Wrapbox
  Configuration = Struct.new(
    :name,
    :runner,
    :cluster,
    :region,
    :container_definition,
    :additional_container_definitions,
    :task_role_arn,
    :use_sudo,
    :rm
  ) do
    def self.load_config(config)
      new(
        config["name"],
        config["runner"] ? config["runner"].to_sym : :docker,
        config["cluster"],
        config["region"],
        config["container_definition"].deep_symbolize_keys,
        config["additional_container_definitions"] || [],
        config["task_role_arn"],
        config["use_sudo"].nil? ? false : config["use_sudo"],
        config["rm"].nil? ? false : config["rm"]
      )
    end

    AVAILABLE_RUNNERS = %i(docker ecs)

    def initialize(*args)
      super
      raise "#{runner} is unsupported runner" unless AVAILABLE_RUNNERS.include?(runner)
      require "wrapbox/runner/#{runner}"
    end

    def build_runner
      Wrapbox::Runner.const_get(runner.to_s.camelcase).new(to_h)
    end

    def run(class_name, method_name, args, **options)
      build_runner.run(class_name, method_name, args, **options)
    end

    def run_cmd(*cmd, **options)
      build_runner.run_cmd(*cmd, **options)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wrapbox-0.1.0 lib/wrapbox/configuration.rb