Created
October 25, 2014 04:55
-
-
Save jeffutter/f628fc2182f49d9fe076 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/bundler-mem.rb | |
require 'action_view' | |
module Bundler | |
class Runtime | |
include ActionView::Helpers::NumberHelper | |
REQUIRE_ERRORS = [ | |
/^no such file to load -- (.+)$/i, | |
/^Missing \w+ (?:file\s*)?([^\s]+.rb)$/i, | |
/^Missing API definition file in (.+)$/i, | |
/^cannot load such file -- (.+)$/i, | |
/^dlopen\([^)]*\): Library not loaded: (.+)$/i, | |
] | |
def require(*groups) | |
groups.map! { |g| g.to_sym } | |
groups = [:default] if groups.empty? | |
@definition.dependencies.each do |dep| | |
# Skip the dependency if it is not in any of the requested | |
# groups | |
next unless ((dep.groups & groups).any? && dep.current_platform?) | |
required_file = nil | |
begin | |
# Loop through all the specified autorequires for the | |
# dependency. If there are none, use the dependency's name | |
# as the autorequire. | |
Array(dep.autorequire || dep.name).each do |file| | |
# Allow `require: true` as an alias for `require: <name>` | |
file = dep.name if file == true | |
required_file = file | |
# puts "Before loading: #{file}: #{system("vmmap #{$$} | tail -5")}" | |
b = %x(pmap #{$$} | tail -1)[10,40].strip.gsub('K','').to_i | |
before = number_to_human_size(b*1024) | |
Kernel.require file | |
a = %x(pmap #{$$} | tail -1)[10,40].strip.gsub('K','').to_i | |
after = number_to_human_size(a*1024) | |
# puts "Before loading:\t#{file}:\t#{before}" | |
puts "After loading:\t#{file}:\t#{after}" | |
puts "Change:\t\t#{file}:\t#{number_to_human_size((a-b)*1024)}\n" | |
end | |
rescue LoadError => e | |
REQUIRE_ERRORS.find { |r| r =~ e.message } | |
raise if dep.autorequire || $1 != required_file | |
if dep.autorequire.nil? && dep.name.include?('-') | |
begin | |
namespaced_file = dep.name.gsub('-', '/') | |
Kernel.require namespaced_file | |
rescue LoadError => e | |
REQUIRE_ERRORS.find { |r| r =~ e.message } | |
raise if $1 != namespaced_file | |
end | |
end | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment