module Maxwell::Agent::Coercable
Public Class Methods
included(base)
click to toggle source
# File lib/maxwell/agent/coercable.rb, line 4 def self.included(base) base.extend ClassMethods base.instance_variable_set('@coercions', {}) end
Public Instance Methods
coerce_value(key, value)
click to toggle source
# 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)
click to toggle source
# 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