Sha256: 8847bf15e919f1b70449d377a5a292ef99f13e32b1f7cede4277bb4bece4f087

Contents?: true

Size: 1.58 KB

Versions: 17

Compression:

Stored size: 1.58 KB

Contents

# frozen_string_literal: true

require 'eac_config/old_configs'
require 'eac_ruby_utils/core_ext'
require 'yaml'

module Avm
  module Apps
    module Sources
      class Configuration < ::EacConfig::OldConfigs
        require_sub __FILE__

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

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

          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

          private

          def internal_find_path(absolute_pathname)
            r = find_in_path(absolute_pathname)
            return r if r.present?

            internal_find_path(absolute_pathname.dirname) unless absolute_pathname.root?
          end
        end

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

        # Utility to read a configuration as a [EacRubyUtils::Envs::Command].
        # @return [EacRubyUtils::Envs::Command]
        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
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 3 rubygems

Version Path
avm-tools-0.106.0 vendor/avm-apps/lib/avm/apps/sources/configuration.rb
avm-apps-0.4.1 lib/avm/apps/sources/configuration.rb
avm-tools-0.105.0 vendor/avm-apps/lib/avm/apps/sources/configuration.rb
avm-tools-0.104.0 vendor/avm-apps/lib/avm/apps/sources/configuration.rb
avm-tools-0.103.1 vendor/avm-apps/lib/avm/apps/sources/configuration.rb
avm-tools-0.103.0 vendor/avm-apps/lib/avm/apps/sources/configuration.rb
avm-apps-0.4.0 lib/avm/apps/sources/configuration.rb
ehbrs-tools-0.22.0 vendor/avm-apps/lib/avm/apps/sources/configuration.rb
avm-tools-0.102.2 vendor/avm-apps/lib/avm/apps/sources/configuration.rb
avm-tools-0.102.1 vendor/avm-apps/lib/avm/apps/sources/configuration.rb
avm-tools-0.102.0 vendor/avm-apps/lib/avm/apps/sources/configuration.rb
avm-apps-0.3.0 lib/avm/apps/sources/configuration.rb
avm-tools-0.101.0 vendor/avm-apps/lib/avm/apps/sources/configuration.rb
avm-tools-0.100.0 vendor/avm-apps/lib/avm/apps/sources/configuration.rb
avm-tools-0.99.1 vendor/avm-apps/lib/avm/apps/sources/configuration.rb
avm-apps-0.2.1 lib/avm/apps/sources/configuration.rb
avm-tools-0.99.0 vendor/avm-apps/lib/avm/apps/sources/configuration.rb