class Yarrow::Configuration
Public Class Methods
load(file)
click to toggle source
Loads a configuration object from the given YAML file.
@param [String] path to YAML file
@return [Yarrow::Config]
# File lib/yarrow/configuration.rb, line 19 def load(file) coerce_config_struct(YAML.load(File.read(file), symbolize_names: true)) end
load_defaults()
click to toggle source
Yarrow
is distributed with a ‘defaults.yml` which provides minimum boostrap configuration and default settings for various internal classes. Use this method to automatically load these defaults.
@return [Yarrow::Configuration]
# File lib/yarrow/configuration.rb, line 28 def load_defaults load(File.join(File.dirname(__FILE__), 'defaults.yml')) end
merge(config)
click to toggle source
Merges the given configuration or hash-like object with the registered global configuration.
@param [Hash, Hashie::Mash, Yarrow::Configuration
]
# File lib/yarrow/configuration.rb, line 9 def merge(config) instance.deep_merge!(config) end
Private Class Methods
coerce_config_struct(config)
click to toggle source
TODO: this should be folded into the schema machinery with type coercions
# File lib/yarrow/configuration.rb, line 35 def coerce_config_struct(config) meta_obj = if config.key?(:meta) Yarrow::Config::Meta.new( title: config[:meta][:title], author: config[:meta][:author] ) else nil end server_obj = if config.key?(:server) Yarrow::Config::Server.new(**config[:server]) else nil end content_obj = if config.key?(:content) Yarrow::Config::Content.new(config[:content]) else Yarrow::Config::Content.new({ module: "", source_map: { pages: :page } }) end output_obj = if config.key?(:output) Yarrow::Config::Output.new(config[:output]) else Yarrow::Config::Output.new({ generator: "web", template_dir: "templates" }) end # TODO: messy hack to get rid of Hashie::Mash, this should either be # automated as part of the schema types or a default value should be # generated here (eg: `"#{Dir.pwd}/docs"`) out_dir_or_string = config[:output_dir] || "" source_dir_or_string = config[:source_dir] || "" Yarrow::Config::Instance.new( output_dir: Pathname.new(File.expand_path(out_dir_or_string)), source_dir: Pathname.new(File.expand_path(source_dir_or_string)), meta: meta_obj, server: server_obj, content: content_obj, output: output_obj ) end