Module: Maxwell::Agent::Coercable
- Included in:
- Host::Serializer, Host::Service::Serializer
- Defined in:
- lib/maxwell/agent/coercable.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(base) ⇒ Object
4 5 6 7 |
# File 'lib/maxwell/agent/coercable.rb', line 4 def self.included(base) base.extend ClassMethods base.instance_variable_set('@coercions', {}) end |
Instance Method Details
#coerce_value(key, value) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/maxwell/agent/coercable.rb', line 17 def coerce_value(key, value) coercion_class = self.class.coercions[key] case when coercion_class.is_a?(Proc) then coercion_class.call(value) else coercion_class.new(value) end end |
#coerce_values!(attrs) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/maxwell/agent/coercable.rb', line 10 def coerce_values!(attrs) attrs.each do |key, value| attrs[key] = coerce_value(key, value) if self.class.coercions[key] end attrs end |