Class: GitHubBub
- Inherits:
-
Object
- Object
- GitHubBub
- Defined in:
- lib/githubbub.rb
Constant Summary collapse
- VERSION =
:stopdoc:
'1.0.0'
- SETUP =
<<-SETUP require 'rbconfig' # Ruby Interpreter location - taken from Rake source code RUBY = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']).sub(/.*\s.*/m, '"\&"') system "\#{RUBY} -S gem install --version '%s' --source http://gems.github.com %s-%s" File.open('Makefile','w') {|fd| fd.puts "install:\\n\\t@-echo -n ''"} SETUP
- WRAPPER =
<<-WRAPPER require 'rubygems' gem '%s-%s' require '%s' WRAPPER
Instance Attribute Summary collapse
-
#gemspec ⇒ Object
Returns the value of attribute gemspec.
-
#github_user ⇒ Object
Returns the value of attribute github_user.
Class Method Summary collapse
- .run(args) ⇒ Object
-
.version ⇒ Object
:startdoc:.
Instance Method Summary collapse
- #build_gem ⇒ Object
- #get_user(user) ⇒ Object
-
#initialize ⇒ GitHubBub
constructor
A new instance of GitHubBub.
- #load_gemspec ⇒ Object
- #publish_gem(file) ⇒ Object
- #run(args) ⇒ Object
- #scrub ⇒ Object
- #tempdir ⇒ Object
- #write_gemspec ⇒ Object
- #write_setup ⇒ Object
- #write_wrapper ⇒ Object
Constructor Details
#initialize ⇒ GitHubBub
Returns a new instance of GitHubBub.
23 24 25 26 |
# File 'lib/githubbub.rb', line 23 def initialize @gemspec = nil @github_user = nil end |
Instance Attribute Details
#gemspec ⇒ Object
Returns the value of attribute gemspec.
21 22 23 |
# File 'lib/githubbub.rb', line 21 def gemspec @gemspec end |
#github_user ⇒ Object
Returns the value of attribute github_user.
21 22 23 |
# File 'lib/githubbub.rb', line 21 def github_user @github_user end |
Class Method Details
.run(args) ⇒ Object
17 18 19 |
# File 'lib/githubbub.rb', line 17 def self.run( args ) self.new.run args end |
.version ⇒ Object
:startdoc:
13 14 15 |
# File 'lib/githubbub.rb', line 13 def self.version VERSION end |
Instance Method Details
#build_gem ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/githubbub.rb', line 78 def build_gem dir = Dir.pwd path = tempdir Dir.chdir path write_setup write_wrapper gemspec.files = Dir.glob('**/*').find_all {|fn| test(?f, fn)}.sort gemspec.extensions = Dir.glob('**/extconf.rb').sort write_gemspec file = Gem::Builder.new(gemspec).build FileUtils.mv file, dir file ensure Dir.chdir dir if dir end |
#get_user(user) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/githubbub.rb', line 37 def get_user( user ) if user.nil? $stdout.write "What is your GitHub handle: " $stdout.flush orig = $stdin.gets user = orig.strip! end if user.nil? or user.empty? puts "You typed in #{orig.inspect} and I don't understand that!" puts "Usage:" puts " githubbub [github username]" abort end self.github_user = user end |
#load_gemspec ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/githubbub.rb', line 55 def load_gemspec fn = Dir.glob('*.gemspec').first if fn.nil? puts "I'm sorry, but I could not find a gemspec file!" abort end code = File.read(fn) self.gemspec = eval(code) end |
#publish_gem(file) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/githubbub.rb', line 97 def publish_gem( file ) rf = RubyForge.new rf.configure rescue nil puts 'Logging in to RubyForge' rf.login begin rf.lookup 'package', gemspec.name rescue RuntimeError puts "Creating package #{gemspec.name} under #{gemspec.rubyforge_project}" rf.create_package gemspec.rubyforge_project, gemspec.name end puts "Releasing #{gemspec.name} v. #{gemspec.version}" rf.add_release gemspec.rubyforge_project, gemspec.name, gemspec.version, file end |
#run(args) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/githubbub.rb', line 28 def run( args ) get_user args.first load_gemspec scrub file = build_gem publish_gem file end |
#scrub ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/githubbub.rb', line 66 def scrub gemspec.files = [] gemspec.has_rdoc = false gemspec.extra_rdoc_files = [] gemspec.executables = [] gemspec.default_executable = nil gemspec.date = Time.now.strftime("%Y-%m-%d") gemspec.instance_variable_get(:@dependencies).clear gemspec.bindir = nil gemspec end |
#tempdir ⇒ Object
114 115 116 117 118 119 120 121 122 |
# File 'lib/githubbub.rb', line 114 def tempdir fd = Tempfile.new 'githubbub-gem' path = fd.path fd.unlink FileUtils.mkdir_p path #at_exit { FileUtils.rm_rf(path) } at_exit { puts path } path end |
#write_gemspec ⇒ Object
138 139 140 141 142 |
# File 'lib/githubbub.rb', line 138 def write_gemspec name = gemspec.name + '.gemspec' gemspec.files << name File.open(name, 'w') {|fd| fd.write(gemspec.to_ruby)} end |
#write_setup ⇒ Object
124 125 126 127 128 129 |
# File 'lib/githubbub.rb', line 124 def write_setup FileUtils.mkdir 'ext' File.open(File.join('ext','extconf.rb'), 'w') do |fd| fd.write(SETUP % [gemspec.version, github_user, gemspec.name]) end end |
#write_wrapper ⇒ Object
131 132 133 134 135 136 |
# File 'lib/githubbub.rb', line 131 def write_wrapper FileUtils.mkdir 'lib' File.open(File.join('lib',"#{gemspec.name}.rb"), 'w') do |fd| fd.write(WRAPPER % [github_user, gemspec.name, gemspec.name]) end end |