Sha256: 86f047bda24d56a46b917680566af89b285e3ef89e2e3372f53a7fed7a9e572d
Contents?: true
Size: 961 Bytes
Versions: 7
Compression:
Stored size: 961 Bytes
Contents
# frozen_string_literal: true require 'json/ext' # module Mutils module Mutils module Serialization # BaseSerializer: inherit this class to get Serializer functionality class BaseSerializer attr_reader :scope include Mutils::Serialization::SerializationIncludes include Mutils::Serialization::SerializationMethods include Mutils::Serialization::SerializationResults def initialize(object, options = {}) options[:child] = false unless options[:child] self.scope = object self.options = options end def as_json(_options = {}) if options[:child] || !self.class.include_root to_h else { class_name => to_h } end end def to_h generate_hash end def to_json(_options = {}) JSON.generate(as_json, options) end private attr_writer :scope attr_accessor :options end end end
Version data entries
7 entries across 7 versions & 1 rubygems