Module: Gist::Standalone

Extended by:
Standalone
Included in:
Standalone
Defined in:
lib/gist/standalone.rb

Constant Summary collapse

PREAMBLE =
<<-preamble
#!/usr/bin/env ruby
# encoding: utf-8
#
# This file, gist, is generated code.
# Please DO NOT EDIT or send patches for it.
#
# Please take a look at the source from
# http://github.com/defunkt/gist
# and submit patches against the individual files
# that build gist.
#

preamble
POSTAMBLE =
"Gist.execute(*ARGV)\n"
MANPAGE =
"__END__\n#{File.read(__DIR__ + '/../../man/gist.1')}"
CACERT =
"__CACERT__\n#{File.read(__DIR__ + '/cacert.pem')}"

Instance Method Summary collapse

Instance Method Details

#buildObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/gist/standalone.rb', line 33

def build
  root = File.dirname(__FILE__)

  standalone = ''
  standalone << PREAMBLE

  Dir["#{root}/../**/*.rb"].each do |file|
    # skip standalone.rb
    next if File.expand_path(file) == File.expand_path(__FILE__)

    File.readlines(file).each do |line|
      next if line =~ /^\s*#/
      standalone << line
    end
  end

  standalone << POSTAMBLE
  standalone << MANPAGE
  standalone << CACERT
  standalone
end

#save(filename, path = '.') ⇒ Object



25
26
27
28
29
30
31
# File 'lib/gist/standalone.rb', line 25

def save(filename, path = '.')
  target = File.join(File.expand_path(path), filename)
  File.open(target, 'w') do |f|
    f.puts build
    f.chmod 0755
  end
end