commands/rhoconnect/config.rb in rhoconnect-3.4.5 vs commands/rhoconnect/config.rb in rhoconnect-4.0.0.beta.10
- old
+ new
@@ -1,20 +1,32 @@
Execute.define_task do
desc "config", "Config", :hide => true
- def config
- $settings = load_settings(File.join('settings','settings.yml'))
- $env = (ENV['RHO_ENV'] || ENV['RACK_ENV'] || :development).to_sym
-
- uri = URI.parse($settings[$env][:syncserver])
- $url = "#{uri.scheme}://#{uri.host}"
- $url = "#{$url}:#{uri.port}" if uri.port && uri.port != 80
- $host = uri.host
- $port = uri.port
- $appname = $settings[$env][:syncserver].split('/').last
- $token_file = File.join(ENV['HOME'],'.rhoconnect_token')
- $token = File.read($token_file) if File.exist?($token_file)
- # Redis options
- redis_server = $settings[$env][:redis]
- host, port, db, password = redis_server.split(':')
- $redis_options = { :host => host, :port => port, :db => db, :password => password }
+ def config(settings_file=false)
+ if File.exist?(File.join('settings','settings.yml'))
+ settings = load_settings(File.join('settings','settings.yml'))
+ rackup_config = "config.ru"
+ elsif settings_file
+ settings = load_settings(settings_file)
+ rackup_config = File.join(File.dirname(__FILE__), '..', 'utilities', 'blank_app.ru')
+ elsif File.exist?(File.join(ENV['HOME'], '.rhoconnect.yml'))
+ settings = load_settings(File.join(ENV['HOME'], '.rhoconnect.yml'))
+ rackup_config = File.join(File.dirname(__FILE__), '..', 'utilities', 'blank_app.ru')
+ else
+ options = { :syncserver => "http://localhost:#{RHOCONNECT_PORT}",
+ :redis => REDIS_SERVER_URL, :push_server => PUSH_SERVER_URL, :api_token => API_TOKEN }
+ settings = { :development => options, :test => options, :production => options }
+ rackup_config = File.join(File.dirname(__FILE__), '..', 'utilities', 'blank_app.ru')
+ end
+ settings = settings[Rhoconnect.environment]
+ # syncserver settings
+ uri = URI.parse(settings[:syncserver])
+ port = uri.port unless port
+ url = "#{uri.scheme}://#{uri.host}:#{port}"
+ settings[:syncserver] = url
+ settings[:rackup] = rackup_config
+ # redis settings
+ redis_conf = settings[:redis]
+ settings[:redis] = [redis_conf] if redis_conf.is_a?(String)
+
+ settings
end
end