Sha256: 74d9ca4ee228238524718be39df4d87f08683c6f05add0c642c1b4e975ffa6b9

Contents?: true

Size: 1.4 KB

Versions: 1

Compression:

Stored size: 1.4 KB

Contents

module PrivatePlease::Tracking::LoadUtils

  module StandardLibUtils

    class << self

      def standard_lib?(requiree)
        path_base   =  "#{std_lib_home}/#{requiree}"
        if File.exists?(path_base)
          path_base
        elsif File.exists?("#{path_base}.rb")
          "#{path_base}.rb"
        end
      end

    #-------------------------------------------------------------------------------------------------------------------
    private

      # Ex:  "/Users/ara/.rbenv/versions/jruby-1.7.3/bin/jruby"
      def ruby_executable
        @@_ruby_executable ||= GemUtils.gem_env.match(/RUBY EXECUTABLE:\s*(.*)/)[1]
      end

      # Ex: "/Users/ara/.rbenv/versions/jruby-1.7.3/lib/ruby/1.9"
      def std_lib_home
        @@_std_lib_home ||= begin
          basedir      = ruby_executable.gsub(/bin\/[j]?ruby/, 'lib/ruby') # => "/Users/ara/.rbenv/versions/jruby-1.7.3/lib/ruby"
                                                  # jruby has 2+ directories of std. libs under the basedir : 1.8 and 1.9
          $:.detect {|path|                       # We choose the one that is also in the load path.
            path =~ /#{basedir}\/[12][^\/]+$/     #
          }                                       # => "/Users/ara/.rbenv/versions/jruby-1.7.3/lib/ruby/1.9"
        end                                       #                                                     ^^^ == the mode
      end

    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
private_please-0.0.5 lib/private_please/tracking/load_utils/standard_lib_utils.rb