class BubBot::Configuration

TODO: merge with some defaults

Constants

BUB_BOT_OPTIONS

These options will be handled by us.

OPTIONS
RACK_OPTIONS

Any of these options will be passed on to rack, rather than handled by us.

Public Instance Methods

rack_options_hash() click to toggle source
# File lib/bub_bot/configuration.rb, line 23
def rack_options_hash
  RACK_OPTIONS.each_with_object({}) do |option_name, options_hash|
    options_hash[option_name] = public_send(option_name)
  end
end
verify_options() click to toggle source
# File lib/bub_bot/configuration.rb, line 29
def verify_options
  # TODO: verify that deploy_targets, etc, are formatted correctly and print
  # useful error messages otherwise.
  true
end

Private Instance Methods

get_binding(variables) click to toggle source

Gets a binding object with the given variables defined in it. You'd think there'd be a simpler way. Well, ok, there is, but there's no simpler way that doesn't also polute the binding with variables from the outer scope.

# File lib/bub_bot/configuration.rb, line 66
def get_binding(variables)
  obj = Class.new {
    attr_accessor *variables.keys
    def get_binding(); binding end
  }.new
  variables.each { |name, value| obj.public_send(:"#{name}=", value) }
  obj.get_binding
end
interpolate(data, extra_context) click to toggle source
# File lib/bub_bot/configuration.rb, line 49
def interpolate(data, extra_context)
  if data.is_a?(String)
    ERB.new(data).result(get_binding(extra_context))
  elsif data.is_a?(Array)
    data.map { |element| interpolate(element, extra_context) }
  elsif data.is_a?(Hash)
    data.each_with_object({}) do |(key, value), new_hash|
      new_hash[key] = interpolate(value, extra_context)
    end
  else
    data
  end
end