Class: Mebla::Configuration

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/mebla/configuration.rb

Overview

Parses the configuration file and holds important configuration attributes

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Initializes a new configuration object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/mebla/configuration.rb', line 15

def initialize
  @log_dir = "#{Dir.pwd}/tmp/log"
  parse_config      
  
  # Setup defaults
  @index ||= "mebla"
  @host ||= "localhost"
  @port ||= 9200
  
  make_tmp_dir
  @logger = ActiveSupport::BufferedLogger.new(
    open("#{@log_dir}/mebla.log", "a")
  )
  @logger.level = ActiveSupport::BufferedLogger::Severity::DEBUG
  
  setup_logger        
  
  # Setup slingshot
  Slingshot::Configuration.url(self.url)
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



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

def host
  @host
end

#indexObject

Returns the value of attribute index.



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

def index
  @index
end

#log_dirObject (readonly)

Returns the value of attribute log_dir.



10
11
12
# File 'lib/mebla/configuration.rb', line 10

def log_dir
  @log_dir
end

#loggerObject

Returns the value of attribute logger.



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

def logger
  @logger
end

#portObject

Returns the value of attribute port.



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

def port
  @port
end

Instance Method Details

#setup_loggernil

Sets up the default settings of the logger

Returns:

  • (nil)


38
39
40
# File 'lib/mebla/configuration.rb', line 38

def setup_logger
  @logger.auto_flushing = true      
end

#urlString

Returns the proper url for elasticsearch

Returns:

  • (String)

    url representation of the configuration options host and port



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

def url
  "http://#{@host}:#{@port}"
end