class Foundry::Configurator

Constants

DEFAULT_OPTS

Attributes

opts[R]

Public Class Methods

configure(opts) click to toggle source
# File lib/foundry/configurator.rb, line 6
def self.configure(opts)
  new.configure(opts)
end

Public Instance Methods

configure(opts) click to toggle source
# File lib/foundry/configurator.rb, line 10
def configure(opts)
  with_opts(opts) do
    relative_path = opts.fetch(:relative_path)
    transmorg = transmorgify(relative_path)
    merged = mergify(transmorg)
    structify(merged)
  end
end

Private Instance Methods

loadify(relative_path) click to toggle source
# File lib/foundry/configurator.rb, line 29
def loadify(relative_path)
  source.load(
    root_path,
    relative_path,
    opts
  )
end
mergify(transmorgs) click to toggle source
# File lib/foundry/configurator.rb, line 37
def mergify(transmorgs)
  transmorgs.reduce({}) { |memo, transmorg| memo.deep_merge(transmorg) }
end
opts_value_or_default(key) click to toggle source
# File lib/foundry/configurator.rb, line 41
def opts_value_or_default(key)
  opts.fetch(key, DEFAULT_OPTS.fetch(key))
end
parser() click to toggle source
# File lib/foundry/configurator.rb, line 45
def parser
  parser_type.new
end
parser_type() click to toggle source
# File lib/foundry/configurator.rb, line 49
def parser_type
  opts_value_or_default(:parser_type)
end
parsify(str) click to toggle source
# File lib/foundry/configurator.rb, line 53
def parsify(str)
  parser.parse(str) || {}
end
root_path() click to toggle source
# File lib/foundry/configurator.rb, line 57
def root_path
  opts.fetch(:root_path)
end
source() click to toggle source
# File lib/foundry/configurator.rb, line 61
def source
  source_type.new
end
source_type() click to toggle source
# File lib/foundry/configurator.rb, line 65
def source_type
  opts_value_or_default(:source_type)
end
structify(value) click to toggle source
# File lib/foundry/configurator.rb, line 69
def structify(value)
  case value
  when Array
    value.map { |item| structify(item) }
  when Hash
    OpenStruct.new.tap do |struct|
      value.each { |item| struct.send("#{item[0]}=", structify(item[1])) }
    end
  else
    value
  end
end
template_engine() click to toggle source
# File lib/foundry/configurator.rb, line 82
def template_engine
  template_engine_type.new
end
template_engine_type() click to toggle source
# File lib/foundry/configurator.rb, line 86
def template_engine_type
  opts_value_or_default(:template_engine_type)
end
templatify(str) click to toggle source
# File lib/foundry/configurator.rb, line 90
def templatify(str)
  template_engine.evaluate(str)
end
transmorgify(relative_path) click to toggle source
# File lib/foundry/configurator.rb, line 94
def transmorgify(relative_path)
  parsed = parsify(templatify(loadify(relative_path)))
  next_relative_path = parsed.delete('inherit')
  Array(next_relative_path && transmorgify(next_relative_path)) << parsed
end
with_opts(opts) { || ... } click to toggle source
# File lib/foundry/configurator.rb, line 100
def with_opts(opts)
  @opts = opts
  yield
ensure
  @opts = nil
end