Class: Karafka::Admin::Configs::Resource
- Inherits:
-
Object
- Object
- Karafka::Admin::Configs::Resource
- Defined in:
- lib/karafka/admin/configs/resource.rb
Overview
Represents a single resource in the context of configuration management
Instance Attribute Summary collapse
-
#configs ⇒ Object
readonly
Returns the value of attribute configs.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #initialize(type:, name:) ⇒ Resource constructor
-
#to_native_hash ⇒ Hash
Resource converted to a hash that rdkafka can work with.
Constructor Details
#initialize(type:, name:) ⇒ Resource
31 32 33 34 35 36 37 38 |
# File 'lib/karafka/admin/configs/resource.rb', line 31 def initialize(type:, name:) @type = map_type(type) @name = name.to_s @configs = [] @operations = Hash.new { |h, k| h[k] = [] } freeze end |
Instance Attribute Details
#configs ⇒ Object (readonly)
Returns the value of attribute configs.
26 27 28 |
# File 'lib/karafka/admin/configs/resource.rb', line 26 def configs @configs end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
26 27 28 |
# File 'lib/karafka/admin/configs/resource.rb', line 26 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
26 27 28 |
# File 'lib/karafka/admin/configs/resource.rb', line 26 def type @type end |
Instance Method Details
#to_native_hash ⇒ Hash
Note:
Configs include the operation type and are expected to be used only for the incremental alter API.
Returns resource converted to a hash that rdkafka can work with.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/karafka/admin/configs/resource.rb', line 55 def to_native_hash configs_with_operations = [] @operations.each do |op_type, configs| configs.each do |config| configs_with_operations << config.to_native_hash.merge(op_type: op_type) end end { resource_type: RESOURCE_TYPES_MAP.fetch(type), resource_name: name, configs: configs_with_operations }.freeze end |