Module: Evostream::Configuration

Included in:
Evostream
Defined in:
lib/evostream/configuration.rb

Constant Summary collapse

VALID_CONFIG_KEYS =
[
  :host, :protocol, :port, :path_prefix, :timeout, :username, :password
].freeze
OPTIONAL_CONFIG_KEYS =
VALID_CONFIG_KEYS - [:host]
DEFAULT_PROTOCOL =
'http'
DEFAULT_PORT =
80
DEFAULT_PATH_PREFIX =
''
DEFAULT_USERNAME =
''
DEFAULT_PASSWORD =
''
DEFAULT_TIMEOUT =
5

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object

Make sure we have the default values set when we get ‘extended’



21
22
23
# File 'lib/evostream/configuration.rb', line 21

def self.extended(base)
  base.reset
end

Instance Method Details

#configure {|_self| ... } ⇒ Object

config/initializers/evostream.rb (for instance)

Evostream.configure do |config|

config.host = 'evostream.example.com'
config.protocol = 'http'
config.port = 80
config.path_prefix = '/evo'
config.username = 'evo'
config.password = 'password'

end

elsewhere

client = Evostream::Client.new

Yields:

  • (_self)

Yield Parameters:



49
50
51
52
# File 'lib/evostream/configuration.rb', line 49

def configure
  yield self
  true
end

#optionsObject



54
55
56
# File 'lib/evostream/configuration.rb', line 54

def options
  Hash[ * VALID_CONFIG_KEYS.map { |key| [key, send(key)] }.flatten ]
end

#resetObject



25
26
27
28
29
30
31
32
# File 'lib/evostream/configuration.rb', line 25

def reset
  self.protocol    = DEFAULT_PROTOCOL
  self.port        = DEFAULT_PORT
  self.path_prefix = DEFAULT_PATH_PREFIX
  self.username    = DEFAULT_USERNAME
  self.password    = DEFAULT_PASSWORD
  self.timeout     = DEFAULT_TIMEOUT
end