Class: Unleash::Configuration
- Inherits:
-
Object
- Object
- Unleash::Configuration
- Defined in:
- lib/unleash/configuration.rb
Instance Attribute Summary collapse
-
#app_name ⇒ Object
Returns the value of attribute app_name.
-
#backup_file ⇒ Object
Returns the value of attribute backup_file.
-
#bootstrap_config ⇒ Object
Returns the value of attribute bootstrap_config.
-
#connection_id ⇒ Object
readonly
Returns the value of attribute connection_id.
-
#custom_http_headers ⇒ Object
Returns the value of attribute custom_http_headers.
-
#disable_client ⇒ Object
Returns the value of attribute disable_client.
-
#disable_metrics ⇒ Object
Returns the value of attribute disable_metrics.
-
#environment ⇒ Object
Returns the value of attribute environment.
-
#experimental_mode ⇒ Object
Returns the value of attribute experimental_mode.
-
#instance_id ⇒ Object
Returns the value of attribute instance_id.
-
#log_level ⇒ Object
Returns the value of attribute log_level.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#metrics_interval ⇒ Object
Returns the value of attribute metrics_interval.
-
#project_name ⇒ Object
Returns the value of attribute project_name.
-
#refresh_interval ⇒ Object
Returns the value of attribute refresh_interval.
-
#retry_limit ⇒ Object
Returns the value of attribute retry_limit.
-
#sdk_flavor ⇒ Object
Returns the value of attribute sdk_flavor.
-
#sdk_flavor_version ⇒ Object
Returns the value of attribute sdk_flavor_version.
-
#strategies ⇒ Object
Returns the value of attribute strategies.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#url ⇒ Object
Returns the value of attribute url.
-
#use_delta_api ⇒ Object
Returns the value of attribute use_delta_api.
Instance Method Summary collapse
- #client_metrics_uri ⇒ Object
- #client_register_uri ⇒ Object
- #fetch_toggles_uri ⇒ Object
- #generate_custom_http_headers ⇒ Object
- #http_headers ⇒ Object
-
#initialize(opts = {}) ⇒ Configuration
constructor
A new instance of Configuration.
- #metrics_interval_in_millis ⇒ Object
- #polling_with_delta? ⇒ Boolean
- #refresh_backup_file! ⇒ Object
- #sdk_flavor_fields ⇒ Object
- #streaming_mode? ⇒ Boolean
- #url_stripped_of_slash ⇒ Object
- #use_bootstrap? ⇒ Boolean
- #validate! ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Configuration
Returns a new instance of Configuration.
31 32 33 34 35 36 37 38 39 |
# File 'lib/unleash/configuration.rb', line 31 def initialize(opts = {}) validate_custom_http_headers!(opts[:custom_http_headers]) if opts.has_key?(:custom_http_headers) set_defaults initialize_default_logger if opts[:logger].nil? merge(opts) refresh_backup_file! end |
Instance Attribute Details
#app_name ⇒ Object
Returns the value of attribute app_name.
7 8 9 |
# File 'lib/unleash/configuration.rb', line 7 def app_name @app_name end |
#backup_file ⇒ Object
Returns the value of attribute backup_file.
7 8 9 |
# File 'lib/unleash/configuration.rb', line 7 def backup_file @backup_file end |
#bootstrap_config ⇒ Object
Returns the value of attribute bootstrap_config.
7 8 9 |
# File 'lib/unleash/configuration.rb', line 7 def bootstrap_config @bootstrap_config end |
#connection_id ⇒ Object (readonly)
Returns the value of attribute connection_id.
29 30 31 |
# File 'lib/unleash/configuration.rb', line 29 def connection_id @connection_id end |
#custom_http_headers ⇒ Object
Returns the value of attribute custom_http_headers.
7 8 9 |
# File 'lib/unleash/configuration.rb', line 7 def custom_http_headers @custom_http_headers end |
#disable_client ⇒ Object
Returns the value of attribute disable_client.
7 8 9 |
# File 'lib/unleash/configuration.rb', line 7 def disable_client @disable_client end |
#disable_metrics ⇒ Object
Returns the value of attribute disable_metrics.
7 8 9 |
# File 'lib/unleash/configuration.rb', line 7 def disable_metrics @disable_metrics end |
#environment ⇒ Object
Returns the value of attribute environment.
7 8 9 |
# File 'lib/unleash/configuration.rb', line 7 def environment @environment end |
#experimental_mode ⇒ Object
Returns the value of attribute experimental_mode.
7 8 9 |
# File 'lib/unleash/configuration.rb', line 7 def experimental_mode @experimental_mode end |
#instance_id ⇒ Object
Returns the value of attribute instance_id.
7 8 9 |
# File 'lib/unleash/configuration.rb', line 7 def instance_id @instance_id end |
#log_level ⇒ Object
Returns the value of attribute log_level.
7 8 9 |
# File 'lib/unleash/configuration.rb', line 7 def log_level @log_level end |
#logger ⇒ Object
Returns the value of attribute logger.
7 8 9 |
# File 'lib/unleash/configuration.rb', line 7 def logger @logger end |
#metrics_interval ⇒ Object
Returns the value of attribute metrics_interval.
7 8 9 |
# File 'lib/unleash/configuration.rb', line 7 def metrics_interval @metrics_interval end |
#project_name ⇒ Object
Returns the value of attribute project_name.
7 8 9 |
# File 'lib/unleash/configuration.rb', line 7 def project_name @project_name end |
#refresh_interval ⇒ Object
Returns the value of attribute refresh_interval.
7 8 9 |
# File 'lib/unleash/configuration.rb', line 7 def refresh_interval @refresh_interval end |
#retry_limit ⇒ Object
Returns the value of attribute retry_limit.
7 8 9 |
# File 'lib/unleash/configuration.rb', line 7 def retry_limit @retry_limit end |
#sdk_flavor ⇒ Object
Returns the value of attribute sdk_flavor.
7 8 9 |
# File 'lib/unleash/configuration.rb', line 7 def sdk_flavor @sdk_flavor end |
#sdk_flavor_version ⇒ Object
Returns the value of attribute sdk_flavor_version.
7 8 9 |
# File 'lib/unleash/configuration.rb', line 7 def sdk_flavor_version @sdk_flavor_version end |
#strategies ⇒ Object
Returns the value of attribute strategies.
7 8 9 |
# File 'lib/unleash/configuration.rb', line 7 def strategies @strategies end |
#timeout ⇒ Object
Returns the value of attribute timeout.
7 8 9 |
# File 'lib/unleash/configuration.rb', line 7 def timeout @timeout end |
#url ⇒ Object
Returns the value of attribute url.
7 8 9 |
# File 'lib/unleash/configuration.rb', line 7 def url @url end |
#use_delta_api ⇒ Object
Returns the value of attribute use_delta_api.
7 8 9 |
# File 'lib/unleash/configuration.rb', line 7 def use_delta_api @use_delta_api end |
Instance Method Details
#client_metrics_uri ⇒ Object
92 93 94 |
# File 'lib/unleash/configuration.rb', line 92 def client_metrics_uri URI("#{self.url_stripped_of_slash}/client/metrics") end |
#client_register_uri ⇒ Object
96 97 98 |
# File 'lib/unleash/configuration.rb', line 96 def client_register_uri URI("#{self.url_stripped_of_slash}/client/register") end |
#fetch_toggles_uri ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/unleash/configuration.rb', line 76 def fetch_toggles_uri uri = nil ## Personal feeling but Rubocop's suggestion here is too dense to be properly readable # rubocop:disable Style/ConditionalAssignment if streaming_mode? uri = URI("#{self.url_stripped_of_slash}/client/streaming") elsif self.use_delta_api || polling_with_delta? uri = URI("#{self.url_stripped_of_slash}/client/delta") else uri = URI("#{self.url_stripped_of_slash}/client/features") end # rubocop:enable Style/ConditionalAssignment uri.query = "project=#{self.project_name}" unless self.project_name.nil? uri end |
#generate_custom_http_headers ⇒ Object
119 120 121 122 123 |
# File 'lib/unleash/configuration.rb', line 119 def generate_custom_http_headers return self.custom_http_headers.call if self.custom_http_headers.respond_to?(:call) self.custom_http_headers end |
#http_headers ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/unleash/configuration.rb', line 64 def http_headers headers = { 'User-Agent' => "UnleashClientRuby/#{Unleash::VERSION} #{RUBY_ENGINE}/#{RUBY_VERSION} [#{RUBY_PLATFORM}]", 'UNLEASH-INSTANCEID' => self.instance_id, 'UNLEASH-APPNAME' => self.app_name, 'Unleash-Client-Spec' => CLIENT_SPECIFICATION_VERSION, 'UNLEASH-SDK' => "unleash-ruby-sdk:#{Unleash::VERSION}" }.merge!(generate_custom_http_headers) headers['UNLEASH-CONNECTION-ID'] = @connection_id headers end |
#metrics_interval_in_millis ⇒ Object
41 42 43 |
# File 'lib/unleash/configuration.rb', line 41 def metrics_interval_in_millis self.metrics_interval * 1_000 end |
#polling_with_delta? ⇒ Boolean
113 114 115 116 117 |
# File 'lib/unleash/configuration.rb', line 113 def polling_with_delta? self.experimental_mode.is_a?(Hash) && self.experimental_mode[:type] == 'polling' && self.experimental_mode[:format] == 'delta' end |
#refresh_backup_file! ⇒ Object
60 61 62 |
# File 'lib/unleash/configuration.rb', line 60 def refresh_backup_file! self.backup_file = File.join(Dir.tmpdir, "unleash-#{app_name}-repo.json") end |
#sdk_flavor_fields ⇒ Object
45 46 47 48 49 50 |
# File 'lib/unleash/configuration.rb', line 45 def sdk_flavor_fields { sdkFlavor: self.sdk_flavor, sdkFlavorVersion: self.sdk_flavor_version }.compact end |
#streaming_mode? ⇒ Boolean
108 109 110 111 |
# File 'lib/unleash/configuration.rb', line 108 def streaming_mode? validate_streaming_support! if streaming_configured? streaming_configured? end |
#url_stripped_of_slash ⇒ Object
100 101 102 |
# File 'lib/unleash/configuration.rb', line 100 def url_stripped_of_slash self.url.delete_suffix '/' end |
#use_bootstrap? ⇒ Boolean
104 105 106 |
# File 'lib/unleash/configuration.rb', line 104 def use_bootstrap? self.bootstrap_config&.valid? end |
#validate! ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/unleash/configuration.rb', line 52 def validate! return if self.disable_client raise ArgumentError, "app_name is a required parameter." if self.app_name.nil? validate_custom_http_headers!(self.custom_http_headers) unless self.url.nil? end |