Class: Goldencobra::Generators::ArticletypeGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/goldencobra/articletype/articletype_generator.rb

Instance Method Summary collapse

Instance Method Details

#create_articletype_filesObject



7
8
9
10
# File 'lib/generators/goldencobra/articletype/articletype_generator.rb', line 7

def create_articletype_files
  #TODO: Check if class name already exists and abort if true
  generate('model', "#{name} #{model_attributes.join(' ')} article_id:integer")
end

#create_partialsObject



12
13
14
15
16
17
18
19
20
# File 'lib/generators/goldencobra/articletype/articletype_generator.rb', line 12

def create_partials
  #TODO: Check if class name already exists and abort if true
  copy_file 'index.html.erb', "app/views/articletypes/#{name.underscore}/_index.html.erb"
  copy_file 'show.html.erb', "app/views/articletypes/#{name.underscore}/_show.html.erb"
  template 'edit_show.html.erb', "app/views/articletypes/#{name.underscore}/_edit_show.html.erb"
  copy_file 'edit_articletype.html.erb', "app/views/articletypes/#{name.underscore}/_edit_articletype.html.erb"
  copy_file 'edit_index.html.erb', "app/views/articletypes/#{name.underscore}/_edit_index.html.erb"
  template 'initializer.rb', "config/initializers/goldencobra_#{name.underscore}.rb"
end

#updates_modelObject



22
23
24
25
26
# File 'lib/generators/goldencobra/articletype/articletype_generator.rb', line 22

def updates_model
  inject_into_class "app/models/#{name.underscore}.rb", name.constantize do
    "belongs_to :article, class_name: Goldencobra::Article\nSortOptions = []\ndef fulltext_searchable_text\n''\nend\n"
  end
end