Created
May 3, 2011 13:19
-
-
Save jcf/953311 to your computer and use it in GitHub Desktop.
Namespace the twitter gem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :twitter do | |
desc 'Stick Twitter in a Nunemaker namespace' | |
task :namespace do | |
ROOT = File.dirname(__FILE__) + '/' | |
def append_to_file(path, text) | |
path = ROOT + path | |
lines = File.readlines(path) | |
lines.unshift(text) | |
File.open(path, 'w') { |io| io.write(lines.join("\n")) } | |
end | |
File.open(ROOT + 'lib/nunemaker.rb', 'w') do |io| | |
io.puts "module Nunemaker\nend" | |
end | |
files = Dir[ROOT + '{lib,spec}/**/*.rb'] | |
fixtures = Dir[ROOT + 'spec/fixtures/**/*.json'] | |
gemspec = ROOT + 'twitter.gemspec' | |
(files + fixtures + [gemspec]).each do |path| | |
contents = File.read(path) | |
# `sed -i '' -e 's/Twitter/Nunemaker::Twitter/g' #{path}` | |
if contents.gsub!(/\b(?<!Nunemaker::)Twitter\b/, 'Nunemaker::Twitter') | |
File.open(path, 'w') { |io| io.write contents } | |
end | |
end | |
append_to_file('lib/twitter.rb', "require 'nunemaker'") | |
append_to_file('lib/twitter/version.rb', | |
"require File.expand_path('../../nunemaker', __FILE__)") | |
system 'rake' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment