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.
-
#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.
-
#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.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #client_metrics_uri ⇒ Object
- #client_register_uri ⇒ Object
- #fetch_toggles_uri ⇒ Object
- #http_headers ⇒ Object
-
#initialize(opts = {}) ⇒ Configuration
constructor
A new instance of Configuration.
- #metrics_interval_in_millis ⇒ Object
- #refresh_backup_file! ⇒ Object
- #url_stripped_of_slash ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Configuration
Returns a new instance of Configuration.
23 24 25 26 27 28 29 30 31 |
# File 'lib/unleash/configuration.rb', line 23 def initialize(opts = {}) ensure_valid_opts(opts) 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.
6 7 8 |
# File 'lib/unleash/configuration.rb', line 6 def app_name @app_name end |
#backup_file ⇒ Object
Returns the value of attribute backup_file.
6 7 8 |
# File 'lib/unleash/configuration.rb', line 6 def backup_file @backup_file end |
#custom_http_headers ⇒ Object
Returns the value of attribute custom_http_headers.
6 7 8 |
# File 'lib/unleash/configuration.rb', line 6 def custom_http_headers @custom_http_headers end |
#disable_client ⇒ Object
Returns the value of attribute disable_client.
6 7 8 |
# File 'lib/unleash/configuration.rb', line 6 def disable_client @disable_client end |
#disable_metrics ⇒ Object
Returns the value of attribute disable_metrics.
6 7 8 |
# File 'lib/unleash/configuration.rb', line 6 def disable_metrics @disable_metrics end |
#environment ⇒ Object
Returns the value of attribute environment.
6 7 8 |
# File 'lib/unleash/configuration.rb', line 6 def environment @environment end |
#instance_id ⇒ Object
Returns the value of attribute instance_id.
6 7 8 |
# File 'lib/unleash/configuration.rb', line 6 def instance_id @instance_id end |
#log_level ⇒ Object
Returns the value of attribute log_level.
6 7 8 |
# File 'lib/unleash/configuration.rb', line 6 def log_level @log_level end |
#logger ⇒ Object
Returns the value of attribute logger.
6 7 8 |
# File 'lib/unleash/configuration.rb', line 6 def logger @logger end |
#metrics_interval ⇒ Object
Returns the value of attribute metrics_interval.
6 7 8 |
# File 'lib/unleash/configuration.rb', line 6 def metrics_interval @metrics_interval end |
#project_name ⇒ Object
Returns the value of attribute project_name.
6 7 8 |
# File 'lib/unleash/configuration.rb', line 6 def project_name @project_name end |
#refresh_interval ⇒ Object
Returns the value of attribute refresh_interval.
6 7 8 |
# File 'lib/unleash/configuration.rb', line 6 def refresh_interval @refresh_interval end |
#retry_limit ⇒ Object
Returns the value of attribute retry_limit.
6 7 8 |
# File 'lib/unleash/configuration.rb', line 6 def retry_limit @retry_limit end |
#timeout ⇒ Object
Returns the value of attribute timeout.
6 7 8 |
# File 'lib/unleash/configuration.rb', line 6 def timeout @timeout end |
#url ⇒ Object
Returns the value of attribute url.
6 7 8 |
# File 'lib/unleash/configuration.rb', line 6 def url @url end |
Instance Method Details
#client_metrics_uri ⇒ Object
61 62 63 |
# File 'lib/unleash/configuration.rb', line 61 def client_metrics_uri URI("#{self.url_stripped_of_slash}/client/metrics") end |
#client_register_uri ⇒ Object
65 66 67 |
# File 'lib/unleash/configuration.rb', line 65 def client_register_uri URI("#{self.url_stripped_of_slash}/client/register") end |
#fetch_toggles_uri ⇒ Object
55 56 57 58 59 |
# File 'lib/unleash/configuration.rb', line 55 def fetch_toggles_uri uri = URI("#{self.url_stripped_of_slash}/client/features") uri.query = "project=#{self.project_name}" unless self.project_name.nil? uri end |
#http_headers ⇒ Object
48 49 50 51 52 53 |
# File 'lib/unleash/configuration.rb', line 48 def http_headers { 'UNLEASH-INSTANCEID' => self.instance_id, 'UNLEASH-APPNAME' => self.app_name }.merge(custom_http_headers.dup) end |
#metrics_interval_in_millis ⇒ Object
33 34 35 |
# File 'lib/unleash/configuration.rb', line 33 def metrics_interval_in_millis self.metrics_interval * 1_000 end |
#refresh_backup_file! ⇒ Object
44 45 46 |
# File 'lib/unleash/configuration.rb', line 44 def refresh_backup_file! self.backup_file = File.join(Dir.tmpdir, "unleash-#{app_name}-repo.json") end |
#url_stripped_of_slash ⇒ Object
69 70 71 |
# File 'lib/unleash/configuration.rb', line 69 def url_stripped_of_slash self.url.delete_suffix '/' end |
#validate! ⇒ Object
37 38 39 40 41 42 |
# File 'lib/unleash/configuration.rb', line 37 def validate! return if self.disable_client raise ArgumentError, "URL and app_name are required parameters." if self.app_name.nil? || self.url.nil? raise ArgumentError, "custom_http_headers must be a hash." unless self.custom_http_headers.is_a?(Hash) end |