Class: RestfulClientConfiguration
- Inherits:
-
Object
- Object
- RestfulClientConfiguration
- Defined in:
- lib/restful_client_configuration.rb
Constant Summary collapse
- DEFAULT_TIMEOUT =
10
- DEFAULT_RETRIES =
2
- DEFAULT_USER_AGENT =
'RestfulClient - https://github.com/AvnerCohen/restful-client'
Instance Attribute Summary collapse
-
#config_folder ⇒ Object
Returns the value of attribute config_folder.
-
#data ⇒ Object
Returns the value of attribute data.
-
#env_name ⇒ Object
Returns the value of attribute env_name.
-
#legacy_postfix ⇒ Object
Returns the value of attribute legacy_postfix.
-
#report_method ⇒ Object
Returns the value of attribute report_method.
-
#retries ⇒ Object
Returns the value of attribute retries.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#use_jynx ⇒ Object
Returns the value of attribute use_jynx.
-
#user_agent ⇒ Object
Returns the value of attribute user_agent.
Instance Method Summary collapse
- #env ⇒ Object
-
#report_on ⇒ Object
Dummy method to test reporting phase.
- #reset ⇒ Object
- #run! ⇒ Object
Instance Attribute Details
#config_folder ⇒ Object
Returns the value of attribute config_folder.
4 5 6 |
# File 'lib/restful_client_configuration.rb', line 4 def config_folder @config_folder end |
#data ⇒ Object
Returns the value of attribute data.
4 5 6 |
# File 'lib/restful_client_configuration.rb', line 4 def data @data end |
#env_name ⇒ Object
Returns the value of attribute env_name.
4 5 6 |
# File 'lib/restful_client_configuration.rb', line 4 def env_name @env_name end |
#legacy_postfix ⇒ Object
Returns the value of attribute legacy_postfix.
4 5 6 |
# File 'lib/restful_client_configuration.rb', line 4 def legacy_postfix @legacy_postfix end |
#report_method ⇒ Object
Returns the value of attribute report_method.
4 5 6 |
# File 'lib/restful_client_configuration.rb', line 4 def report_method @report_method end |
#retries ⇒ Object
Returns the value of attribute retries.
4 5 6 |
# File 'lib/restful_client_configuration.rb', line 4 def retries @retries end |
#timeout ⇒ Object
Returns the value of attribute timeout.
4 5 6 |
# File 'lib/restful_client_configuration.rb', line 4 def timeout @timeout end |
#use_jynx ⇒ Object
Returns the value of attribute use_jynx.
4 5 6 |
# File 'lib/restful_client_configuration.rb', line 4 def use_jynx @use_jynx end |
#user_agent ⇒ Object
Returns the value of attribute user_agent.
4 5 6 |
# File 'lib/restful_client_configuration.rb', line 4 def user_agent @user_agent end |
Instance Method Details
#env ⇒ Object
51 52 53 |
# File 'lib/restful_client_configuration.rb', line 51 def env @env_name || "default" end |
#report_on ⇒ Object
Dummy method to test reporting phase
47 48 49 |
# File 'lib/restful_client_configuration.rb', line 47 def report_on @report_method.call("RestfulClientConfiguration", "Initialized at: #{Time.now}.") end |
#reset ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/restful_client_configuration.rb', line 37 def reset @report_method = nil @timeout = nil @user_agent = nil @retries = nil @use_jynx = nil @legacy_postfix = nil end |
#run! ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/restful_client_configuration.rb', line 9 def run! raise "Configuration directory name must be provided" unless config_folder.class.to_s == "String" file_name = ["restful_services.yml", "rest_api.yml"].each do |name| locale_name = File.join(config_folder, name) break locale_name if File.file?(locale_name) end ## Set Default Values @report_method ||= proc {|*args| nil } @timeout ||= DEFAULT_TIMEOUT @user_agent ||= DEFAULT_USER_AGENT @retries ||= DEFAULT_RETRIES @legacy_postfix ||= "" @use_jynx = true if @use_jynx.nil? @data = YAML.load(ERB.new(File.read(file_name)).result)[env].each do |name, entry| next unless entry.has_key?("url") opts = { time_window_in_seconds: entry.fetch(:time_window_in_seconds, 20), max_errors: entry.fetch(:max_errors, 10), grace_period: entry.fetch(:grace_period, 120) } ServiceJynx.register!(name.gsub(@legacy_postfix, ""), opts) if @use_jynx end end |