lib/planter/config.rb in planter-cli-3.0.5 vs lib/planter/config.rb in planter-cli-3.0.7

- old
+ new

@@ -1,18 +1,17 @@ # frozen_string_literal: true module Planter + ## Configuration class class Config < Hash attr_reader :template ## ## Initialize a new Config object for a template ## - ## @param template [String] template name - ## def initialize - # super() + super() @config = initial_config @template = Planter.template load_template @@ -20,30 +19,21 @@ die('No configuration found', :config) unless @config generate_accessors end - def initial_config - { - defaults: false, - git_init: false, - files: { '_planter.yml' => 'ignore' }, - color: true, - preserve_tags: nil, - variables: nil, - replacements: nil, - repo: false, - patterns: nil, - debug: false, - script: nil - } - end - + ## String representation of the configuration def to_s @config.to_s end + ## Get a config key + ## + ## @param key [String,Symbol] key + ## + ## @return [String] value + ## def [](key) @config[key] end ## @@ -57,20 +47,43 @@ generate_accessors end private + ## Default configuration + ## + ## @return [Hash] default configuration + ## + ## @api private + ## + def initial_config + { + defaults: false, + git_init: false, + files: { '_planter.yml' => 'ignore' }, + color: true, + preserve_tags: nil, + variables: nil, + replacements: nil, + repo: false, + patterns: nil, + debug: false, + script: nil + } + end + ## Generate accessors for configuration + ## + ## @api private + ## def generate_accessors @config.each do |k, v| define_singleton_method(k) { v } unless respond_to?(k) end end ## ## Build a configuration from template name - ## - ## @param template [String] The template name ## ## @return [Hash] Configuration object ## ## @api private ##