Module: Stretchy::Utils::Configuration

Included in:
Stretchy
Defined in:
lib/stretchy/utils/configuration.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#adapterObject

Returns the value of attribute adapter.



5
6
7
# File 'lib/stretchy/utils/configuration.rb', line 5

def adapter
  @adapter
end

#client(options = {}) ⇒ Object

Returns the value of attribute client.



5
6
7
# File 'lib/stretchy/utils/configuration.rb', line 5

def client
  @client
end

#index_nameObject

Returns the value of attribute index_name.



5
6
7
# File 'lib/stretchy/utils/configuration.rb', line 5

def index_name
  @index_name
end

#log_colorObject

Returns the value of attribute log_color.



5
6
7
# File 'lib/stretchy/utils/configuration.rb', line 5

def log_color
  @log_color
end

#log_levelObject

Returns the value of attribute log_level.



5
6
7
# File 'lib/stretchy/utils/configuration.rb', line 5

def log_level
  @log_level
end

#loggerObject

Returns the value of attribute logger.



5
6
7
# File 'lib/stretchy/utils/configuration.rb', line 5

def logger
  @logger
end

#urlObject

Returns the value of attribute url.



5
6
7
# File 'lib/stretchy/utils/configuration.rb', line 5

def url
  @url
end

Class Method Details

.extended(base) ⇒ Object



7
8
9
# File 'lib/stretchy/utils/configuration.rb', line 7

def self.extended(base)
  base.set_default_configuration
end

Instance Method Details

#client_optionsObject



22
23
24
25
26
27
28
29
30
# File 'lib/stretchy/utils/configuration.rb', line 22

def client_options
  Hash[
    index_name: index_name,
    log:        !!logger,
    logger:     logger,
    adapter:    adapter,
    url:        url
  ]
end

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

Yields:

  • (_self)

Yield Parameters:



11
12
13
# File 'lib/stretchy/utils/configuration.rb', line 11

def configure
  yield self
end

#connect(options = {}) ⇒ Object



32
33
34
# File 'lib/stretchy/utils/configuration.rb', line 32

def connect(options = {})
  @client = Elasticsearch::Client.new(client_options.merge(options))
end

#log(*args) ⇒ Object



44
45
46
# File 'lib/stretchy/utils/configuration.rb', line 44

def log(*args)
  args.each {|arg| log_handler.log(arg) }
end

#log_handlerObject



40
41
42
# File 'lib/stretchy/utils/configuration.rb', line 40

def log_handler
  @log_handler ||= Stretchy::Utils::Logger.new(logger, log_level, log_color)
end

#set_default_configurationObject



15
16
17
18
19
20
# File 'lib/stretchy/utils/configuration.rb', line 15

def set_default_configuration
  self.index_name = 'myapp'
  self.adapter =    :excon
  self.url =        ENV['ELASTICSEARCH_URL']
  self.log_level =  :silence
end