Module: Squeezer::Configuration

Included in:
Squeezer
Defined in:
lib/squeezer/configuration.rb

Overview

Defines constants and methods related to configuration

Constant Summary collapse

VALID_OPTIONS_KEYS =

An array of valid keys in the options hash when configuring an API

[:server, :port].freeze
DEFAULT_SERVER =

By default, set localhost as the server

"127.0.0.1".freeze
DEFAULT_PORT =
Note:

The default is set to 9090

The port where the CLI interface is running on

9090.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object

When this module is extended, set all configuration options to their default values



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

def self.extended(base)
  base.reset
end

Instance Method Details

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

Convenience method to allow configuration options to be set in a block

Yields:

  • (_self)

Yield Parameters:



26
27
28
# File 'lib/squeezer/configuration.rb', line 26

def configure
  yield self
end

#optionsObject

Create a hash of options and their values



31
32
33
34
35
# File 'lib/squeezer/configuration.rb', line 31

def options
  VALID_OPTIONS_KEYS.inject({}) do |option, key|
    option.merge!(key => send(key))
  end
end

#resetObject

Reset all configuration options to defaults



38
39
40
41
42
# File 'lib/squeezer/configuration.rb', line 38

def reset
  self.server = DEFAULT_SERVER
  self.port = DEFAULT_PORT
  self
end