Sha256: 607b289e381bc39cc41d1088411782448bb364542283714eafadf09f61c1f664

Contents?: true

Size: 946 Bytes

Versions: 1

Compression:

Stored size: 946 Bytes

Contents

module Zeus
  class Server
    class LoadTracking

      def self.inject!(server)
        $server = server
        class << Kernel
          alias_method :__original_load, :load
          def load(file, *a)
            LoadTracking.add_feature($server, file)
            __original_load(file, *a)
          end
        end
      end

      def self.add_feature(server, file)
        if absolute_path?(file)
          server.add_extra_feature(file)
        elsif File.exist?("./#{file}")
          server.add_extra_feature(File.expand_path("./#{file}"))
        else
          path = find_in_load_path(file)
          server.add_extra_feature(path) if path
        end
      end

      def self.find_in_load_path(file)
        path = $LOAD_PATH.detect { |path| File.exist?("#{path}/#{file}") }
        "#{path}/#{file}" if path
      end

      def self.absolute_path?(file)
        file =~ /^\// && File.exist?(file)
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
zeus-0.4.1 lib/zeus/server/load_tracking.rb