Class: Trackman::Utility::Configuration
- Inherits:
-
Object
- Object
- Trackman::Utility::Configuration
- Defined in:
- lib/trackman/utility/configuration.rb
Constant Summary collapse
- @@ERROR =
'ERROR_PAGE_URL'
- @@MAINTENANCE =
'MAINTENANCE_PAGE_URL'
- @@TRACKMAN_ERROR =
'TRACKMAN_ERROR_PAGE_URL'
- @@TRACKMAN_MAINTENANCE =
'TRACKMAN_MAINTENANCE_PAGE_URL'
Instance Attribute Summary collapse
-
#configs ⇒ Object
Returns the value of attribute configs.
-
#heroku_version ⇒ Object
Returns the value of attribute heroku_version.
-
#options ⇒ Object
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #add_configs ⇒ Object
- #get_configs ⇒ Object
- #get_version ⇒ Object
-
#initialize(options = {}) ⇒ Configuration
constructor
A new instance of Configuration.
- #rename_configs ⇒ Object
- #setup ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Configuration
Returns a new instance of Configuration.
13 14 15 16 17 |
# File 'lib/trackman/utility/configuration.rb', line 13 def initialize( = {}) self. = self.heroku_version = get_version self.configs = get_configs end |
Instance Attribute Details
#configs ⇒ Object
Returns the value of attribute configs.
11 12 13 |
# File 'lib/trackman/utility/configuration.rb', line 11 def configs @configs end |
#heroku_version ⇒ Object
Returns the value of attribute heroku_version.
11 12 13 |
# File 'lib/trackman/utility/configuration.rb', line 11 def heroku_version @heroku_version end |
#options ⇒ Object
Returns the value of attribute options.
11 12 13 |
# File 'lib/trackman/utility/configuration.rb', line 11 def @options end |
Class Method Details
.h_to_s(configs) ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/trackman/utility/configuration.rb', line 81 def self.h_to_s configs out = [] configs.each do |k,v| out << k + "=" + v end out.join ' ' end |
.s_to_h(configs) ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'lib/trackman/utility/configuration.rb', line 72 def self.s_to_h configs new_configs = {} configs.split(" ").each do |a| key_val = a.split("=") new_configs[key_val[0]] = key_val[1] end new_configs end |
Instance Method Details
#add_configs ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/trackman/utility/configuration.rb', line 45 def add_configs if configs.include?(@@TRACKMAN_ERROR) && configs.include?(@@TRACKMAN_MAINTENANCE) trackman_configs = {} [[@@TRACKMAN_ERROR, @@ERROR], [@@TRACKMAN_MAINTENANCE, @@MAINTENANCE]].each do |old_c, new_c| trackman_configs[new_c] = configs[old_c] end add = trackman_configs.map{|k,v| "#{k}=#{v}" }.join(' ') add_config add else raise Trackman::Errors::ConfigSetupError, "cannot find trackman configuration, make sure trackman addon is installed" end end |
#get_configs ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/trackman/utility/configuration.rb', line 35 def get_configs Bundler.with_clean_env do result = run "heroku config -s" do |option| "heroku config -s #{option}" end self.class.s_to_h(result) end end |
#get_version ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/trackman/utility/configuration.rb', line 25 def get_version Bundler.with_clean_env do which_result = `which heroku` raise 'Could not find heroku toolbelt or gem. Make sure you installed one of them.' unless which_result && which_result.length > 0 heroku_version = `heroku --version` heroku_version.match(/heroku-.*(\d+\.?\d+\.?\d+).*\(/)[1] end end |
#rename_configs ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/trackman/utility/configuration.rb', line 59 def rename_configs bkp = {} [@@ERROR, @@MAINTENANCE].each do |c| bkp[c] = configs[c] if configs.include? c end add = Hash[bkp.map {|k, v| [k + "_bkp", v] }].map{|k,v| "#{k}=#{v}" }.select{|c| !configs.include? c }.join(' ') unless add.empty? add_config add end end |
#setup ⇒ Object
19 20 21 22 23 |
# File 'lib/trackman/utility/configuration.rb', line 19 def setup raise Trackman::Errors::ConfigSetupError, "Your heroku version is too low, trackman requires '~> 2.26'." unless is_heroku_valid rename_configs add_configs end |