Class: Goldencobra::Generators::InstallGenerator

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



92
93
94
# File 'lib/generators/goldencobra/install_generator.rb', line 92

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

Instance Method Details

#copy_initializerObject



68
69
70
71
# File 'lib/generators/goldencobra/install_generator.rb', line 68

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

#create_admin_user_passwordObject



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/generators/goldencobra/install_generator.rb', line 120

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("goldencobra: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



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/generators/goldencobra/install_generator.rb', line 73

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_goldencobra_articles_controller.rb",
           "app/controllers/extend_goldencobra_articles_controller.rb"
  remove_file "public/index.html"
  copy_file "../templates/robots.txt", "public/robots.txt"
end

#install_capistranoObject



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
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
# File 'lib/generators/goldencobra/install_generator.rb', line 139

def install_capistrano
  if yes?("Would you like to configure git?")
    @git_url = ask("What is your git url? (bsp: ssh://[email protected]:7999/KLIMA/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



96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/generators/goldencobra/install_generator.rb', line 96

def install_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: errors.ikusei.de)")
    @host = "errors.ikusei.de" 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

#install_local_rvmObject



11
12
13
14
15
16
17
18
# File 'lib/generators/goldencobra/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.3-p194)")
    @ruby_version = "1.9.3-p194" 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



110
111
112
113
114
115
116
117
118
# File 'lib/generators/goldencobra/install_generator.rb', line 110

def install_newrelic
  if yes?("Would you like to install NewRelic? (www.newrelic.com)")
    gem("newrelic_rpm", "3.18.1.330")
    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_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
45
# File 'lib/generators/goldencobra/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")
    system("bundle install")
  end
end

#modify_application_rbObject



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/generators/goldencobra/install_generator.rb', line 54

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

  line = "class Application < Rails::Application"
  gsub_file "config/environments/production.rb", /(#{Regexp.escape(line)})/mi do |match|
    "class Application < Rails::Application"
    "  require 'pdfkit'"
    "  config.middleware.use PDFKit::Middleware, print_media_type: true"
  end
end

#modify_production_envObject



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

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



85
86
87
88
89
90
# File 'lib/generators/goldencobra/install_generator.rb', line 85

def setup_routes
  route "mount Goldencobra::Engine => '/'"
  route "devise_for :users, ActiveAdmin::Devise.config"
  route "devise_for :visitors"
  route "ActiveAdmin.routes(self)"
end