Class: ActiveUnimodGenerator

Inherits:
Rails::Generator::Base
  • Object
show all
Defined in:
lib/generators/active_unimod/active_unimod_generator.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(runtime_args, runtime_options = {}) ⇒ ActiveUnimodGenerator

Returns a new instance of ActiveUnimodGenerator.



4
5
6
7
# File 'lib/generators/active_unimod/active_unimod_generator.rb', line 4

def initialize(runtime_args, runtime_options = {})
  super
  @destination_root = runtime_args.shift || Dir.pwd
end

Instance Method Details

#manifestObject



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
39
40
# File 'lib/generators/active_unimod/active_unimod_generator.rb', line 9

def manifest
  record do |m|
    m.directory "app/models"
    m.directory "db/migrate"
    m.directory "lib/tasks"
    m.directory "test/fixtures"
    m.directory "test/unit"
    
    m.file "/../../../../lib/active_unimod_tasks.rb",  "lib/tasks/active_unimod_tasks.rake"
    
    root = File.expand_path( File.dirname(__FILE__) + "/../../../" )
    Dir.glob(File.join(root, "app/models/*.rb")).each do |model_file|
      model = File.basename(model_file).chomp(".rb")

      m.file "/../../../../app/models/#{model}.rb",  File.join('app/models', "#{model}.rb")
      m.template 'unit_test.rb',  File.join('test/unit', "#{model}_test.rb"), :assigns => {:class_name => model.camelize}
      unless options[:skip_fixtures] 
     	  m.template 'fixtures.yml',  File.join('test/fixtures', "#{model}.yml")
      end
    end
    
    unless options[:skip_migration]
      @migration_directory = File.join(@destination_root, 'db/migrate')
      migration_file_name = "active_unimod_schema"
      if migration_exists?(migration_file_name)
        raise "Another migration is already named #{migration_file_name}: #{existing_migrations(migration_file_name).first}"
      end
      
      m.file('/../../../../db/migrate/001_active_unimod_schema.rb', "db/migrate/#{next_migration_string}_#{migration_file_name}.rb")
    end
  end
end