module Pliny::CanonicalLogLineHelpers
Helpers
to produce a canonical log line. This mostly amounts to a set of accessors that do basic type checking combined with tracking an internal schema so that we can produce a hash of everything that’s been set so far.
Public Class Methods
included(klass)
click to toggle source
# File lib/pliny/canonical_log_line_helpers.rb, line 20 def self.included(klass) klass.extend(ClassMethods) end
Public Instance Methods
to_h()
click to toggle source
# File lib/pliny/canonical_log_line_helpers.rb, line 24 def to_h @values end
Private Instance Methods
set_field(name, value)
click to toggle source
# File lib/pliny/canonical_log_line_helpers.rb, line 30 def set_field(name, value) type = self.class.instance_variable_get(:@fields)[name] unless type raise ArgumentError, "Field #{name} undefined" end if !value.nil? && !value.is_a?(type) raise ArgumentError, "Expected #{name} to be type #{type} (was #{value.class.name})" end @values ||= {} @values[name] = value end