Class: SunRaise::Generator
- Inherits:
-
Object
- Object
- SunRaise::Generator
- Defined in:
- lib/generator.rb
Overview
generates sunraise file
Class Method Summary collapse
Class Method Details
.run ⇒ Object
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 |
# File 'lib/generator.rb', line 5 def self.run # check if ./sunrise already exists if File.file? './sunraise' puts 'file ' + 'sunraise'.color(:blue) + ' already exists' exit end # check .git folder unless File.directory? './.git' puts 'no ' + '.git'.color(:blue) + ' directory found' exit end # detecting origins git = `git remote -v | grep origin` # parse git url remote = git.split("\n").first.split(" ")[1] # parse project name # [email protected]:Paxa/ShopFront.git => ShopFront dir = remote.match(/.+@.+:.+\/(.+)\.git/)[1] # calculate executing path bin_dir = File.dirname File.(__FILE__) # open and render template template = ERB.new File.new(File.join bin_dir, '../sunraise-template.erb').read result_content = template.result(binding) # write it to file File.open('./sunraise', 'w') {|f| f.write result_content } puts 'file ' + 'sunraise'.color(:blue) + ' successfuly created' exit end |