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.44.0 lib/standard/resolves_yaml_option.rb
standard-1.43.0 lib/standard/resolves_yaml_option.rb
standard-1.42.1 lib/standard/resolves_yaml_option.rb
standard-1.42.0 lib/standard/resolves_yaml_option.rb
standard-1.41.1 lib/standard/resolves_yaml_option.rb
standard-1.41.0 lib/standard/resolves_yaml_option.rb
standard-1.40.1 lib/standard/resolves_yaml_option.rb
standard-1.40.0 lib/standard/resolves_yaml_option.rb
standard-1.39.2 lib/standard/resolves_yaml_option.rb
standard-1.39.1 lib/standard/resolves_yaml_option.rb
standard-1.39.0 lib/standard/resolves_yaml_option.rb
standard-1.38.0 lib/standard/resolves_yaml_option.rb
standard-1.37.0 lib/standard/resolves_yaml_option.rb
harbr-2.8.1 vendor/bundle/ruby/3.2.0/gems/standard-1.32.0/lib/standard/resolves_yaml_option.rb
standard-1.35.0.1 lib/standard/resolves_yaml_option.rb
standard-1.34.0.1 lib/standard/resolves_yaml_option.rb
standard-1.35.1 lib/standard/resolves_yaml_option.rb
standard-1.35.0 lib/standard/resolves_yaml_option.rb
standard-1.34.0 lib/standard/resolves_yaml_option.rb
harbr-0.2.10 vendor/bundle/ruby/3.2.0/gems/standard-1.32.0/lib/standard/resolves_yaml_option.rb