class BootswatchRails::Generators::CreatedByGenerator
Public Instance Methods
add_helper()
click to toggle source
# File lib/generators/bootswatch_rails/created_by/created_by_generator.rb, line 19 def add_helper return unless options.init? template "created_by_helper.rb", "app/helpers/created_by_helper.rb" end
add_migration()
click to toggle source
# File lib/generators/bootswatch_rails/created_by/created_by_generator.rb, line 24 def add_migration return unless options.migration? migration_template 'created_by_migration.rb', "db/migrate/#{migration_name}.rb" end
update_controller()
click to toggle source
# File lib/generators/bootswatch_rails/created_by/created_by_generator.rb, line 29 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
Protected Instance Methods
migration_name()
click to toggle source
# File lib/generators/bootswatch_rails/created_by/created_by_generator.rb, line 43 def migration_name "add_created_by_to_#{table_name}" end