Class: ConfigServerAgent
- Inherits:
-
Object
- Object
- ConfigServerAgent
- Defined in:
- lib/config_server_agent.rb,
lib/config_server_agent/version.rb
Defined Under Namespace
Classes: Error
Constant Summary collapse
- VERSION =
'0.4.2'
Instance Method Summary collapse
- #clear ⇒ Object
- #get_config ⇒ Object
- #get_selected_config(area, item = nil, **options) ⇒ Object
-
#initialize(config_server_api_key: ENV['CONFIG_SERVER_API_KEY'], config_server_host: ENV['CONFIG_SERVER_HOST'], user_agent: "ConfigServerAgent/#{ConfigServerAgent::VERSION}", user_agent_comment: nil) ⇒ ConfigServerAgent
constructor
A new instance of ConfigServerAgent.
- #notify_missing(area, missing) ⇒ Object
- #set_config(values) ⇒ Object
Constructor Details
#initialize(config_server_api_key: ENV['CONFIG_SERVER_API_KEY'], config_server_host: ENV['CONFIG_SERVER_HOST'], user_agent: "ConfigServerAgent/#{ConfigServerAgent::VERSION}", user_agent_comment: nil) ⇒ ConfigServerAgent
Returns a new instance of ConfigServerAgent.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/config_server_agent.rb', line 10 def initialize( config_server_api_key: ENV['CONFIG_SERVER_API_KEY'], config_server_host: ENV['CONFIG_SERVER_HOST'], user_agent: "ConfigServerAgent/#{ConfigServerAgent::VERSION}", user_agent_comment: nil ) @config_server_api_key = config_server_api_key or raise ArgumentError, 'Missing config_server_api_key parameter' @config_server_host = config_server_host or raise ArgumentError, 'Missing config_server_host parameter' @config = nil @mutex = Mutex.new @user_agent = user_agent @user_agent += " (#{user_agent_comment})" if user_agent_comment end |
Instance Method Details
#clear ⇒ Object
54 55 56 |
# File 'lib/config_server_agent.rb', line 54 def clear @config = nil end |
#get_config ⇒ Object
25 26 27 28 29 30 |
# File 'lib/config_server_agent.rb', line 25 def get_config return @config if @config @mutex.synchronize do @config ||= get_request('config_pack', {'cb' => Random.rand}) end end |
#get_selected_config(area, item = nil, **options) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/config_server_agent.rb', line 32 def get_selected_config(area, item=nil, **) if [:ignore_cache] @config = nil end data = get_config.group_by { |x| x['area'] } raise Error, "Area is missing: #{area}" unless data.key? area if item data.fetch(area, []).find { |row_item| break row_item["value"] if row_item["name"] == item } else data.fetch(area, []) end end |
#notify_missing(area, missing) ⇒ Object
58 59 60 |
# File 'lib/config_server_agent.rb', line 58 def notify_missing(area, missing) post_request 'notify_missing', area: area, name: missing end |
#set_config(values) ⇒ Object
49 50 51 52 |
# File 'lib/config_server_agent.rb', line 49 def set_config(values) raise Error, 'values not found' if values.empty? post_request('set_values', values) end |