Module: Peas
- Defined in:
- lib/peas/config.rb,
lib/peas/version.rb
Constant Summary collapse
- SWITCHBOARD_PORT =
The port for Peas’ Switchboard socket server
ENV['SWITCHBOARD_PORT'] || 9345
- VERSION =
File.read File.("../../../VERSION", __FILE__)
Class Method Summary collapse
-
.api_domain ⇒ Object
Hierarchy of sources for the Peas API domain.
-
.config ⇒ Object
Read JSON config from file.
- .config_file ⇒ Object
- .error_message(string) ⇒ Object
- .host ⇒ Object
-
.update_config(hash) ⇒ Object
Merge new key/values into the config file.
- .warning_message(string) ⇒ Object
Class Method Details
.api_domain ⇒ Object
Hierarchy of sources for the Peas API domain
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/peas/config.rb', line 24 def self.api_domain git_domain = Git.sh 'git config peas.domain' domain = if ENV['PEAS_API_ENDPOINT'] ENV['PEAS_API_ENDPOINT'] elsif !git_domain.nil? && git_domain != '' git_domain elsif Peas.config['domain'] Peas.config['domain'] else 'vcap.me:4443' end unless domain[/\Ahttp:\/\//] || domain[/\Ahttps:\/\//] "https://#{domain}" else domain end end |
.config ⇒ Object
Read JSON config from file
10 11 12 13 14 15 |
# File 'lib/peas/config.rb', line 10 def self.config file = File.open config_file, "a+" contents = file.read contents = '{}' if contents == '' JSON.parse contents end |
.config_file ⇒ Object
5 6 7 |
# File 'lib/peas/config.rb', line 5 def self.config_file "#{ENV['HOME']}/.peas" end |
.error_message(string) ⇒ Object
47 48 49 |
# File 'lib/peas/config.rb', line 47 def self.(string) puts string.color(:red) end |
.host ⇒ Object
43 44 45 |
# File 'lib/peas/config.rb', line 43 def self.host URI.parse(Peas.api_domain).host end |
.update_config(hash) ⇒ Object
Merge new key/values into the config file
18 19 20 21 |
# File 'lib/peas/config.rb', line 18 def self.update_config(hash) content = Peas.config.merge(hash).to_json File.open(Peas.config_file, 'w+') { |f| f.write(content) } end |
.warning_message(string) ⇒ Object
51 52 53 |
# File 'lib/peas/config.rb', line 51 def self.(string) puts string.color(:magenta) end |