Class: Vitrage::Generators::PieceGenerator

Inherits:
ActiveRecord::Generators::ModelGenerator
  • Object
show all
Defined in:
lib/generators/vitrage/piece_generator.rb

Instance Method Summary collapse

Instance Method Details

#class_nameObject



12
13
14
15
# File 'lib/generators/vitrage/piece_generator.rb', line 12

def class_name
  clsn = super
  clsn[0..3] == "Vtrg" ? clsn : "Vtrg#{clsn}"
end

#create_migration_fileObject

override ActiveRecord::Generators::ModelGenerator method



28
29
30
31
32
# File 'lib/generators/vitrage/piece_generator.rb', line 28

def create_migration_file
  return unless options[:migration] && options[:parent].nil?
  attributes.each { |a| a.attr_options.delete(:index) if a.reference? && !a.has_index? } if options[:indexes] == false
  migration_template "migrations/create_vitrage_piece.rb", "db/migrate/create_#{table_name}.rb"
end

#create_model_fileObject

override ActiveRecord::Generators::ModelGenerator method



35
36
37
# File 'lib/generators/vitrage/piece_generator.rb', line 35

def create_model_file
  template 'vitrage_piece.rb', File.join('app/models/vitrage_pieces/', class_path, "#{file_name}.rb")
end

#create_necessary_viewsObject



39
40
41
42
# File 'lib/generators/vitrage/piece_generator.rb', line 39

def create_necessary_views
  copy_file 'views/piece_show_generator.html.erb', File.join('app/views/vitrage/', "_#{file_name}.html.erb")
  copy_file 'views/piece_form_generator.html.erb', File.join('app/views/vitrage/', "_#{file_name}_form.html.erb")
end

#file_nameObject



17
18
19
20
# File 'lib/generators/vitrage/piece_generator.rb', line 17

def file_name
  flen = super
  flen[0..4] == "vtrg_" ? flen : "vtrg_#{flen}"
end

#table_nameObject



22
23
24
25
# File 'lib/generators/vitrage/piece_generator.rb', line 22

def table_name
  tbns = super
  tbns[0..4] == "vtrg_" ? tbns : "vtrg_#{tbns}"
end