Sha256: 39875068a3170eb1cf61a94888c7a04e6a871f4c5c156c228ff4f08303c793d0

Contents?: true

Size: 1.04 KB

Versions: 6

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

module Avm
  module Launcher
    module Paths
      class Real < String
        def initialize(path)
          raise "Argument path is not a string: \"#{path}\"|#{path.class}" unless path.is_a?(String)

          super
        end

        def subpath(relative_path)
          ::Avm::Launcher::Paths::Real.new(::File.expand_path(relative_path, self))
        end

        def basename
          ::File.basename(self)
        end

        def dirname
          return nil if self == '/'

          self.class.new(::File.dirname(self))
        end

        def find_file_with_extension(extension)
          r = find_files_with_extension(extension)
          return r.first if r.any?

          raise "Extension \"#{extension}\" not found in directory \"#{self}\""
        end

        def find_files_with_extension(extension)
          r = []
          ::Dir.entries(self).each do |i|
            r << ::File.expand_path(i, self) if i =~ /#{::Regexp.quote(extension)}\z/
          end
          r
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
avm-0.94.0 lib/avm/launcher/paths/real.rb
eac_tools-0.94.0 sub/avm/lib/avm/launcher/paths/real.rb
avm-0.93.0 lib/avm/launcher/paths/real.rb
eac_tools-0.92.0 sub/avm/lib/avm/launcher/paths/real.rb
avm-0.92.0 lib/avm/launcher/paths/real.rb
eac_tools-0.91.0 sub/avm/lib/avm/launcher/paths/real.rb