class Survey::Generators::InstallGenerator

Public Instance Methods

copy_migration() click to toggle source
# File lib/generators/survey/install_generator.rb, line 6
def copy_migration
  timestamp_number = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
  
  migration_files = [{new_file_name: "create_survey", origin_file_name: "migration"},
                     {new_file_name: "create_sections", origin_file_name: "migration_section"},
                     {new_file_name: "update_survey_tables", origin_file_name: "migration_update_survey_tables"},
                     {new_file_name: "add_types_to_questions_and_options", origin_file_name: "migration_add_types_to_questions_and_options"},
                     {new_file_name: "add_head_number_to_options_table", origin_file_name: "migration_add_head_number_to_options_table"},
                     {new_file_name: "create_predefined_values_table", origin_file_name: "migration_create_predefined_values_table"},
                     {new_file_name: "add_mandatory_to_questions_table", origin_file_name: "migration_add_mandatory_to_questions_table"}
                    ]
  
  migration_files.each do |migration_file|
    unless already_exists?(migration_file[:new_file_name])
      copy_file "#{migration_file[:origin_file_name]}.rb", "db/migrate/#{timestamp_number}_#{migration_file[:new_file_name]}.rb"
      timestamp_number += 1
    end
  end
end

Private Instance Methods

already_exists?(file_name) click to toggle source
# File lib/generators/survey/install_generator.rb, line 30
def already_exists?(file_name)
  Dir.glob("#{File.join(destination_root, File.join("db", "migrate"))}/[0-9]*_*.rb").grep(Regexp.new('\d+_' + file_name + '.rb$')).first
end