Class: Melissa::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/melissa/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/melissa/config.rb', line 25

def initialize
  #It is recommended to read the following config options from environment variables
  #From Melissa Data documentation:
  #The license string should be entered as an environment variable named
  #MD_LICENSE. This allows you to update your license string without editing
  #and recompiling your code
  self.mode = :live

  self.home = ENV['MELISSA_HOME'] || '/usr/local/dqs'
  self.config_path = ENV['MELISSA_CONFIG_PATH'] if ENV['MELISSA_CONFIG_PATH']
  @data_path = ENV['MELISSA_DATA_PATH'] if ENV['MELISSA_DATA_PATH']
  @addr_obj_lib = ENV['MELISSA_ADDR_OBJ_LIB'] if ENV['MELISSA_ADDR_OBJ_LIB']
  @geo_point_lib = ENV['MELISSA_GEO_POINT_LIB'] if ENV['MELISSA_GEO_POINT_LIB']
  @license = ENV['MD_LICENSE'] if ENV['MD_LICENSE']
end

Instance Attribute Details

#addr_obj_libObject

Returns the value of attribute addr_obj_lib.



23
24
25
# File 'lib/melissa/config.rb', line 23

def addr_obj_lib
  @addr_obj_lib
end

#data_pathObject

Returns the value of attribute data_path.



23
24
25
# File 'lib/melissa/config.rb', line 23

def data_path
  @data_path
end

#geo_point_libObject

Returns the value of attribute geo_point_lib.



23
24
25
# File 'lib/melissa/config.rb', line 23

def geo_point_lib
  @geo_point_lib
end

#licenseObject

Returns the value of attribute license.



23
24
25
# File 'lib/melissa/config.rb', line 23

def license
  @license
end

#modeObject

Returns the value of attribute mode.



23
24
25
# File 'lib/melissa/config.rb', line 23

def mode
  @mode
end

Instance Method Details

#config_path=(config_path) ⇒ Object

you can configure config_path from your code using:

Melissa.configure do |config|
  config.config_path = "/etc/config/melissa"
end


45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/melissa/config.rb', line 45

def config_path=(config_path)
  File.open(config_path, 'r') do |fin|
    fin.each do |line|
      line.strip!
      next if line.empty? || line[0] == '#'
      equal_index = line.index('=')
      key = line[0, equal_index].strip.downcase
      value = line[(equal_index+1)..-1].strip
      send("#{key}=", value)
    end
  end
rescue Errno::ENOENT
  raise "Configuration file couldn't be found. We need #{config_path}"
end

#home=(home) ⇒ Object



60
61
62
63
64
# File 'lib/melissa/config.rb', line 60

def home=(home)
  @addr_obj_lib = "#{home}/AddrObj/libmdAddr.so"
  @geo_point_lib = "#{home}/GeoObj/libmdGeo.so"
  @data_path = "#{home}/data"
end