class Leosca::Generators::MassiveGenerator
Public Instance Methods
scaffold()
click to toggle source
# File lib/generators/leosca/massive_generator.rb, line 13 def scaffold # puts "args #{self.args}" # puts "options #{self.options}" puts "behavior #{self.behavior}" # puts "shell #{self.shell}" # puts "in_group #{self.instance_variable_get(:@in_group)}" # puts "_invocations #{self.instance_variable_get(:@_invocations)}" # puts "_initializer #{self.instance_variable_get(:@_initializer)}" # return nil num_ok, num_ko, num_discards = 0, 0, 0 time = Time.now begin filename = "scaffold.txt" raise "Write all your resources into #{filename} in the app root" unless File.exist? filename puts "#{time.strftime("%H:%M:%S")} - Starting generations, please wait..." puts "-" * 45 File.open(filename, "r") do |file| while (line = file.gets) begin case generate line when true num_ok += 1 when false num_ko += 1 when nil num_discards += 1 end rescue num_ko += 1 puts "*** #{$!.message} ***" end end end rescue puts "Oh oh, generation interrupted! #{$!.message} ***" end puts "-" * 45 puts "Generations started at #{time.strftime("%H:%M:%S")}" puts "#{Time.now.strftime("%H:%M:%S")} - generations ended in #{(Time.now-time).to_i} second(s)" puts "#{num_ok} generation#{'s' unless num_ok == 1} executed" puts "#{num_discards} line#{'s' unless num_discards == 1} discarded (comments etc.)" if num_discards>0 puts "#{num_ko} generation#{'s' unless num_ko == 1} *** FAILED ***" if num_ko>0 puts "-" * 45 end
Private Instance Methods
generate(line)
click to toggle source
# File lib/generators/leosca/massive_generator.rb, line 62 def generate line regexp_rails_g = 'rails [dg][a-z]*\s' line.strip! unless line.empty? or line[0..0]=="#" if /#{regexp_rails_g}/i === line # Will invoke a custom generator specified in the line line.sub! /#{regexp_rails_g}/i, '' generator_name = line.match(/\w+/).to_s line.sub! /#{generator_name}/, '' line.strip! else generator_name = 'leosca' end raise "Generator not recognized! #{line[0..20]}..." if /^rails/ === line puts "#{generator_name} #{line}" Rails::Generators.invoke generator_name, line.split(' '), :behavior => self.behavior true else nil end end