class Tdc::ExtendedAttributes::DefaultInterpreter

Know how on interpret extended attributes.

Note: extended attribute keys are expected to be strings rather than symbols.

Constants

EXTENDED_ATTRIBUTE_SUFFIX

Public Instance Methods

extended_attribute_context() click to toggle source
# File lib/tdc/extended_attributes/default_interpreter.rb, line 23
def extended_attribute_context
  Time.zone
end
interpret(instance_definition) click to toggle source
# File lib/tdc/extended_attributes/default_interpreter.rb, line 9
def interpret(instance_definition)
  extended_attribute_definitions = keep_extended_attributes(instance_definition)

  extended_attribute_definitions.each do |extended_attribute_key, extended_attribute_value|
    # Remove the extended attribute.
    instance_definition.delete(extended_attribute_key)

    # Add the extended attribute back as a standard attribute.
    instance_definition[convert_to_standard_attribute(extended_attribute_key)] =
      extended_attribute_context.instance_eval(extended_attribute_value)
  end
end

Private Instance Methods

convert_to_standard_attribute(extended_attribute_key) click to toggle source
# File lib/tdc/extended_attributes/default_interpreter.rb, line 32
def convert_to_standard_attribute(extended_attribute_key)
  extended_attribute_key.delete_suffix(EXTENDED_ATTRIBUTE_SUFFIX)
end
extended_attribute?(extended_attribute_key) click to toggle source
# File lib/tdc/extended_attributes/default_interpreter.rb, line 36
def extended_attribute?(extended_attribute_key)
  extended_attribute_key.end_with?(EXTENDED_ATTRIBUTE_SUFFIX)
end
keep_extended_attributes(instance_definition) click to toggle source
# File lib/tdc/extended_attributes/default_interpreter.rb, line 40
def keep_extended_attributes(instance_definition)
  instance_definition.select do |extended_attribute_key, _|
    extended_attribute?(extended_attribute_key)
  end
end