Sha256: bb0f2a41d58e8a513f641e77e0495dd606979238f36d0aeafdbe465589471082

Contents?: true

Size: 873 Bytes

Versions: 5

Compression:

Stored size: 873 Bytes

Contents

# frozen_string_literal: true

module RubyNext
  module Utils
    module_function

    if $LOAD_PATH.respond_to?(:resolve_feature_path)
      def resolve_feature_path(feature)
        $LOAD_PATH.resolve_feature_path(feature)&.last
      end
    else
      def resolve_feature_path(path)
        if File.file?(relative = File.expand_path(path))
          path = relative
        end

        path = "#{path}.rb" if File.extname(path).empty?

        return path if Pathname.new(path).absolute?

        $LOAD_PATH.find do |lp|
          lpath = File.join(lp, path)
          return lpath if File.file?(lpath)
        end
      end
    end

    def source_with_lines(source, path)
      source.lines.map.with_index do |line, i|
        "#{(i + 1).to_s.rjust(4)}:  #{line}"
      end.tap do |lines|
        lines.unshift "   0:  # source: #{path}"
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
ruby-next-core-0.4.0 lib/ruby-next/utils.rb
ruby-next-0.3.0 lib/ruby-next/utils.rb
ruby-next-core-0.3.0 lib/ruby-next/utils.rb
ruby-next-0.2.0 lib/ruby-next/utils.rb
ruby-next-core-0.2.0 lib/ruby-next/utils.rb