Sha256: 64feaf47b5c5e2b33fde9438a46be5bd5cb64cc64ea5b9987b3569a9296418f2

Contents?: true

Size: 1.46 KB

Versions: 2

Compression:

Stored size: 1.46 KB

Contents

module Convoy
    module Setup
        module Configuration
            class Loader
                attr_reader :setup, :auto_options

                def initialize(setup, auto_options)
                    @setup        = setup
                    @auto_options = auto_options
                end

                def configuration
                    if setup.has_config_file?
                        Writer.new(config_path, Generator.new(setup).default_data).write if setup.config_file_autocreatable?
                        Reader.new(config_path).read
                    else
                        Instance.blank
                    end
                end

                def default_config_path
                    @default_config_path ||= (config_filename ? File.join(File.expand_path(ENV["HOME"]), config_filename) : nil)
                end

                private

                def config_filename
                    @config_filename ||= setup.config_file
                end

                def config_path
                    @config_path ||= (auto_options.non_default_config_path || locator.locate || default_config_path)
                end

                def locator
                    Locator::Chaining.new(config_filename).
                        add_locator(Locator::ExecutingScriptDirectory.new(config_filename)).
                        add_locator(Locator::DescendingToHome.new(config_filename))
                end
            end
        end
    end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
convoy-1.3.2 lib/convoy/setup/configuration/loader.rb
convoy-1.2.0 lib/convoy/setup/configuration/loader.rb