def serializable_hash(options = nil)
options ||= {}
only = Array.wrap(options[:only]).map(&:to_s)
except = Array.wrap(options[:except]).map(&:to_s)
except |= ['_type']
field_names = fields.keys.map { |field| field.to_s }
attribute_names = (attributes.keys + field_names).sort
if only.any?
attribute_names &= only
elsif except.any?
attribute_names -= except
end
method_names = Array.wrap(options[:methods]).map { |n| n.to_s if respond_to?(n.to_s) }.compact
Hash[(attribute_names + method_names).map { |n| [n, send(n)] }].tap do |attrs|
serialize_relations(attrs, options) if options[:include]
end
end