Class: Kafkat::Config

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

Defined Under Namespace

Classes: NotFoundError, ParseError

Constant Summary collapse

CONFIG_PATHS =
[
  '~/.kafkatcfg',
  '/etc/kafkatcfg'
]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ Config

Returns a new instance of Config.



39
40
41
42
43
# File 'lib/kafkat/config.rb', line 39

def initialize(json)
  @kafka_path = json['kafka_path']
  @log_path = json['log_path']
  @zk_path = json['zk_path']
end

Instance Attribute Details

#kafka_pathObject (readonly)

Returns the value of attribute kafka_path.



11
12
13
# File 'lib/kafkat/config.rb', line 11

def kafka_path
  @kafka_path
end

#log_pathObject (readonly)

Returns the value of attribute log_path.



12
13
14
# File 'lib/kafkat/config.rb', line 12

def log_path
  @log_path
end

#zk_pathObject (readonly)

Returns the value of attribute zk_path.



13
14
15
# File 'lib/kafkat/config.rb', line 13

def zk_path
  @zk_path
end

Class Method Details

.load!Object



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

def self.load!
  string = nil
  e = nil

  CONFIG_PATHS.each do |rel_path|
    begin
      path = File.expand_path(rel_path)
      string = File.read(path)
      break
    rescue => e
    end
  end

  raise e if e && string.nil?

  json = JSON.parse(string)
  self.new(json)

rescue Errno::ENOENT
  raise NotFoundError
rescue JSON::JSONError
  raise ParseError
end