Class: ScrapbookerGenerator

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

Constant Summary collapse

@@migrations =
false

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ ScrapbookerGenerator

Returns a new instance of ScrapbookerGenerator.



10
11
12
13
14
# File 'lib/generators/scrapbooker.rb', line 10

def initialize(args,*)
  super
  given_name = args.first
  @class_name = test_singularity(given_name) ? given_name.underscore : given_name.singularize.underscore
end

Instance Attribute Details

#class_nameObject

Returns the value of attribute class_name.



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

def class_name
  @class_name
end

Class Method Details

.next_migration_number(dirname) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/generators/scrapbooker.rb', line 26

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

Instance Method Details

#create_migrationObject



20
21
22
# File 'lib/generators/scrapbooker.rb', line 20

def create_migration
  migration_template "migration.rb", "db/migrate/#{migration_file_name}"
end

#create_modelObject



16
17
18
# File 'lib/generators/scrapbooker.rb', line 16

def create_model
  template "model.rb", "app/models/#{@class_name}.rb"
end