Class: Chronos::Configuration

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

Overview

Mutable configuration used only while the Chronos agent is being set up.

Examples:

config = Chronos::Configuration.new
config.project_id = 'project-id'
config.project_key = 'project-key'
config.host = 'https://chronos.example.com'
snapshot = config.snapshot

Defined Under Namespace

Classes: Snapshot

Constant Summary collapse

ATTRIBUTES =
[
  :project_id, :project_key, :host, :environment, :app_version,
  :service_name, :root_directory, :logger, :timeout, :open_timeout,
  :queue_size, :workers, :enabled, :error_notifications,
  :ignored_environments, :proxy, :ssl_verify, :user_agent,
  :max_payload_size, :gzip
].freeze

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/chronos/configuration.rb', line 32

def initialize
  @project_id = nil
  @project_key = nil
  @host = nil
  @environment = "production"
  @app_version = nil
  @service_name = nil
  @root_directory = Dir.pwd
  @logger = nil
  @timeout = 5.0
  @open_timeout = 2.0
  @queue_size = 100
  @workers = 1
  @enabled = true
  @error_notifications = true
  @ignored_environments = []
  @proxy = nil
  @ssl_verify = true
  @user_agent = "chronos-ruby/#{Chronos::VERSION}"
  @max_payload_size = 1_048_576
  @gzip = false
end

Instance Method Details

#snapshotObject

Raises:



55
56
57
58
59
60
# File 'lib/chronos/configuration.rb', line 55

def snapshot
  errors = validation_errors
  raise ConfigurationError, errors.join(", ") unless errors.empty?

  Snapshot.new(to_hash)
end

#valid?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/chronos/configuration.rb', line 62

def valid?
  validation_errors.empty?
end

#validation_errorsObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/chronos/configuration.rb', line 66

def validation_errors
  errors = []
  if enabled
    errors << "project_id is required" if blank?(project_id)
    errors << "project_key is required" if blank?(project_key)
    errors.concat(host_errors)
  end
  errors << "timeout must be greater than zero" unless positive_number?(timeout)
  errors << "open_timeout must be greater than zero" unless positive_number?(open_timeout)
  errors << "queue_size must be a positive integer" unless positive_integer?(queue_size)
  errors << "workers must be a positive integer" unless positive_integer?(workers)
  errors << "max_payload_size must be a positive integer" unless positive_integer?(max_payload_size)
  errors
end