Sha256: dc54a09e954e0b13c6e452362ec2ff980ac826a66eb7b90ad69ba4f619dc282b
Contents?: true
Size: 778 Bytes
Versions: 6
Compression:
Stored size: 778 Bytes
Contents
require 'active_support/core_ext/module/delegation' module Upholsterer class Base delegate :to_json, :as_json, to: :to_hash, prefix: false def self.serializable(*args) args.each do |method_name| attributes[method_name.to_sym] = [method_name.to_sym, { serializable: true }] end end def to_hash Hash[json_fields.collect do |field| [field, public_send(field)] end] end alias :to_h :to_hash private def json_fields @json_fields ||= begin methods = public_methods(false).tap do |fields| fields.delete(:subject) fields.delete(:respond_to?) fields.delete(:method_missing) end (methods + self.class.attributes.keys).uniq end end end end
Version data entries
6 entries across 6 versions & 1 rubygems