Class: Nsweb::Generators::ModelGenerator

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

Instance Attribute Summary

Attributes inherited from Base

#plugin_name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

banner, source_root

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.timestamped_migrations
    Time.now.utc.strftime( '%Y%m%d%H%M%S' )
  else
    "#.3d" % (current_migration_number(dirname) + 1)
  end
end

Instance Method Details

#create_migrationObject



28
29
30
31
32
# File 'lib/generators/nsweb/model/model_generator.rb', line 28

def create_migration
  unless options.skip_migration?
    migration_template 'migration.rb', "db/migrate/create_#{table_name}.rb"
  end
end

#create_modelObject



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