Class: BootswatchRails::Generators::CreatedByGenerator

Inherits:
ActiveRecord::Generators::Base
  • Object
show all
Defined in:
lib/generators/bootswatch_rails/created_by/created_by_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_helperObject



20
21
22
# File 'lib/generators/bootswatch_rails/created_by/created_by_generator.rb', line 20

def add_helper
  template "created_by_helper.rb", "app/helpers/created_by_helper.rb"
end

#add_migrationObject



15
16
17
18
# File 'lib/generators/bootswatch_rails/created_by/created_by_generator.rb', line 15

def add_migration
  return unless options.migration?
  migration_template 'created_by_migration.rb', "db/migrate/#{migration_name}.rb"
end

#update_controllerObject



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/generators/bootswatch_rails/created_by/created_by_generator.rb', line 24

def update_controller
  file = "app/controllers/#{table_name}_controller.rb"
  curr = "current_#{user}"
  inject_into_file file, after: /def update$/ do
    "\n    @#{name}.updated_by = #{curr} ? #{curr}.id : nil"
  end
  inject_into_file file, after: /@#{name} = #{class_name}\.new\(#{name}_params\)$/ do
    "\n    @#{name}.created_by = #{curr} ? #{curr}.id : nil" +
    "\n    @#{name}.updated_by = #{curr} ? #{curr}.id : nil"
  end
end