Class: Bumbleworks::Rails::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Bumbleworks::Rails::InstallGenerator
- Defined in:
- lib/generators/bumbleworks/rails/install/install_generator.rb
Constant Summary collapse
- STORAGE_TYPES =
['Sequel', 'Redis', 'Hash']
- STORAGE_CONFIG_PATH =
"config/bumbleworks_storage.yml"
- SEQUEL_TABLE_NAME =
"bumbleworks_documents"
- QUESTIONS =
{ :which_storage => "Which storage will you be using?", :storage_config_path => "Where do you want your storage configuration file to live?", :sequel_table_name => "What database table name do you want Bumbleworks to use?" }
Instance Attribute Summary collapse
-
#storage_config_path ⇒ Object
readonly
Returns the value of attribute storage_config_path.
-
#storage_options ⇒ Object
readonly
Returns the value of attribute storage_options.
-
#storage_type ⇒ Object
readonly
Returns the value of attribute storage_type.
Instance Method Summary collapse
- #add_routes ⇒ Object
- #add_storage_gem_to_gemfile ⇒ Object
- #add_task_helper_to_application_controller ⇒ Object
- #ask_for_table_name ⇒ Object
- #check_storage_type ⇒ Object
- #copy_bumbleworks_directory ⇒ Object
- #copy_initializer ⇒ Object
- #copy_locale ⇒ Object
- #copy_storage_config_file ⇒ Object
- #farewell ⇒ Object
- #introduction ⇒ Object
Instance Attribute Details
#storage_config_path ⇒ Object (readonly)
Returns the value of attribute storage_config_path.
7 8 9 |
# File 'lib/generators/bumbleworks/rails/install/install_generator.rb', line 7 def storage_config_path @storage_config_path end |
#storage_options ⇒ Object (readonly)
Returns the value of attribute storage_options.
7 8 9 |
# File 'lib/generators/bumbleworks/rails/install/install_generator.rb', line 7 def @storage_options end |
#storage_type ⇒ Object (readonly)
Returns the value of attribute storage_type.
7 8 9 |
# File 'lib/generators/bumbleworks/rails/install/install_generator.rb', line 7 def storage_type @storage_type end |
Instance Method Details
#add_routes ⇒ Object
93 94 95 96 97 98 99 100 |
# File 'lib/generators/bumbleworks/rails/install/install_generator.rb', line 93 def add_routes insert_into_file 'config/routes.rb', :after => /\.routes\.draw do\s*$/ do File.read(find_in_source_paths('config/routes.rb')) end prepend_file 'config/routes.rb' do "require 'bumbleworks/gui'\n\n" end end |
#add_storage_gem_to_gemfile ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/generators/bumbleworks/rails/install/install_generator.rb', line 50 def add_storage_gem_to_gemfile unless storage_type == 'hash' create_file 'Gemfile', :skip => true add_source 'https://rubygems.org' gem "bumbleworks-#{storage_type}" end end |
#add_task_helper_to_application_controller ⇒ Object
102 103 104 105 106 107 108 109 |
# File 'lib/generators/bumbleworks/rails/install/install_generator.rb', line 102 def add_task_helper_to_application_controller insert_into_file 'app/controllers/application_controller.rb', :after => "protect_from_forgery with: :exception\n" do <<-RUBY helper Bumbleworks::Rails::TasksHelper RUBY end end |
#ask_for_table_name ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/generators/bumbleworks/rails/install/install_generator.rb', line 58 def ask_for_table_name if storage_type == 'sequel' unless @table_name = [:table_name] @table_name = ask("#{QUESTIONS[:sequel_table_name]} [#{SEQUEL_TABLE_NAME}]") @table_name = SEQUEL_TABLE_NAME if @table_name.blank? end @storage_options = { 'sequel_table_name' => [:table_name] } end end |
#check_storage_type ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/generators/bumbleworks/rails/install/install_generator.rb', line 38 def check_storage_type @storage_type = if [:storage_type] unless STORAGE_TYPES.include?([:storage_type]) say "Storage type specified must be one of: #{STORAGE_TYPES.join(', ')}" exit 1 end [:storage_type].underscore else ask(QUESTIONS[:which_storage], :limited_to => STORAGE_TYPES).underscore end end |
#copy_bumbleworks_directory ⇒ Object
84 85 86 |
# File 'lib/generators/bumbleworks/rails/install/install_generator.rb', line 84 def copy_bumbleworks_directory directory 'lib' end |
#copy_initializer ⇒ Object
79 80 81 82 |
# File 'lib/generators/bumbleworks/rails/install/install_generator.rb', line 79 def copy_initializer template 'config/initializers/bumbleworks.rb', 'config/initializers/bumbleworks.rb' end |
#copy_locale ⇒ Object
88 89 90 91 |
# File 'lib/generators/bumbleworks/rails/install/install_generator.rb', line 88 def copy_locale copy_file "config/locales/bumbleworks.en.yml", "config/locales/bumbleworks.en.yml" end |
#copy_storage_config_file ⇒ Object
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/generators/bumbleworks/rails/install/install_generator.rb', line 68 def copy_storage_config_file unless storage_type == 'hash' unless @storage_config_path = [:storage_config_path] @storage_config_path = ask("#{QUESTIONS[:storage_config_path]} [#{STORAGE_CONFIG_PATH}]") @storage_config_path = STORAGE_CONFIG_PATH if @storage_config_path.blank? end template "config/storages/#{storage_type}.yml", storage_config_path end end |
#farewell ⇒ Object
111 112 113 114 115 116 117 118 |
# File 'lib/generators/bumbleworks/rails/install/install_generator.rb', line 111 def farewell say <<-FAREWELL We're done! Remember to run `rake bumbleworks:bootstrap` whenever you change process definitions or participant registration. Enjoy using bumbleworks! FAREWELL end |
#introduction ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/generators/bumbleworks/rails/install/install_generator.rb', line 30 def introduction say <<-INTRODUCTION Let's install Bumbleworks into your Rails app! INTRODUCTION end |