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/github/hub # preamble
Instance Method Summary collapse
- #build(io) ⇒ Object
- #detailed_version ⇒ Object
- #each_source_file ⇒ Object
- #ruby_executable ⇒ Object
- #ruby_shebang ⇒ 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 40 41 42 43 44 45 46 |
# File 'lib/hub/standalone.rb', line 25 def build io io.puts "#!#{ruby_shebang}" io << PREAMBLE io.puts "Encoding.default_external = 'UTF-8' if defined?(Encoding)" each_source_file do |filename| File.open(filename, 'r') do |source| source.each_line do |line| next if line =~ /^\s*#/ if line.include?(' VERSION =') line.sub!(/'(.+?)'/, "'#{detailed_version}'") end io << line end 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 |
#detailed_version ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/hub/standalone.rb', line 58 def detailed_version version = `git describe --tags HEAD 2>/dev/null`.chomp if version.empty? version = Hub::VERSION head_sha = `git rev-parse --short HEAD 2>/dev/null`.chomp version += "-g#{head_sha}" unless head_sha.empty? version else version.sub(/^v/, '') end end |
#each_source_file ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/hub/standalone.rb', line 48 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
70 71 72 73 74 75 76 |
# File 'lib/hub/standalone.rb', line 70 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 |
#ruby_shebang ⇒ Object
78 79 80 81 82 83 84 85 86 |
# File 'lib/hub/standalone.rb', line 78 def ruby_shebang ruby = ruby_executable `RUBYOPT= #{ruby_executable} --disable-gems -e0 2>/dev/null` if $?.success? "#{ruby} --disable-gems" else ruby 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 |