Class: Surveyor::InstallGenerator

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

Constant Summary collapse

MIGRATION_ORDER =
%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

Methods included from Helpers::AssetPipeline

#asset_pipeline_enabled?

Instance Method Details

#assetsObject



76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/generators/surveyor/install_generator.rb', line 76

def assets
  if asset_pipeline_enabled?
    directory "app/assets"
    copy_file "vendor/assets/stylesheets/custom.sass"
  else
    directory "../../../assets/javascripts", "public/javascripts"
    directory "../../../assets/images", "public/images"
    directory "../../../assets/stylesheets/surveyor", "public/stylesheets/surveyor"
    copy_file "../../../assets/stylesheets/surveyor.sass", "public/stylesheets/sass/surveyor.sass"
    copy_file "vendor/assets/stylesheets/custom.sass", "public/stylesheets/sass/custom.sass"
  end
end

#localesObject



97
98
99
# File 'lib/generators/surveyor/install_generator.rb', line 97

def locales
  directory "config/locales"
end

#migrationsObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/generators/surveyor/install_generator.rb', line 48

def migrations
  unless options[:skip_migrations]
    migration_files = Dir[File.join(self.class.source_root, 'db/migrate/*.rb')]
    migrations_not_in_order =
      migration_files.collect { |f| File.basename(f).sub(/\.rb$/, '') } - MIGRATION_ORDER
    unless migrations_not_in_order.empty?
      fail "%s migration%s not added to MIGRATION_ORDER: %s" % [
        migrations_not_in_order.size,
        migrations_not_in_order.size == 1 ? '' : 's',
        migrations_not_in_order.join(', ')
      ]
    end

    # because all migration timestamps end up the same, causing a collision when running rake db:migrate
    # copied functionality from RAILS_GEM_PATH/lib/rails_generator/commands.rb
    MIGRATION_ORDER.each_with_index do |model, i|
      unless (prev_migrations = Dir.glob("db/migrate/[0-9]*_*.rb").grep(/[0-9]+_#{model}.rb$/)).empty?
        prev_migration_timestamp = prev_migrations[0].match(/([0-9]+)_#{model}.rb$/)[1]
      end
      copy_file("db/migrate/#{model}.rb", "db/migrate/#{(prev_migration_timestamp || Time.now.utc.strftime("%Y%m%d%H%M%S").to_i + i).to_s}_#{model}.rb")
    end
  end
end

#readmeObject



45
46
47
# File 'lib/generators/surveyor/install_generator.rb', line 45

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

#routesObject



72
73
74
# File 'lib/generators/surveyor/install_generator.rb', line 72

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

#surveysObject



89
90
91
92
93
94
95
# File 'lib/generators/surveyor/install_generator.rb', line 89

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