Class: Crystallize::Creator
- Inherits:
-
Object
- Object
- Crystallize::Creator
- Defined in:
- lib/crystallize/creator.rb
Instance Method Summary collapse
-
#initialize ⇒ Creator
constructor
A new instance of Creator.
- #rename_files ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize ⇒ Creator
Returns a new instance of Creator.
5 6 7 8 9 10 11 |
# File 'lib/crystallize/creator.rb', line 5 def initialize args = ARGV @gem_name = args.shift if @gem_name.blank? puts "Please specify a gem name:\ncrystallize my_gem" and return end end |
Instance Method Details
#rename_files ⇒ Object
32 33 34 |
# File 'lib/crystallize/creator.rb', line 32 def rename_files %x[for f in *gem_name*; do mv "$f" "`echo $f | sed s/gem_name/#{@gem_name}/`"; done] end |
#run ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/crystallize/creator.rb', line 13 def run gem_dir = "#{Dir.pwd}/#{@gem_name}" FileUtils.rm_rf(gem_dir) FileUtils.cp_r("#{Crystallize.dir}/gem_name", gem_dir) Dir.chdir(gem_dir) do rename_files Dir.glob('**/*').each do |name| next unless File.file?(name) content = File.read(name) content.gsub!('gem_name', @gem_name) content.gsub!('GemName', @gem_name.camelize) File.write(name, content) end end Dir.chdir("#{gem_dir}/lib") do rename_files end end |