Class: UsZipcode::ModelsGenerator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/generators/us_zipcode/models_generator.rb
Class Method Summary collapse
-
.next_migration_number(dirname) ⇒ Object
Implement the required interface for Rails::Generators::Migration.
Instance Method Summary collapse
- #add_gems ⇒ Object
- #create_models ⇒ Object
- #create_rakefile ⇒ Object
- #generate_models ⇒ Object
-
#initialize(*args, &block) ⇒ ModelsGenerator
constructor
A new instance of ModelsGenerator.
Methods inherited from Base
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. Time.now.utc.strftime("%Y%m%d%H%M%S") else "%.3d" % (current_migration_number(dirname) + 1) end end |
Instance Method Details
#add_gems ⇒ Object
16 17 18 |
# File 'lib/generators/us_zipcode/models_generator.rb', line 16 def add_gems add_gem "mocha", :group => :test end |
#create_models ⇒ Object
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_rakefile ⇒ Object
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_models ⇒ Object
12 13 14 |
# File 'lib/generators/us_zipcode/models_generator.rb', line 12 def generate_models # puts ">>> generate_zipcodes:" end |