Class: Dink::Configuration

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

Overview

Used to set up and modify settings for the notifier.

Constant Summary collapse

OPTIONS =
[:api_key, :host, :http_open_timeout, :http_read_timeout, :project_root,
:port, :protocol, :secure, :framework].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



41
42
43
44
45
46
47
48
49
50
# File 'lib/dink/configuration.rb', line 41

def initialize
  @secure                   = false
  @host                     ||= 'dink.developmentnow.com'
  @port                     ||= 80
  @cdn_host                 = 'd15ceu2kbcb932.cloudfront.net'
  @framework                = 'Standalone'
  @protocol                 = protocol
  @http_open_timeout        = 2
  @http_read_timeout        = 10
end

Instance Attribute Details

#api_keyObject

The API key for your project, found on the project edit form.



9
10
11
# File 'lib/dink/configuration.rb', line 9

def api_key
  @api_key
end

#cdn_hostObject

The CDN host to connect to



15
16
17
# File 'lib/dink/configuration.rb', line 15

def cdn_host
  @cdn_host
end

#frameworkObject

The framework is configured to use



31
32
33
# File 'lib/dink/configuration.rb', line 31

def framework
  @framework
end

#hostObject

The host to connect to



12
13
14
# File 'lib/dink/configuration.rb', line 12

def host
  @host
end

#http_open_timeoutObject

The HTTP open timeout in seconds (defaults to 2).



34
35
36
# File 'lib/dink/configuration.rb', line 34

def http_open_timeout
  @http_open_timeout
end

#http_read_timeoutObject

The HTTP read timeout in seconds (defaults to 5).



37
38
39
# File 'lib/dink/configuration.rb', line 37

def http_read_timeout
  @http_read_timeout
end

#loggerObject

The logger used by



28
29
30
# File 'lib/dink/configuration.rb', line 28

def logger
  @logger
end

#portObject

The port on which your server runs (defaults to 443 for secure connections, 80 for insecure connections).



19
20
21
# File 'lib/dink/configuration.rb', line 19

def port
  @port
end

#project_rootObject

The path to the project in which the error occurred, such as the RAILS_ROOT



25
26
27
# File 'lib/dink/configuration.rb', line 25

def project_root
  @project_root
end

#secureObject Also known as: secure?

true for https connections, false for http connections.



22
23
24
# File 'lib/dink/configuration.rb', line 22

def secure
  @secure
end

Instance Method Details

#[](option) ⇒ Object

Allows config options to be read like a hash

Parameters:

  • option (Symbol)

    Key for a given attribute



55
56
57
# File 'lib/dink/configuration.rb', line 55

def [](option)
  send(option)
end

#merge(hash) ⇒ Object

Returns a hash of all configurable options merged with hash

Parameters:

  • hash (Hash)

    A set of configuration options that will take precedence over the defaults



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

def merge(hash)
  to_hash.merge(hash)
end

#protocolObject



86
87
88
89
90
91
92
# File 'lib/dink/configuration.rb', line 86

def protocol
  if secure?
    'https'
  else
    'http'
  end
end

#to_hashObject

Returns a hash of all configurable options



69
70
71
72
73
# File 'lib/dink/configuration.rb', line 69

def to_hash
  OPTIONS.inject({}) do |hash, option|
    hash.merge(option.to_sym => send(option))
  end
end

#urlObject



59
60
61
62
63
64
65
66
# File 'lib/dink/configuration.rb', line 59

def url
  url = URI::HTTP.build({
    :host => @host,
    :scheme => protocol,
    :path => "/",
    :port => @port
  })
end