Class: HasStarGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/has_star/has_star_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_has_star_to_controllerObject



18
19
20
21
22
# File 'lib/generators/has_star/has_star_generator.rb', line 18

def add_has_star_to_controller
  with_file controller_file do |file|
    insert_into_file file, render_template('controller.erb'), after: /class .+$/
  end
end

#add_has_star_to_cssObject



30
31
32
33
34
# File 'lib/generators/has_star/has_star_generator.rb', line 30

def add_has_star_to_css
  with_file 'app/assets/stylesheets/application.css' do |file|
    insert_into_file file, " *= require has_star\n", before: ' *= require_tree'
  end
end

#add_has_star_to_modelObject



12
13
14
15
16
# File 'lib/generators/has_star/has_star_generator.rb', line 12

def add_has_star_to_model
  with_file model_file do |file|
    insert_into_file file, "\n  has_star", after: 'ActiveRecord::Base'
  end
end

#add_has_star_to_routesObject



24
25
26
27
28
# File 'lib/generators/has_star/has_star_generator.rb', line 24

def add_has_star_to_routes
  with_file 'config/routes.rb' do |file|
    insert_into_file file, "\n  has_star :#{table_name}", after: 'Rails.application.routes.draw do'
  end
end

#create_migration_fileObject



7
8
9
10
# File 'lib/generators/has_star/has_star_generator.rb', line 7

def create_migration_file
  # using Rails::Generators::Migration
  migration_template 'add_star_to.rb.erb', "db/migrate/add_star_to_#{table_name}.rb"
end