Class: CookbookCreator::ConfigLoader
- Inherits:
-
Object
- Object
- CookbookCreator::ConfigLoader
- Defined in:
- lib/cookbook_creator/config_loader.rb
Instance Attribute Summary collapse
-
#explicit_config_file ⇒ Object
Path to a config file requested by user, (e.g., via command line option).
Instance Method Summary collapse
- #config_location ⇒ Object
-
#env ⇒ Object
(Private API, public for test purposes).
- #generator_config_dir ⇒ Object
-
#initialize(explicit_config_file, logger = nil) ⇒ ConfigLoader
constructor
A new instance of ConfigLoader.
- #load ⇒ Object
- #no_config_found? ⇒ Boolean
-
#path_exists?(path) ⇒ Boolean
(Private API, public for test purposes).
Constructor Details
#initialize(explicit_config_file, logger = nil) ⇒ ConfigLoader
Returns a new instance of ConfigLoader.
20 21 22 23 24 25 |
# File 'lib/cookbook_creator/config_loader.rb', line 20 def initialize(explicit_config_file, logger=nil) @explicit_config_file = explicit_config_file @generator_config_dir = nil @config_location = nil @logger = logger || NullLogger.new end |
Instance Attribute Details
#explicit_config_file ⇒ Object
Path to a config file requested by user, (e.g., via command line option). Can be nil
18 19 20 |
# File 'lib/cookbook_creator/config_loader.rb', line 18 def explicit_config_file @explicit_config_file end |
Instance Method Details
#config_location ⇒ Object
31 32 33 |
# File 'lib/cookbook_creator/config_loader.rb', line 31 def config_location @config_location ||= (explicit_config_file || locate_local_config) end |
#env ⇒ Object
(Private API, public for test purposes)
65 66 67 |
# File 'lib/cookbook_creator/config_loader.rb', line 65 def env ENV end |
#generator_config_dir ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/cookbook_creator/config_loader.rb', line 35 def generator_config_dir if @generator_config_dir.nil? @generator_config_dir = false full_path = working_directory.split(File::SEPARATOR) (full_path.length - 1).downto(0) do |i| candidate_directory = File.join(full_path[0..i] + [".generator"]) if File.exist?(candidate_directory) && File.directory?(candidate_directory) @generator_config_dir = candidate_directory break end end end @generator_config_dir end |
#load ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/cookbook_creator/config_loader.rb', line 50 def load # Ignore it if there's no explicit_config_file and can't find one at a # default path. return false if config_location.nil? if explicit_config_file && !path_exists?(config_location) raise "Specified config file #{config_location} does not exist" end # Have to set Config.config_file b/c other config is derived from it. Config.config_file = config_location read_config(IO.read(config_location), config_location) end |
#no_config_found? ⇒ Boolean
27 28 29 |
# File 'lib/cookbook_creator/config_loader.rb', line 27 def no_config_found? config_location.nil? end |
#path_exists?(path) ⇒ Boolean
(Private API, public for test purposes)
70 71 72 |
# File 'lib/cookbook_creator/config_loader.rb', line 70 def path_exists?(path) Pathname.new(path)..exist? end |