Class: Localeapp::CLI::Install::HerokuInstaller

Inherits:
DefaultInstaller show all
Defined in:
lib/localeapp/cli/install.rb

Instance Attribute Summary

Attributes inherited from DefaultInstaller

#config_file_path, #data_directory, #key, #project_data

Instance Method Summary collapse

Methods inherited from DefaultInstaller

#check_data_directory_exists, #check_key, #execute, #initialize, #print_default_locale, #print_header, #set_config_paths, #write_config_file

Constructor Details

This class inherits a constructor from Localeapp::CLI::Install::DefaultInstaller

Instance Method Details

#get_heroku_api_keyObject



142
143
144
145
146
147
148
149
150
151
152
# File 'lib/localeapp/cli/install.rb', line 142

def get_heroku_api_key
  self.key = if ENV['CUCUMBER_HEROKU_TEST_API_KEY']
    ENV['CUCUMBER_HEROKU_TEST_API_KEY']
  elsif ENV['LOCALEAPP_API_KEY']
    ENV['LOCALEAPP_API_KEY']
  elsif File.exist?('.env') && IO.read('.env') =~ /^LOCALEAPP_API_KEY=(\w+)$/
    $1
  else
    nil
  end
end

#validate_keyObject



128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/localeapp/cli/install.rb', line 128

def validate_key
  @output.puts "Getting API key from heroku config"
  get_heroku_api_key
  if key.nil?
    @output.puts "ERROR: No api key found in heroku config, have you installed the localeapp addon?"
    return
  else
    @output.puts "Add the following line to your .env file for Foreman"
    @output.puts "LOCALEAPP_API_KEY=#{key}"
    @output.puts '^' * 80
  end
  super
end

#write_rails_configObject



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/localeapp/cli/install.rb', line 154

def write_rails_config
  File.open(config_file_path, 'w+') do |file|
    file.write <<-CONTENT
require 'localeapp/rails'

Localeapp.configure do |config|
  config.api_key = ENV['LOCALEAPP_API_KEY']
  config.environment_name = ENV['LOCALEAPP_ENV'] unless ENV['LOCALEAPP_ENV'].nil?
  config.polling_environments = [:development, :staging]
  config.reloading_environments = [:development, :staging]
  config.sending_environments = [:development, :staging]
end

# Pull latest when dyno restarts on staging
if defined?(Rails) && Rails.env.staging?
  Localeapp::CLI::Pull.new.execute
end
CONTENT
  end
end