Class: UsZipcode::ModelsGenerator

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

banner

Constructor Details

#initialize(*args, &block) ⇒ ModelsGenerator

Returns a new instance of ModelsGenerator.



7
8
9
10
# File 'lib/generators/us_zipcode/models_generator.rb', line 7

def initialize(*args, &block)
  super
  migration_template 'migration.rb', "db/migrate/create_us_zipcode_models.rb"
end

Class Method Details

.next_migration_number(dirname) ⇒ Object

Implement the required interface for Rails::Generators::Migration. taken from github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb



28
29
30
31
32
33
34
# File 'lib/generators/us_zipcode/models_generator.rb', line 28

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

Instance Method Details

#add_gemsObject



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

def add_gems
  add_gem "mocha", :group => :test
end

#create_modelsObject



20
21
22
23
24
# File 'lib/generators/us_zipcode/models_generator.rb', line 20

def create_models
  template 'zipcode_model.rb', "app/models/zipcode.rb"
  template 'county_model.rb', "app/models/county.rb"
  template 'state_model.rb', "app/models/state.rb"
end

#create_rakefileObject



36
37
38
# File 'lib/generators/us_zipcode/models_generator.rb', line 36

def create_rakefile
  template 'zipcodes.rake', "lib/tasks/zipcodes.rake"
end

#generate_modelsObject



12
13
14
# File 'lib/generators/us_zipcode/models_generator.rb', line 12

def generate_models
  # puts ">>> generate_zipcodes:"
end