Class: Unleash::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/unleash/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Configuration

Returns a new instance of Configuration.



26
27
28
29
30
31
32
33
34
# File 'lib/unleash/configuration.rb', line 26

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_nameObject

Returns the value of attribute app_name.



7
8
9
# File 'lib/unleash/configuration.rb', line 7

def app_name
  @app_name
end

#backup_fileObject

Returns the value of attribute backup_file.



7
8
9
# File 'lib/unleash/configuration.rb', line 7

def backup_file
  @backup_file
end

#bootstrap_configObject

Returns the value of attribute bootstrap_config.



7
8
9
# File 'lib/unleash/configuration.rb', line 7

def bootstrap_config
  @bootstrap_config
end

#custom_http_headersObject

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_clientObject

Returns the value of attribute disable_client.



7
8
9
# File 'lib/unleash/configuration.rb', line 7

def disable_client
  @disable_client
end

#disable_metricsObject

Returns the value of attribute disable_metrics.



7
8
9
# File 'lib/unleash/configuration.rb', line 7

def disable_metrics
  @disable_metrics
end

#environmentObject

Returns the value of attribute environment.



7
8
9
# File 'lib/unleash/configuration.rb', line 7

def environment
  @environment
end

#instance_idObject

Returns the value of attribute instance_id.



7
8
9
# File 'lib/unleash/configuration.rb', line 7

def instance_id
  @instance_id
end

#log_levelObject

Returns the value of attribute log_level.



7
8
9
# File 'lib/unleash/configuration.rb', line 7

def log_level
  @log_level
end

#loggerObject

Returns the value of attribute logger.



7
8
9
# File 'lib/unleash/configuration.rb', line 7

def logger
  @logger
end

#metrics_intervalObject

Returns the value of attribute metrics_interval.



7
8
9
# File 'lib/unleash/configuration.rb', line 7

def metrics_interval
  @metrics_interval
end

#project_nameObject

Returns the value of attribute project_name.



7
8
9
# File 'lib/unleash/configuration.rb', line 7

def project_name
  @project_name
end

#refresh_intervalObject

Returns the value of attribute refresh_interval.



7
8
9
# File 'lib/unleash/configuration.rb', line 7

def refresh_interval
  @refresh_interval
end

#retry_limitObject

Returns the value of attribute retry_limit.



7
8
9
# File 'lib/unleash/configuration.rb', line 7

def retry_limit
  @retry_limit
end

#strategiesObject

Returns the value of attribute strategies.



7
8
9
# File 'lib/unleash/configuration.rb', line 7

def strategies
  @strategies
end

#timeoutObject

Returns the value of attribute timeout.



7
8
9
# File 'lib/unleash/configuration.rb', line 7

def timeout
  @timeout
end

#urlObject

Returns the value of attribute url.



7
8
9
# File 'lib/unleash/configuration.rb', line 7

def url
  @url
end

Instance Method Details

#client_metrics_uriObject



66
67
68
# File 'lib/unleash/configuration.rb', line 66

def client_metrics_uri
  URI("#{self.url_stripped_of_slash}/client/metrics")
end

#client_register_uriObject



70
71
72
# File 'lib/unleash/configuration.rb', line 70

def client_register_uri
  URI("#{self.url_stripped_of_slash}/client/register")
end

#fetch_toggles_uriObject



60
61
62
63
64
# File 'lib/unleash/configuration.rb', line 60

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_headersObject



52
53
54
55
56
57
58
# File 'lib/unleash/configuration.rb', line 52

def http_headers
  {
    'UNLEASH-INSTANCEID' => self.instance_id,
    'UNLEASH-APPNAME' => self.app_name,
    'Unleash-Client-Spec' => '4.2.2'
  }.merge!(generate_custom_http_headers)
end

#metrics_interval_in_millisObject



36
37
38
# File 'lib/unleash/configuration.rb', line 36

def metrics_interval_in_millis
  self.metrics_interval * 1_000
end

#refresh_backup_file!Object



48
49
50
# File 'lib/unleash/configuration.rb', line 48

def refresh_backup_file!
  self.backup_file = File.join(Dir.tmpdir, "unleash-#{app_name}-repo.json")
end

#url_stripped_of_slashObject



74
75
76
# File 'lib/unleash/configuration.rb', line 74

def url_stripped_of_slash
  self.url.delete_suffix '/'
end

#use_bootstrap?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/unleash/configuration.rb', line 78

def use_bootstrap?
  self.bootstrap_config&.valid?
end

#validate!Object

Raises:

  • (ArgumentError)


40
41
42
43
44
45
46
# File 'lib/unleash/configuration.rb', line 40

def validate!
  return if self.disable_client

  raise ArgumentError, "URL and app_name are required parameters." if self.app_name.nil? || self.url.nil?

  validate_custom_http_headers!(self.custom_http_headers)
end