Class: Surveyor::InstallGenerator

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

Constant Summary collapse

SURVEYOR_MIGRATIONS =
%w(
  create_surveys
  create_survey_sections
  create_questions
  create_question_groups create_answers
  create_response_sets
  create_responses
  create_dependencies
  create_dependency_conditions
  create_validations
  create_validation_conditions
  add_display_order_to_surveys
  add_correct_answer_id_to_questions
  add_index_to_response_sets
  add_index_to_surveys
  add_unique_indicies
  add_section_id_to_responses
  add_default_value_to_answers
  add_api_ids
  add_display_type_to_answers
  add_api_id_to_question_groups
  add_api_ids_to_response_sets_and_responses
  update_blank_api_ids_on_question_group
  drop_unique_index_on_access_code_in_surveys
  add_version_to_surveys
  add_unique_index_on_access_code_and_version_in_surveys
  update_blank_versions_on_surveys
  api_ids_must_be_unique
  create_survey_translations
  add_input_mask_attributes_to_answer
)

Instance Method Summary collapse

Instance Method Details

#assetsObject



64
65
66
67
# File 'lib/generators/surveyor/install_generator.rb', line 64

def assets
  directory "app/assets"
  copy_file "vendor/assets/stylesheets/custom.sass"
end

#localesObject



77
78
79
# File 'lib/generators/surveyor/install_generator.rb', line 77

def locales
  directory "config/locales"
end

#migrationsObject



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/generators/surveyor/install_generator.rb', line 46

def migrations
  unless options[:skip_migrations]
    check_for_orphaned_migration_files

    # increment migration timestamps to prevent collisions. copied functionality from RAILS_GEM_PATH/lib/rails_generator/commands.rb
    SURVEYOR_MIGRATIONS.each_with_index do |name, i|
      unless (prev_migrations = check_for_existing_migrations(name)).empty?
        prev_migration_timestamp = prev_migrations[0].match(/([0-9]+)_#{name}.rb$/)[1]
      end
      copy_file("db/migrate/#{name}.rb", "db/migrate/#{(prev_migration_timestamp || Time.now.utc.strftime("%Y%m%d%H%M%S").to_i + i).to_s}_#{name}.rb")
    end
  end
end

#readmeObject



43
44
45
# File 'lib/generators/surveyor/install_generator.rb', line 43

def readme
  copy_file "../../../../README.md", "surveys/README.md"
end

#routesObject



60
61
62
# File 'lib/generators/surveyor/install_generator.rb', line 60

def routes
  route('mount Surveyor::Engine => "/surveys", :as => "surveyor"')
end

#surveysObject



69
70
71
72
73
74
75
# File 'lib/generators/surveyor/install_generator.rb', line 69

def surveys
  copy_file "surveys/kitchen_sink_survey.rb"
  copy_file "surveys/quiz.rb"
  copy_file "surveys/date_survey.rb"
  copy_file "surveys/languages.rb"
  directory "surveys/translations"
end