Class: Stilts::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/stilts/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
51
52
# File 'lib/stilts/configuration.rb', line 41

def initialize
  @secure                   = false
  # @host                     = 'stilts.developmentnow.com'
  # @port                     = 80
  @host                     = "localhost"
  @port                     = 3000
  @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/stilts/configuration.rb', line 9

def api_key
  @api_key
end

#cdn_hostObject

The CDN host to connect to



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

def cdn_host
  @cdn_host
end

#frameworkObject

The framework is configured to use



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

def framework
  @framework
end

#hostObject

The host to connect to



12
13
14
# File 'lib/stilts/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/stilts/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/stilts/configuration.rb', line 37

def http_read_timeout
  @http_read_timeout
end

#loggerObject

The logger used by



28
29
30
# File 'lib/stilts/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/stilts/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/stilts/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/stilts/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



57
58
59
# File 'lib/stilts/configuration.rb', line 57

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



80
81
82
# File 'lib/stilts/configuration.rb', line 80

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

#protocolObject



88
89
90
91
92
93
94
# File 'lib/stilts/configuration.rb', line 88

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

#to_hashObject

Returns a hash of all configurable options



71
72
73
74
75
# File 'lib/stilts/configuration.rb', line 71

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

#urlObject



61
62
63
64
65
66
67
68
# File 'lib/stilts/configuration.rb', line 61

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