class MetaModel::MetaModelSerializer
Public Class Methods
new(*args, &block)
click to toggle source
Calls superclass method
# File lib/meta_model/meta_model_serializer.rb, line 8 def initialize *args, &block super args.first.setup_serializer(self) end
Public Instance Methods
_type()
click to toggle source
# File lib/meta_model/meta_model_serializer.rb, line 4 def _type object.type.pluralize end
associations(include_tree = DEFAULT_INCLUDE_TREE, include_slice = nil)
click to toggle source
# File lib/meta_model/meta_model_serializer.rb, line 24 def associations(include_tree = DEFAULT_INCLUDE_TREE, include_slice = nil) include_slice ||= include_tree return unless object Enumerator.new do |y| self.singleton_class._reflections.each do |reflection| next if reflection.excluded?(self) key = reflection.options.fetch(:key, reflection.name) next unless include_tree.key?(key) y.yield reflection.build_association(self, instance_options, include_slice) end end end
attributes(requested_attrs = nil, reload = false)
click to toggle source
Return the attributes
of object
as presented by the serializer.
# File lib/meta_model/meta_model_serializer.rb, line 15 def attributes(requested_attrs = nil, reload = false) @attributes = nil if reload @attributes ||= self.singleton_class._attributes_data.each_with_object({}) do |(key, attr), hash| next if attr.excluded?(self) next unless requested_attrs.nil? || requested_attrs.include?(key) hash[key] = object.send(key) end end