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.



40
41
42
43
44
45
46
47
48
# File 'lib/kafkat/config.rb', line 40

def initialize(json)
  @kafka_path = json['kafka_path']
  @log_path = json['log_path']
  @zk_path = json['zk_path']
  @json_files_path = json['json_files_path']
  if !@json_files_path || !File.exist?(@json_files_path)
    raise ArgumentError, "The directory \"json_files_path\": \"#{@json_files_path}\" does not exit."
  end
end

Instance Attribute Details

#json_files_pathObject (readonly)

Returns the value of attribute json_files_path.



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

def json_files_path
  @json_files_path
end

#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



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

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