Class: Kafkat::Config
- Inherits:
-
Object
- Object
- Kafkat::Config
- Defined in:
- lib/kafkat/config.rb
Defined Under Namespace
Classes: NotFoundError, ParseError
Constant Summary collapse
- CONFIG_PATHS =
[ '~/.kafkatcfg', '/etc/kafkatcfg' ]
Instance Attribute Summary collapse
-
#json_files_path ⇒ Object
readonly
Returns the value of attribute json_files_path.
-
#kafka_path ⇒ Object
readonly
Returns the value of attribute kafka_path.
-
#log_path ⇒ Object
readonly
Returns the value of attribute log_path.
-
#zk_path ⇒ Object
readonly
Returns the value of attribute zk_path.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(json) ⇒ Config
constructor
A new instance of Config.
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_path ⇒ Object (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_path ⇒ Object (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_path ⇒ Object (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_path ⇒ Object (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.(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 |