Sha256: 72a7be46e1f10e7cc66dcafa4900520ba0ac42b17bce747ff6a972d31dc93051

Contents?: true

Size: 706 Bytes

Versions: 108

Compression:

Stored size: 706 Bytes

Contents

require "pathname"

module Standard
  class ResolvesYamlOption
    def call(argv, search_path, option_name, default_file)
      search_argv(argv, option_name) || FileFinder.new.call(default_file, search_path)
    end

    private

    def search_argv(argv, option_name)
      return unless (config_file = argv_value_for(argv, option_name))

      resolved_config = Pathname.new(config_file)
      if resolved_config.exist?
        resolved_config.expand_path
      else
        raise "Configuration file \"#{resolved_config.expand_path}\" not found."
      end
    end

    def argv_value_for(argv, option_name)
      return unless (index = argv.index(option_name))
      argv[index + 1]
    end
  end
end

Version data entries

108 entries across 108 versions & 3 rubygems

Version Path
standard-1.28.5 lib/standard/resolves_yaml_option.rb
standard-1.28.4 lib/standard/resolves_yaml_option.rb
standard-1.28.3 lib/standard/resolves_yaml_option.rb
standard-1.28.2 lib/standard/resolves_yaml_option.rb
standard-1.28.1 lib/standard/resolves_yaml_option.rb
standard-1.28.0 lib/standard/resolves_yaml_option.rb
standard-1.27.0 lib/standard/resolves_yaml_option.rb
standard-1.26.0 lib/standard/resolves_yaml_option.rb