class Slinky::ConfigReader

Constants

ANY_TYPE
ARRAY_TYPE
BOOL_TYPE
DEFAULT_SCRIPT_PRODUCT
DEFAULT_STYLE_PRODUCT
HASH_TYPE
NUMBER_TYPE
STRING_TYPE

Public Class Methods

empty() click to toggle source
# File lib/slinky/config_reader.rb, line 56
def self.empty
  new "{}"
end
from_file(path) click to toggle source
# File lib/slinky/config_reader.rb, line 52
def self.from_file path
  new File.open(path).read
end
new(string_or_hash) click to toggle source
# File lib/slinky/config_reader.rb, line 76
def initialize string_or_hash
  case string_or_hash
  when String
    @config = YAML::load(string_or_hash)
  when Hash
    @config = string_or_hash
  else
    raise TypeError.new("Config must be either a string or a hash")
  end
  ConfigReader.validate(@config)
end
validate(config) click to toggle source

Validates whether a supplied hash is well-formed according to the allowed entries

# File lib/slinky/config_reader.rb, line 62
def self.validate config
  entries = {}
  @entries.each{|e| entries[e.name] = e}
  errors = config.map{|k, v|
    if !entries[k]
      " * '#{k}' is not an allowed configuration key"
    end
  }.compact

  if !errors.empty?
    raise InvalidConfigError.new(errors.join("\n"))
  end
end

Public Instance Methods

[](x) click to toggle source
# File lib/slinky/config_reader.rb, line 97
def [](x)
  @config[x]
end
pushstate_for_path(path) click to toggle source
# File lib/slinky/config_reader.rb, line 88
def pushstate_for_path path
  if pushstate && pushstate.is_a?(Hash)
    p = pushstate.sort_by{|from, to| -from.count("/")}.find{|a|
      path.start_with? a[0]
    }
    p[1] if p
  end
end
to_s() click to toggle source
# File lib/slinky/config_reader.rb, line 101
def to_s
  @config.to_s
end