Class: Nsweb::Generators::ModelGenerator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/generators/nsweb/model/model_generator.rb
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
Instance Method Summary collapse
- #create_migration ⇒ Object
- #create_model ⇒ Object
-
#initialize(*args, &block) ⇒ ModelGenerator
constructor
A new instance of ModelGenerator.
Methods inherited from Base
Constructor Details
#initialize(*args, &block) ⇒ ModelGenerator
Returns a new instance of ModelGenerator.
12 13 14 15 16 17 18 |
# File 'lib/generators/nsweb/model/model_generator.rb', line 12 def initialize(*args, &block) super @model_attributes = [] attributes.each do |attr| @model_attributes << Rails::Generators::GeneratedAttribute.new(*attr.split(':')) end end |
Class Method Details
.next_migration_number(dirname) ⇒ Object
:nodoc:
34 35 36 37 38 39 40 |
# File 'lib/generators/nsweb/model/model_generator.rb', line 34 def self.next_migration_number(dirname) #:nodoc: 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
#create_migration ⇒ Object
28 29 30 31 32 |
# File 'lib/generators/nsweb/model/model_generator.rb', line 28 def create_migration unless .skip_migration? migration_template 'migration.rb', "db/migrate/create_#{table_name}.rb" end end |
#create_model ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/generators/nsweb/model/model_generator.rb', line 20 def create_model template 'model.rb', File.join(plugin_path, 'app/models', "#{file_path}.rb") if test_framework == :rspec template 'tests/rspec/model.rb', File.join('spec', plugin_path, 'models', "#{file_path}_spec.rb") end end |