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.
-
#disable_metrics ⇒ Object
Returns the value of attribute disable_metrics.
-
#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.
-
#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_url ⇒ Object
- #client_register_url ⇒ Object
- #fetch_toggles_url ⇒ Object
-
#initialize(opts = {}) ⇒ Configuration
constructor
A new instance of Configuration.
- #metrics_interval_in_millis ⇒ Object
- #refresh_backup_file! ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Configuration
Returns a new instance of Configuration.
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 36 37 |
# File 'lib/unleash/configuration.rb', line 11 def initialize(opts = {}) self.app_name = opts[:app_name] || nil self.url = opts[:url] || nil self.instance_id = opts[:instance_id] || SecureRandom.uuid self.disable_metrics = opts[:disable_metrics] || false self.refresh_interval = opts[:refresh_interval] || 15 self.metrics_interval = opts[:metrics_interval] || 10 self.timeout = opts[:timeout] || 30 self.retry_limit = opts[:retry_limit] || 1 self.backup_file = opts[:backup_file] || nil self.logger = opts[:logger] || Logger.new(STDOUT) self.log_level = opts[:log_level] || Logger::ERROR if opts[:logger].nil? # on default logger, use custom formatter that includes thread_name: self.logger.formatter = proc do |severity, datetime, progname, msg| thread_name = (Thread.current[:name] || "Unleash").rjust(16, ' ') "[#{datetime.iso8601(6)} #{thread_name} #{severity.ljust(5, ' ')}] : #{msg}\n" end end 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 |
#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 |
#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 |
#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_url ⇒ Object
59 60 61 |
# File 'lib/unleash/configuration.rb', line 59 def client_metrics_url self.url + '/client/metrics' end |
#client_register_url ⇒ Object
63 64 65 |
# File 'lib/unleash/configuration.rb', line 63 def client_register_url self.url + '/client/register' end |
#fetch_toggles_url ⇒ Object
55 56 57 |
# File 'lib/unleash/configuration.rb', line 55 def fetch_toggles_url self.url + '/client/features' end |
#metrics_interval_in_millis ⇒ Object
39 40 41 |
# File 'lib/unleash/configuration.rb', line 39 def metrics_interval_in_millis self.metrics_interval * 1_000 end |
#refresh_backup_file! ⇒ Object
49 50 51 52 53 |
# File 'lib/unleash/configuration.rb', line 49 def refresh_backup_file! if self.backup_file.nil? self.backup_file = Dir.tmpdir + "/unleash-#{app_name}-repo.json" end end |
#validate! ⇒ Object
43 44 45 46 47 |
# File 'lib/unleash/configuration.rb', line 43 def validate! if self.app_name.nil? or self.url.nil? raise ArgumentError, "URL and app_name are required" end end |