Sha256: ea4170803ef37d96026fb462d6364db2a8edc7077844b1323cc5c4c1d5ee4da7

Contents?: true

Size: 1.58 KB

Versions: 3

Compression:

Stored size: 1.58 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/configs'
require 'eac_ruby_utils/core_ext'
require 'yaml'

module Avm
  module Apps
    module Sources
      class Configuration < ::EacRubyUtils::Configs
        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

3 entries across 3 versions & 2 rubygems

Version Path
avm-tools-0.98.0 vendor/avm-apps/lib/avm/apps/sources/configuration.rb
avm-apps-0.2.0 lib/avm/apps/sources/configuration.rb
avm-tools-0.97.0 vendor/avm-apps/lib/avm/apps/sources/configuration.rb