Class: Fatbundle::Packager
- Inherits:
-
Object
- Object
- Fatbundle::Packager
- Defined in:
- lib/fatbundle/packager.rb
Instance Method Summary collapse
- #collect(path) ⇒ Object
-
#initialize ⇒ Packager
constructor
A new instance of Packager.
- #pack ⇒ Object
Constructor Details
#initialize ⇒ Packager
Returns a new instance of Packager.
6 7 8 |
# File 'lib/fatbundle/packager.rb', line 6 def initialize @files = {} end |
Instance Method Details
#collect(path) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/fatbundle/packager.rb', line 52 def collect(path) base = Pathname.new(path) Dir["#{path}/**/*.rb"].each do |file| name = Pathname.new(file).relative_path_from(base) @files[name.sub(/\.rb$/, '').to_s] ||= File.read(file) end end |
#pack ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/fatbundle/packager.rb', line 10 def pack # assuming it's running under bundler already Bundler.load.specs.each do |spec| unless spec.extensions.empty? warn "Can't package C extension #{spec.name}" next end spec.load_paths.each do |path| warn "Packing #{spec.name} from #{spec.gem_dir}" collect(path) end end preamble = " module Fatbundle\n FILES = \#{@files.inspect}\n LOADED = []\n end\n\n module Kernel\n alias original_require require\n def require(file)\n if Fatbundle::LOADED.include?(file)\n return true\n end\n\n if Fatbundle::FILES[file]\n Fatbundle::LOADED << file\n return eval(Fatbundle::FILES[file], TOPLEVEL_BINDING)\n end\n\n warn \"File '\\\#{file}' not found in Fatbundle, falling back to original require\" if ENV['FATBUNDLE_DEBUG']\n original_require(file)\n end\n end\n \n EOF\n\n puts preamble.gsub /^ {8}/, ''\nend\n" |