Class: KafkaCommand::Configuration
- Inherits:
-
Object
- Object
- KafkaCommand::Configuration
- Defined in:
- lib/kafka_command/configuration.rb
Constant Summary collapse
- HOST_REGEX =
/[^\:]+:[0-9]{1,5}/
- CLUSTER_KEYS =
%w( protocol description version seed_brokers ssl_ca_cert ssl_ca_cert_file_path ssl_client_cert ssl_client_cert_file_path ssl_client_cert_key ssl_client_cert_key_file_path sasl_scram_username sasl_scram_password socket_timeout connect_timeout )
Instance Attribute Summary collapse
-
#clusters ⇒ Object
readonly
Returns the value of attribute clusters.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(config_hash) ⇒ Configuration
constructor
A new instance of Configuration.
- #invalid? ⇒ Boolean
- #valid? ⇒ Boolean
Constructor Details
#initialize(config_hash) ⇒ Configuration
Returns a new instance of Configuration.
34 35 36 37 38 |
# File 'lib/kafka_command/configuration.rb', line 34 def initialize(config_hash) @config = config_hash[ENV['RAILS_ENV']] @clusters = config['clusters'] if config.present? @errors = [] end |
Instance Attribute Details
#clusters ⇒ Object (readonly)
Returns the value of attribute clusters.
15 16 17 |
# File 'lib/kafka_command/configuration.rb', line 15 def clusters @clusters end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
15 16 17 |
# File 'lib/kafka_command/configuration.rb', line 15 def config @config end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
15 16 17 |
# File 'lib/kafka_command/configuration.rb', line 15 def errors @errors end |
Class Method Details
.load!(file_path) ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/kafka_command/configuration.rb', line 60 def self.load!(file_path) KafkaCommand.config = parse_yaml(file_path) if KafkaCommand.config.invalid? puts "KafkaCommand improperly configured. #{KafkaCommand.config.errors}" end end |
.parse_yaml(file_path) ⇒ Object
56 57 58 |
# File 'lib/kafka_command/configuration.rb', line 56 def self.parse_yaml(file_path) YAML.load(ERB.new(File.read(file_path)).result(binding)) end |
Instance Method Details
#invalid? ⇒ Boolean
52 53 54 |
# File 'lib/kafka_command/configuration.rb', line 52 def invalid? !valid? end |
#valid? ⇒ Boolean
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/kafka_command/configuration.rb', line 40 def valid? @errors = [] if config.blank? errors << 'No config specified for environment' return false end validate! errors.none? end |