Class: Avm::Sources::Configuration

Inherits:
EacConfig::OldConfigs
  • Object
show all
Defined in:
lib/avm/sources/configuration.rb,
lib/avm/sources/configuration/rubocop.rb

Defined Under Namespace

Modules: Rubocop

Constant Summary collapse

FILENAMES =
%w[.avm.yml .avm.yaml].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Configuration

Returns a new instance of Configuration.



45
46
47
# File 'lib/avm/sources/configuration.rb', line 45

def initialize(path)
  super(nil, storage_path: path)
end

Class Method Details

.find_by_path(path) ⇒ Object



15
16
17
18
# File 'lib/avm/sources/configuration.rb', line 15

def find_by_path(path)
  path = ::Pathname.new(path.to_s) unless path.is_a?(::Pathname)
  internal_find_path(path.expand_path)
end

.find_in_path(path) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/avm/sources/configuration.rb', line 20

def find_in_path(path)
  absolute_pathname = path.to_pathname.expand_path
  if absolute_pathname.directory?
    FILENAMES.each do |filename|
      file = absolute_pathname.join(filename)
      return new(file) if file.exist?
    end
  end
  nil
end

.temp_instanceObject



31
32
33
# File 'lib/avm/sources/configuration.rb', line 31

def temp_instance
  new(::Tempfile.new(['.avm', '.yaml']))
end

Instance Method Details

#read_command(key) ⇒ EacRubyUtils::Envs::Command

Utility to read a configuration as a [EacRubyUtils::Envs::Command].

Returns:

  • (EacRubyUtils::Envs::Command)


51
52
53
54
55
56
# File 'lib/avm/sources/configuration.rb', line 51

def read_command(key)
  read_entry(key).if_present do |v|
    args = v.is_a?(::Enumerable) ? v.map(&:to_s) : ::Shellwords.split(v)
    ::EacRubyUtils::Envs.local.command(args).chdir(::File.dirname(storage_path))
  end
end