forked from sferik/twitter-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
47 lines (37 loc) · 1.25 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
require 'bundler'
Bundler::GemHelper.install_tasks
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
task :test => :spec
task :default => :spec
require 'yard'
YARD::Rake::YardocTask.new
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