Class: IfdTools::InstallGenerator

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

Instance Method Summary collapse

Instance Method Details

#add_gemsObject



9
10
11
12
13
14
# File 'lib/generators/ifd_tools/install/install_generator.rb', line 9

def add_gems
  gem "capistrano", group: :development
  gem "rvm-capistrano", group: :development
  gem 'foreman', group: :development
  gem 'thin'
end

#add_to_gitignoreObject



141
142
143
144
145
146
# File 'lib/generators/ifd_tools/install/install_generator.rb', line 141

def add_to_gitignore
  append_to_file "#{Rails.root}/.gitignore", <<-GITIGNORE
  .DS_Store
  /config/database.yml
  GITIGNORE
end

#cleanup_assetsObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/generators/ifd_tools/install/install_generator.rb', line 35

def cleanup_assets

  remove_file "#{Rails.root}/app/assets/stylesheets/active_admin.css.scss", verbose: false
  template "assets/active_admin.css.scss", "#{Rails.root}/app/assets/stylesheets/active_admin.css.scss"
  
  remove_file "#{Rails.root}/app/assets/stylesheets/application.css", verbose: false
  template "assets/application.css.scss", "#{Rails.root}/app/assets/stylesheets/application.css.scss"
  
  
  %w(active_admin.js application.js).each do |js|
    remove_file "#{Rails.root}/app/assets/javascripts/#{js}", verbose: false
    template "assets/#{js}", "#{Rails.root}/app/assets/javascripts/#{js}"
  end
  
  empty_directory "#{Rails.root}/app/assets/javascripts/ckeditor", verbose: false
  copy_file "assets/ckeditor.js.coffee", "#{Rails.root}/app/assets/javascripts/ckeditor/config.js.coffee"
  
  remove_file "#{Rails.root}/app/assets/images/rails.png"
  remove_file "#{Rails.root}/public/index.html"
  
end

#configure_devise_asyncObject



71
72
73
74
75
76
77
78
79
80
# File 'lib/generators/ifd_tools/install/install_generator.rb', line 71

def configure_devise_async
  initializer "devise_async.rb", "Devise::Async.backend = :delayed_job"
  
  devise_init = "#{Rails.root}/config/initializers/devise.rb"
  gsub_file devise_init, %r{mailer = ".*"}, %q{mailer = "Devise::Async::Proxy"}
  gsub_file devise_init, %r{mailer_sender = ".*"}, %q{mailer_sender = Settings.notifications_email}
  
  uncomment_lines devise_init, /token_authentication_key/
  uncomment_lines devise_init, /mailer = /
end

#install_controllersObject



111
112
113
# File 'lib/generators/ifd_tools/install/install_generator.rb', line 111

def install_controllers
  template "controllers/api_controller.rb", "#{Rails.root}/app/controllers/api_controller.rb"
end

#install_dashboardObject



136
137
138
139
# File 'lib/generators/ifd_tools/install/install_generator.rb', line 136

def install_dashboard
  remove_file "#{Rails.root}/app/admin/dashboard.rb", verbose: false
  template "admin/dashboard.rb", "#{Rails.root}/app/admin/dashboard.rb"
end

#install_layoutsObject



115
116
117
118
119
# File 'lib/generators/ifd_tools/install/install_generator.rb', line 115

def install_layouts
  remove_file "#{Rails.root}/app/views/layouts/application.html.erb", verbose: false
  template "layouts/application.html.haml", "#{Rails.root}/app/views/layouts/application.html.haml"
  template "layouts/application_logged_out.html.haml", "#{Rails.root}/app/views/layouts/application_logged_out.html.haml"
end

#install_migrationsObject



94
95
96
97
# File 'lib/generators/ifd_tools/install/install_generator.rb', line 94

def install_migrations
  Dir["#{Rails.root}/db/migrate/*.rb"].select { |f| f.end_with? "create_users.rb" }.map { |f| File.delete f }
  rake "railties:install:migrations FROM=ifd_tools"
end

#install_our_initializerObject



132
133
134
# File 'lib/generators/ifd_tools/install/install_generator.rb', line 132

def install_our_initializer
  template "config/ifd_tools.rb", "#{Rails.root}/config/initializers/ifd_tools.rb"
end

#install_settingslogicObject



88
89
90
91
92
# File 'lib/generators/ifd_tools/install/install_generator.rb', line 88

def install_settingslogic
  gem "settingslogic"
  template "models/settings.rb", "#{Rails.root}/app/models/settings.rb"
  template "settings/application.yml", "#{Rails.root}/config/application.yml"
end

#last_tasksObject



148
149
150
# File 'lib/generators/ifd_tools/install/install_generator.rb', line 148

def last_tasks
  rake "db:migrate"
end

#set_defaults_in_application_configObject



65
66
67
68
69
# File 'lib/generators/ifd_tools/install/install_generator.rb', line 65

def set_defaults_in_application_config
  application 'config.autoload_paths += %W(#{config.root}/lib)'
  application "config.time_zone = 'Eastern Time (US & Canada)'"
  application "config.assets.initialize_on_precompile = false"
end

#setup_active_adminObject



25
26
27
28
29
30
31
32
33
# File 'lib/generators/ifd_tools/install/install_generator.rb', line 25

def setup_active_admin
  generate "active_admin:install", "User"
  remove_file "#{Rails.root}/app/admin/user.rb", verbose: false
  remove_file "#{Rails.root}/app/models/user.rb", verbose: false
  template "models/user.rb", "#{Rails.root}/app/models/user.rb"
  application(nil, env: :production) do
    'config.assets.precompile += %w( ckeditor/config.js active_admin.css active_admin.js active_admin/print.css )'
  end
end

#setup_cancanObject



82
83
84
85
86
# File 'lib/generators/ifd_tools/install/install_generator.rb', line 82

def setup_cancan
  template "models/ability.rb", "#{Rails.root}/app/models/ability.rb"
  remove_file "#{Rails.root}/app/controllers/application_controller.rb", verbose: false
  template "controllers/application_controller.rb", "#{Rails.root}/app/controllers/application_controller.rb"
end

#setup_capistranoObject



121
122
123
124
125
126
127
128
129
130
# File 'lib/generators/ifd_tools/install/install_generator.rb', line 121

def setup_capistrano      
  template "capistrano/Capfile", "#{Rails.root}/Capfile"
  template "capistrano/deploy.rb", "#{Rails.root}/config/deploy.rb"
  
  empty_directory "#{Rails.root}/config/deploy"
  template "capistrano/deploy/staging.rb", "#{Rails.root}/config/deploy/staging.rb"
  template "capistrano/deploy/production.rb", "#{Rails.root}/config/deploy/production.rb"
  
  copy_file "#{Rails.root}/config/environments/production.rb", "#{Rails.root}/config/environments/staging.rb"
end

#setup_customersObject



99
100
101
102
103
104
105
106
107
108
109
# File 'lib/generators/ifd_tools/install/install_generator.rb', line 99

def setup_customers
  template "models/customer.rb", "#{Rails.root}/app/models/customer.rb"
  template "admin/customers.rb", "#{Rails.root}/app/admin/customers.rb"
  template "controllers/customer_session_controller.rb", "#{Rails.root}/app/controllers/customer_session_controller.rb"
  empty_directory "#{Rails.root}/app/views/admin/customers"
  template "views/customers/_form.html.haml", "#{Rails.root}/app/views/admin/customers/_form.html.haml"
  route "devise_for :customers, path: '', controllers: { sessions: 'customer_session' }"
  
  remove_file "#{Rails.root}/config/locales/en.yml", verbose: false
  template "config/en.yml", "#{Rails.root}/config/locales/en.yml"
end

#setup_delayed_jobObject



16
17
18
# File 'lib/generators/ifd_tools/install/install_generator.rb', line 16

def setup_delayed_job
  generate "delayed_job:active_record"
end

#setup_foremanObject



57
58
59
# File 'lib/generators/ifd_tools/install/install_generator.rb', line 57

def setup_foreman
  template "foreman/Procfile", "#{Rails.root}/Procfile"
end

#setup_routesObject



61
62
63
# File 'lib/generators/ifd_tools/install/install_generator.rb', line 61

def setup_routes
  route %q{match '/api/:action(.:format)', to: 'api'}
end

#setup_wheneverizeObject



20
21
22
23
# File 'lib/generators/ifd_tools/install/install_generator.rb', line 20

def setup_wheneverize
  gem 'whenever', require: false
  template "config/schedule.rb.erb", "#{Rails.root}/config/schedule.rb"
end