class Devtools::Config

Abstract base class of tool configuration

Constants

DEFAULT_CONFIG

Represent no configuration

TypeError

Error raised on type errors

Private Class Methods

attribute(name, classes, **options) click to toggle source

Declare an attribute

@param [Symbol] name @param [Array<Class>] classes

@api private

@return [self]

# File lib/devtools/config.rb, line 54
def self.attribute(name, classes, **options)
  default    = [options.fetch(:default)] if options.key?(:default)
  type_check = TypeCheck.new(name, classes)
  key        = name.to_s

  define_method(name) do
    type_check.call(raw.fetch(key, *default))
  end
end

Public Instance Methods

config_file() click to toggle source

Return config path

@return [String]

@api private

# File lib/devtools/config.rb, line 71
def config_file
  config_dir.join(self.class::FILE)
end

Private Instance Methods

raw() click to toggle source

Return raw data

@return [Hash]

@api private

# File lib/devtools/config.rb, line 84
def raw
  yaml_config || DEFAULT_CONFIG
end
yaml_config() click to toggle source

Return the raw config data from a yaml file

@return [Hash]

returned if the yaml file is found

@return [nil]

returned if the yaml file is not found

@api private

# File lib/devtools/config.rb, line 98
def yaml_config
  IceNine.deep_freeze(YAML.load_file(config_file)) if config_file.file?
end