Module: Hub::Standalone
Constant Summary collapse
- HUB_ROOT =
File.('../../..', __FILE__)
- PREAMBLE =
<<-preamble # # This file is generated code. DO NOT send patches for it. # # Original source files with comments are at: # https://github.com/defunkt/hub # preamble
Instance Method Summary collapse
- #build(io) ⇒ Object
- #each_source_file ⇒ Object
- #ruby_executable ⇒ Object
- #save(filename, path = '.') ⇒ Object
Instance Method Details
#build(io) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/hub/standalone.rb', line 25 def build io io.puts "#!#{ruby_executable}" io << PREAMBLE each_source_file do |filename| File.open(filename, 'r') do |source| source.each_line {|line| io << line if line !~ /^\s*#/ } end io.puts '' end io.puts "Hub::Runner.execute(*ARGV)" io.puts "\n__END__" io << File.read(File.join(HUB_ROOT, 'man/hub.1')) end |
#each_source_file ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/hub/standalone.rb', line 41 def each_source_file File.open(File.join(HUB_ROOT, 'lib/hub.rb'), 'r') do |main| main.each_line do |req| if req =~ /^require\s+["'](.+)["']/ yield File.join(HUB_ROOT, 'lib', "#{$1}.rb") end end end end |
#ruby_executable ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/hub/standalone.rb', line 51 def ruby_executable if File.executable? '/usr/bin/ruby' then '/usr/bin/ruby' else require 'rbconfig' File.join RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name'] end end |
#save(filename, path = '.') ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/hub/standalone.rb', line 17 def save(filename, path = '.') target = File.join(File.(path), filename) File.open(target, 'w') do |f| build f f.chmod 0755 end end |