Class: Rdcms::Generators::InstallGenerator

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



101
102
103
# File 'lib/generators/rdcms/install_generator.rb', line 101

def self.source_root
  File.expand_path("../templates", __FILE__)
end

Instance Method Details

#copy_initializerObject



73
74
75
76
# File 'lib/generators/rdcms/install_generator.rb', line 73

def copy_initializer
  @underscored_user_name = "user".underscore
  template '../templates/active_admin.rb.erb', 'config/initializers/active_admin.rb'
end

#create_admin_user_passwordObject



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/generators/rdcms/install_generator.rb', line 137

def create_admin_user_password
  @admin_email = ask("Please enter a email for your admin account (default: [email protected]):")
  @admin_email = "[email protected]" if @admin_email.blank?

  @admin_password = ask("Please enter a new password for admin account (user: #{@admin_email}):")
  template '../templates/seeds.rb.erb', "db/seeds.rb"
  if yes?("Would you like to create your local db?")
    system("bundle install")
    rake("db:create")
  end
  rake("rdcms:install:migrations")
  if yes?("Would you like to migrate your local db?")
    rake("db:migrate")
  end
  if yes?("Would you like to seed your local db?")
    rake("db:seed")
  end
end

#install_assetsObject



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

def install_assets
  require 'rails'
  require 'active_admin'
  remove_file "app/assets/stylesheets/application.css"
  directory "../templates/assets", "app/assets"
  directory "../templates/views", "app/views"
  template '../templates/extend_posts_controller.rb', 'app/controllers/extend_posts_controller.rb'
  remove_file "public/index.html"
end

#install_capistranoObject



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/generators/rdcms/install_generator.rb', line 156

def install_capistrano
  if yes?("Would you like to configure git?")
    @git_url = ask("What is your git url? (bsp: ssh://[email protected]:requestdev/website.git)")
    git :init
    git :remote => "add origin #{@git_url}"
    git :add => "."
    git :commit => "-m 'First commit'"
    git :push => "origin master"
  end
  if yes?("Would you like to configure capistrano? (a git repository is required)")
    @ip_address = ask("To which IP do you want to deploy? (bsp: Taurus 178.23.121.27)")
    if @git_url.blank?
      @git_url = ask("What is your git url? (bsp: ssh://[email protected]:7999/KLIMA/website.git)")
    end
    @app_name = Rails.application.class.parent_name.parameterize.underscore
    capify!
    remove_file "config/deploy.rb"
    template '../templates/deploy.rb.erb', 'config/deploy.rb'

    #Add Changes to git
    git :add => "."
    git :commit => "-m 'Deploy files added'"
    git :push => "origin master"
  end
  if yes?("Would you like to configure your server and deploy to it?")
    copy_file '../templates/create_database.mysql.erb', 'config/templates/create_database.mysql.erb'
    copy_file '../templates/database.yml.erb', 'config/templates/database.yml.erb'
    template '../templates/apache.tmpl.erb', "config/templates/#{@app_name}"
    system("bundle install")

    #Add Changes to git
    git :add => "."
    git :commit => "-m 'Server configuration files added'"
    git :push => "origin master"

    system("cap deploy:create_gemset")
    system("cap deploy:setup")
    if yes?("Would you like to create remote database?")
      system("cap deploy:db:setup")
    end
    system("cap deploy")
    if yes?("Would you like to seed your remote db?")
      system("cap deploy:seed")
    end
    if yes?("Would you like to configure apache on your server?")
      system("cap deploy:apache_setup")
    end
  end
end

#install_errbitObject



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/generators/rdcms/install_generator.rb', line 111

def install_errbit
  if yes?("Would you like to configure Errbit?")
    gem("airbrake")
    system("bundle install")
    @api_key = ask("What is your Errbit API key? (default: 1eacfe13fb5d9eca2dee5401a9b93ddb)")
    @api_key = "1eacfe13fb5d9eca2dee5401a9b93ddb" if @api_key.blank?

    @host = ask("What is your Errbit Host? (default: error.requestdev.com.br)")
    @host = "error.requestdev.com.br" if @host.blank?

    @port = ask("What is your Errbit Port? (bsp: 80 default | 443 secure )")
    @port = "80" if @port.blank?
    template '../templates/errbit.rb.erb', 'config/initializers/errbit.rb'
  end
end

#install_gemsObject



60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/generators/rdcms/install_generator.rb', line 60

def install_gems
  gem('acts-as-taggable-on', :git => 'git://github.com/mbleigh/acts-as-taggable-on')
  gem('meta-tags', :git => 'git://github.com/jazzgumpy/meta-tags.git')
  gem('compass-960-plugin')
  gem('progress_bar')
  gem('compass-rails')
  gem('mysql2', :group => "development, test")
  gem('pg', :group => "production")
  gem('unicorn', :group => "production, staging")
  gem('thin', :group => "production", :platform => :ruby)
  system("bundle install")
end

#install_local_rvmObject



11
12
13
14
15
16
17
18
# File 'lib/generators/rdcms/install_generator.rb', line 11

def install_local_rvm
  if yes?("Would you like to configure a .rvmrc file?")
    @ruby_version = ask("What is your current ruby version (default: 1.9.3p374)")
    @ruby_version = "1.9.3p374" if @ruby_version.blank?
    template '../templates/rvmrc.erb', '.rvmrc'
    system("/bin/bash -ce '[[ -s \"$HOME/.rvm/scripts/rvm\" ]] && source \"$HOME/.rvm/scripts/rvm\" && rvm use #{@ruby_version}@#{Rails.application.class.parent_name} --create'")
  end
end

#install_newrelicObject



127
128
129
130
131
132
133
134
135
# File 'lib/generators/rdcms/install_generator.rb', line 127

def install_newrelic
  if yes?("Would you like to install NewRelic? (www.newrelic.com)")
    gem("newrelic_rpm", "3.5.5.38")
    system("bundle install")
    @license_key = ask("What is your NewRelic license key? (default: b199ad3e4e0d728b1aac69aec4870af7ef9478bb)")
    @license_key = "b199ad3e4e0d728b1aac69aec4870af7ef9478bb" if @license_key.blank?
    template '../templates/newrelic.yml.erb', 'config/newrelic.yml'
  end
end

#install_optional_assetsObject



105
106
107
108
109
# File 'lib/generators/rdcms/install_generator.rb', line 105

def install_optional_assets
  gem("better_errors", :group => "development")
  gem("binding_of_caller", :group => "development")
  system("bundle install")
end

#install_test_envObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/generators/rdcms/install_generator.rb', line 20

def install_test_env
  if yes?("Would you like to install a test Environment")
    gem("rspec-rails", '~> 2.12.2', :group => "test")
    gem("annotate", :group => "test")
    gem("ruby-graphviz", :group => "test")
    gem("mysql2", :group => "test")
    gem("cucumber", :group => "test")
    gem("cucumber-rails", :group => "test", :require => false)
    gem("factory_girl", :group => "test")
    gem("factory_girl_rails", :group => "test")
    gem("database_cleaner", :group => "test")
    gem("capybara", :group => "test")
    gem("capybara-webkit", :group => "test")
    gem("guard", :group => "test")
    gem("guard-rspec", :group => "test")
    gem("guard-cucumber", :group => "test")
    gem("guard-livereload", :group => "test")
    gem("rb-fsevent", '~> 0.9.1', :group => "test")
    gem("growl", :group => "test")
    gem("launchy", :group => "test")
    gem("faker", :group => "test")
    gem("email_spec", :group => "test")
    gem("shoulda-matchers", :group => "test")
  end
end

#modify_application_rbObject



53
54
55
56
57
58
# File 'lib/generators/rdcms/install_generator.rb', line 53

def modify_application_rb
  line = "config.active_record.whitelist_attributes = true"
  gsub_file 'config/application.rb', /(#{Regexp.escape(line)})/mi do |match|
    "config.active_record.whitelist_attributes = false"
  end
end

#modify_production_envObject



46
47
48
49
50
51
# File 'lib/generators/rdcms/install_generator.rb', line 46

def modify_production_env
  line = "config.assets.compile = false"
  gsub_file 'config/environments/production.rb', /(#{Regexp.escape(line)})/mi do |match|
    "config.assets.compile = true"
  end
end

#setup_routesObject



88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/generators/rdcms/install_generator.rb', line 88

def setup_routes
  route "# Editor de texto Online"
  route "mount Ckeditor::Engine => '/ckeditor'"

  route "# Administracion"
  route "devise_for :users, ActiveAdmin::Devise.config"
  # route "devise_for :visitors"
  route "match '/admin/edit_page/:id' =>  'admin/publications#edit_page', :as => :admin_edit_page_publication"

  route "ActiveAdmin.routes(self)"
  route "mount Rdcms::Engine => '/'"
end