Class: Leosca::Generators::MassiveGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/leosca/massive_generator.rb

Instance Method Summary collapse

Instance Method Details

#scaffoldObject



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
48
49
50
51
52
53
54
55
56
57
58
# 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