Class: Avm::Instances::Configuration

Inherits:
EacRubyUtils::Configs
  • Object
show all
Defined in:
lib/avm/instances/configuration.rb,
lib/avm/instances/configuration/_tests.rb,
lib/avm/instances/configuration/_locale.rb,
lib/avm/instances/configuration/_rubocop.rb

Constant Summary collapse

FILENAMES =
%w[.avm.yml .avm.yaml].freeze
BUNDLE_TEST_COMMAND_KEY =
'test.bundle_command'
TEST_COMMAND_KEY =
'test.command'
LOCALE_KEY =
:locale
RUBOCOP_COMMAND_KEY =
'ruby.rubocop.command'
RUBOCOP_GEMFILE_KEY =
'ruby.rubocop.gemfile'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Configuration

Returns a new instance of Configuration.



41
42
43
# File 'lib/avm/instances/configuration.rb', line 41

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

Class Method Details

.find_by_path(path) ⇒ Object



15
16
17
18
# File 'lib/avm/instances/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/instances/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

Instance Method Details

#any_test_commandObject



11
12
13
# File 'lib/avm/instances/configuration/_tests.rb', line 11

def any_test_command
  bundle_test_command || test_command
end

#bundle_test_commandObject



19
20
21
22
23
24
# File 'lib/avm/instances/configuration/_tests.rb', line 19

def bundle_test_command
  read_entry(BUNDLE_TEST_COMMAND_KEY).if_present do |v|
    args = v.is_a?(::Enumerable) ? v.map(&:to_s) : ::Shellwords.split(v)
    ::EacRubyGemsUtils::Gem.new(::File.dirname(storage_path)).bundle(*args).chdir_root
  end
end

#localeObject



11
12
13
# File 'lib/avm/instances/configuration/_locale.rb', line 11

def locale
  read_entry(LOCALE_KEY) || ::I18n.default_locale
end

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

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

Returns:

  • (EacRubyUtils::Envs::Command)


47
48
49
50
51
52
# File 'lib/avm/instances/configuration.rb', line 47

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

#rubocop_commandObject



9
10
11
# File 'lib/avm/instances/configuration/_rubocop.rb', line 9

def rubocop_command
  read_command(RUBOCOP_COMMAND_KEY)
end

#rubocop_gemfileObject



13
14
15
16
17
18
19
20
21
# File 'lib/avm/instances/configuration/_rubocop.rb', line 13

def rubocop_gemfile
  gemfile_path = read_entry(RUBOCOP_GEMFILE_KEY)
  return nil if gemfile_path.blank?

  gemfile_path = gemfile_path.to_pathname.expand_path(storage_path.parent)
  return gemfile_path if gemfile_path.file?

  raise "Gemfile path \"#{gemfile_path}\" does not exist or is not a file"
end

#test_commandObject



15
16
17
# File 'lib/avm/instances/configuration/_tests.rb', line 15

def test_command
  read_command(TEST_COMMAND_KEY)
end