class Strut::Config

Attributes

host[R]
max_attempts[R]
namespace[R]
output[R]
port[R]
runner[R]
swagger[R]

Public Class Methods

new(config_file) click to toggle source
# File lib/strut/config.rb, line 8
def initialize(config_file)
  path = File.dirname(config_file)
  read_and_store(config_file, path)
end

Public Instance Methods

extract_enum_value(yaml, name, enums) click to toggle source
# File lib/strut/config.rb, line 54
def extract_enum_value(yaml, name, enums)
  value = extract_value(yaml, name).to_sym
  throw "'#{name}' must be one of #{enums}." unless enums.include?(value)
  value
end
extract_int_value(yaml, name) click to toggle source
# File lib/strut/config.rb, line 48
def extract_int_value(yaml, name)
  value = extract_value(yaml, name).to_i
  throw "'#{name}' must be a number > 0." unless value > 0
  value
end
extract_optional_value(yaml, name) click to toggle source
# File lib/strut/config.rb, line 37
def extract_optional_value(yaml, name)
  extract_value(yaml, name, true)
end
extract_value(yaml, name, optional = false) click to toggle source
# File lib/strut/config.rb, line 41
def extract_value(yaml, name, optional = false)
  value = yaml[name]
  value = value["value"] unless value.nil?
  throw "No '#{name}' specified." if value.nil? and !optional
  value
end
read_and_store(config_file, path) click to toggle source
# File lib/strut/config.rb, line 13
def read_and_store(config_file, path)
  yaml = File.read(config_file)
  parsed_yaml = Psych::parse_yaml(yaml)
  store_values(parsed_yaml, path)
end
store_values(yaml, config_path) click to toggle source
# File lib/strut/config.rb, line 19
def store_values(yaml, config_path)
  @swagger = swagger_path(yaml, config_path)
  @runner = extract_optional_value(yaml, "runner")
  @host = extract_value(yaml, "host")
  @port = extract_int_value(yaml, "port")
  @max_attempts = extract_int_value(yaml, "max_attempts")
  @namespace = extract_value(yaml, "namespace")
  @output = extract_enum_value(yaml, "output", [:junit, :pretty])
end
swagger_path(yaml, config_path) click to toggle source
# File lib/strut/config.rb, line 29
def swagger_path(yaml, config_path)
  swagger_path = Pathname.new(extract_value(yaml, "swagger"))
  unless swagger_path.absolute?
    swagger_path = Pathname.new(config_path) + swagger_path
  end
  swagger_path.to_s
end