class Docks::Builder::Config

Attributes

options[R]

Public Class Methods

new(options) click to toggle source
# File lib/docks/build.rb, line 10
def initialize(options)
  @options = options
end

Public Instance Methods

default_config() click to toggle source
# File lib/docks/build.rb, line 14
def default_config; @default_config ||= Docks.config end
method_missing(meth) click to toggle source
Calls superclass method
# File lib/docks/build.rb, line 20
def method_missing(meth)
  if options.respond_to?(meth)
    present(options.send(meth), meth)
  elsif !(result = default_config.instance_variable_get("@#{meth}".to_sym)).nil?
    present(result, meth)
  else
    super
  end
end
respond_to?(meth) click to toggle source
Calls superclass method
# File lib/docks/build.rb, line 16
def respond_to?(meth)
  options.respond_to?(meth) || !default_config.instance_variable_get("@#{meth}".to_sym).nil? || super
end

Private Instance Methods

json?() click to toggle source
# File lib/docks/build.rb, line 40
def json?
  options.config_type == "json"
end
needs_quotes?(string) click to toggle source
# File lib/docks/build.rb, line 32
def needs_quotes?(string)
  !yaml? || /[:\{\}\[\],&\*#\?\|\-<>=!%@\\]/ =~ string
end
present(value, name = nil) click to toggle source
# File lib/docks/build.rb, line 52
def present(value, name = nil)
  if value.kind_of?(Class) || (name && [:naming_convention, :theme].include?(name) && !value.kind_of?(String))
    value = value.class.name.demodulize
  end

  value = case value
          when Hash
            value = "\n#{value.map { |k, v| "#{spaces}  #{json? ? present(k) : k}: #{present(v)}" }.join("#{"," unless yaml?}\n")}"
            yaml? ? value : "{#{value}\n#{spaces}}"
          when String
            needs_quotes?(value) ? "\"#{value}\"" : value
          when Array
            if value.empty?
              "[]"
            elsif yaml?
              "\n#{value.map { |v| "#{spaces}  - #{present(v)}" }.join("\n")}"
            else
              "[\n#{value.map { |v| "#{spaces}  #{present(v)}" }.join(",\n")}\n#{spaces}]"
            end
          when Symbol
            ruby? ? ":#{value}" : present(value.to_s)
          else
            value
          end

  value
end
ruby?() click to toggle source
# File lib/docks/build.rb, line 44
def ruby?
  options.config_type == "ruby"
end
spaces() click to toggle source
# File lib/docks/build.rb, line 48
def spaces
  yaml? ? "" : "  "
end
yaml?() click to toggle source
# File lib/docks/build.rb, line 36
def yaml?
  options.config_type == "yaml"
end