Class: AddressByCep::ModelGenerator

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

banner

Constructor Details

#initialize(*args, &block) ⇒ ModelGenerator

Returns a new instance of ModelGenerator.



7
8
9
# File 'lib/generators/address_by_cep/model_generator.rb', line 7

def initialize(*args, &block)
  super
end

Class Method Details

.next_migration_number(dirname) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/generators/address_by_cep/model_generator.rb', line 23

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_js_in_application_jsObject



15
16
17
# File 'lib/generators/address_by_cep/model_generator.rb', line 15

def add_js_in_application_js
  add_js_reference
end

#create_migrationObject



31
32
33
# File 'lib/generators/address_by_cep/model_generator.rb', line 31

def create_migration
  migration_template 'migration.rb', "db/migrate/create_table_addresses.rb"
end

#create_modelObject



19
20
21
# File 'lib/generators/address_by_cep/model_generator.rb', line 19

def create_model
  template 'address_model.rb', "app/models/address.rb"
end

#create_partialObject



11
12
13
# File 'lib/generators/address_by_cep/model_generator.rb', line 11

def create_partial
  copy_file 'partial_addressable_form.html.erb', "app/views/addresses/_addressable_form.html.erb"
end