Class: BrainDamage::FullGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/brain_damage/full/full_generator.rb

Instance Method Summary collapse

Instance Method Details

#just_do_itObject



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
# File 'lib/generators/brain_damage/full/full_generator.rb', line 7

def just_do_it
  action = options[:destroy] ? 'd' : 'g'

  descriptions = if options[:descriptions] == '*'
    then
      Dir["desc/*"].map { |description|
        file_name = description.split('/').last
        if file_name =~ /\d+\./ then
          file_name
        else
          nil
        end
      }.reject(&:nil?)
  else
    options[:descriptions].split(',').map(&:strip)
  end

  descriptions.each do |description|
    add = if options[:force]
            '--force'
          else
            ''
          end

    cmd = "rails #{action} brain_damage:resource --description=#{description} #{add}"
    puts cmd
    spawn cmd
  end
end