Sha256: c4dd73a7e6f93777d0033e9fa1cef673e891a666e68851e5f6c92dca46bb86bc
Contents?: true
Size: 1.56 KB
Versions: 29
Compression:
Stored size: 1.56 KB
Contents
module Lutaml module LutamlPath class DocumentWrapper attr_reader :serialized_document, :original_document def initialize(document) @original_document = document end def to_liquid serialized_document end def serialized_document @serialized_document ||= serialize_document(@original_document) end protected def serialize_document(_path) raise ArgumentError, "implement #serialize_document!" end def serialize_value(attr_value) if attr_value.is_a?(Array) return attr_value.map(&method(:serialize_to_hash)) end serialize_to_hash(attr_value) end BASE_OBJECTS = [String, Integer, Float, FalseClass, TrueClass, Symbol, NilClass, Hash] def serialize_to_hash(object) return object if BASE_OBJECTS.include?(object.class) object.instance_variables.each_with_object({}) do |var, res| variable = object.instance_variable_get(var) res[var.to_s.gsub("@", "")] = if variable.is_a?(Array) variable.map do |n| serialize_to_hash(n) end elsif BASE_OBJECTS.include?(variable.class) || var == :@parent variable else serialize_to_hash(variable) end end end end end end
Version data entries
29 entries across 29 versions & 1 rubygems