Class: WssAgent::Configure
- Inherits:
-
Object
- Object
- WssAgent::Configure
- Extended by:
- SingleForwardable
- Defined in:
- lib/wss_agent/configure.rb
Constant Summary collapse
- DEFAULT_CONFIG_FILE =
'default.yml'.freeze
- CUSTOM_DEFAULT_CONFIG_FILE =
'custom_default.yml'.freeze
- CURRENT_CONFIG_FILE =
'wss_agent.yml'.freeze
- API_PATH =
'/agent'.freeze
Class Method Summary collapse
- .api_path ⇒ Object
- .coordinates ⇒ Object
- .current ⇒ Object
- .current_path ⇒ Object
- .custom_default_path ⇒ Object
- .default ⇒ Object
- .default_path ⇒ Object
- .exist_default_config? ⇒ Boolean
- .port ⇒ Object
- .project_meta ⇒ Object
- .ssl? ⇒ Boolean
- .token ⇒ Object
- .uri ⇒ Object
- .url ⇒ Object
- .user_key ⇒ Object
- .user_key? ⇒ Boolean
Class Method Details
.api_path ⇒ Object
74 75 76 77 78 |
# File 'lib/wss_agent/configure.rb', line 74 def api_path @uri = uri @url_path = @uri.path @url_path == '' ? API_PATH : @url_path end |
.coordinates ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/wss_agent/configure.rb', line 101 def coordinates return {} unless current['project_token'].to_s.strip.empty? coordinates_config = current['coordinates'] coordinates_artifact_id = coordinates_config['artifact_id'] coordinates_version = coordinates_config['version'] if coordinates_artifact_id.to_s.strip.empty? coordinates_artifact_id = .project_name coordinates_version = .project_version end { 'artifactId' => coordinates_artifact_id, 'version' => coordinates_version } end |
.current ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/wss_agent/configure.rb', line 37 def current unless File.exist?(current_path) return raise NotFoundConfigFile, WssAgentError::NOT_FOUND_CONFIGFILE end @current_config = Psych.safe_load(File.read(current_path)) unless @current_config return raise InvalidConfigFile, WssAgentError::INVALID_CONFIG_FORMAT end default.merge(@current_config) end |
.current_path ⇒ Object
33 34 35 |
# File 'lib/wss_agent/configure.rb', line 33 def current_path Bundler.root.join(CURRENT_CONFIG_FILE).to_s end |
.custom_default_path ⇒ Object
18 19 20 21 22 23 |
# File 'lib/wss_agent/configure.rb', line 18 def custom_default_path File.join( File.('../..', __FILE__), 'config', CUSTOM_DEFAULT_CONFIG_FILE ) end |
.default ⇒ Object
29 30 31 |
# File 'lib/wss_agent/configure.rb', line 29 def default exist_default_config? ? Psych.safe_load(File.read(default_path)) : {} end |
.default_path ⇒ Object
12 13 14 15 16 |
# File 'lib/wss_agent/configure.rb', line 12 def default_path File.join( File.('../..', __FILE__), 'config', DEFAULT_CONFIG_FILE ) end |
.exist_default_config? ⇒ Boolean
25 26 27 |
# File 'lib/wss_agent/configure.rb', line 25 def exist_default_config? File.exist?(default_path) end |
.port ⇒ Object
61 62 63 |
# File 'lib/wss_agent/configure.rb', line 61 def port uri.port || 80 end |
.project_meta ⇒ Object
97 98 99 |
# File 'lib/wss_agent/configure.rb', line 97 def @project_meta ||= WssAgent::Project.new end |
.ssl? ⇒ Boolean
70 71 72 |
# File 'lib/wss_agent/configure.rb', line 70 def ssl? uri.scheme == 'https' end |
.token ⇒ Object
80 81 82 83 84 85 86 87 |
# File 'lib/wss_agent/configure.rb', line 80 def token if current['token'].nil? || (current['token'] == '') || (current['token'] == default['token']) raise TokenNotFound, WssAgentError::CANNOT_FIND_TOKEN else current['token'] end end |
.uri ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/wss_agent/configure.rb', line 51 def uri @url = current['url'] if @url.nil? || @url == '' raise ApiUrlNotFound, WssAgentError::CANNOT_FIND_URL end URI(@url) rescue URI::Error raise ApiUrlInvalid, WssAgentError::URL_INVALID end |
.url ⇒ Object
65 66 67 68 |
# File 'lib/wss_agent/configure.rb', line 65 def url @uri = uri [@uri.scheme, @uri.host].join('://') end |
.user_key ⇒ Object
89 90 91 |
# File 'lib/wss_agent/configure.rb', line 89 def user_key current['user_key'].to_s.strip end |
.user_key? ⇒ Boolean
93 94 95 |
# File 'lib/wss_agent/configure.rb', line 93 def user_key? !user_key.empty? end |