Class: AskIt::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/ask_it/install_generator.rb

Instance Method Summary collapse

Instance Method Details

#copy_migrationObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/generators/ask_it/install_generator.rb', line 8

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|
    next if already_exists?(migration_file[:new_file_name])

    template "#{migration_file[:origin_file_name]}.rb.tt",
             "db/migrate/#{timestamp_number}_#{migration_file[:new_file_name]}.rb"
    timestamp_number += 1
  end
end

#migration_versionObject



33
34
35
36
37
38
39
# File 'lib/generators/ask_it/install_generator.rb', line 33

def migration_version
  return unless rails5_and_up?

  puts(Rails::VERSION)

  "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
end

#rails5_and_up?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/generators/ask_it/install_generator.rb', line 41

def rails5_and_up?
  Rails::VERSION::MAJOR >= 5
end