Class: ContentmentGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/contentment_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(dirname) ⇒ Object

:nodoc:



13
14
15
16
17
18
19
# File 'lib/generators/contentment_generator.rb', line 13

def self.next_migration_number(dirname) #:nodoc:
  if ActiveRecord::Base.timestamped_migrations
    Time.now.utc.strftime("%Y%m%d%H%M%S")
  else
    "%.3d" % (current_migration_number(dirname) + 1)
  end
end

.source_rootObject



8
9
10
11
# File 'lib/generators/contentment_generator.rb', line 8

def self.source_root
  # This must be defined.  It tells the generator where to find the template for your migration.
  File.join(File.dirname(__FILE__), 'contentment/templates')
end

Instance Method Details

#create_migration_fileObject

This method is pulling all of the migration data from the migration.rb template. After it pulls the migration date, it generates a migration in the main application called create_contents



43
44
45
# File 'lib/generators/contentment_generator.rb', line 43

def create_migration_file
  migration_template 'migration.rb', 'db/migrate/create_contents.rb'
end

#installObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/generators/contentment_generator.rb', line 21

def install
  content_model = "app/models/content.rb"
  if File.exists?(content_model)
    puts "Well, Fuck."
    # Need to figure out how to ask the user if they would like to overwrite their model.
  else
    template 'content.rb', content_model
    template 'content_test.rb', 'test/unit/content_test.rb'
  end

  contents_controller = 'app/controllers/contents_controller.rb'
  if File.exists?(contents_controller)
    puts "Damn, him too?"
    # Again, figure out how to ask the user if they want to overwrite it.
  else
    template 'contents_controller.rb', contents_controller
  end
end