lib/maglev/serialization/serializer.rb
# used to map a relation (either a collection or single item) and build its partial.
# This method provides the includeable option as a convienence to having to wrap
# relations within includable blocks.
# The permission option is used to call `user_can!(permission)` - most useful for when
# includable is used, since this enforcement will only be applied IF the inclusion was requested.
# default can be passed in, which will be used in place of a missing value
used to map a relation (either a collection or single item) and build its partial.
This method provides the includeable option as a convienence to having to wrap
relations within includable blocks.
The permission option is used to call `user_can!(permission)` - most useful for when
includable is used, since this enforcement will only be applied IF the inclusion was requested.
default can be passed in, which will be used in place of a missing value
used to map a relation ( either a collection or single item ) and build its partial . This method provides the includeable option as a convienence to having to wrap relations within includable blocks . The permission option is used to call ` user_can! ( permission ) ` - most useful for when includable is used since this enforcement will only be applied IF the inclusion was requested . default can be passed in which will be used in place of a missing value
def relation(name, includable: false, serializer: nil, value: nil, allow_nil: false,
                 default: nil, permission: nil, order_by: nil, model: self.model, &block)
      current_pathname = join_namespace(@namespace, name)
      if includable
        return unless includable?(current_pathname)
        return if block_given? and !block.call
      end
      user_can!(permission) if permission
      value ||= model.try(name) || default
      if value.is_a?(Proc)
        value = value.arity > 0 ? value.call(model) : value.call
      end
      value = value.order_by(order_by) if order_by and value.respond_to?(:order_by)
      if value
        if value.respond_to?(:each)
          builder.set!(name, array(value, serializer, current_pathname))
        else
          builder.set!(name, partial(value, serializer, current_pathname))
        end
      elsif include_nil and allow_nil
        builder.set!(name, nil)
      end
    end
def relation ( name , includable : false , serializer : nil , value : nil , allow_nil : false , default : nil , permission : nil , order_by : nil , model : self . model , & block ) current_pathname = join_namespace ( @namespace , name ) if includable return unless includable? ( current_pathname ) return if block_given? and ! block . call end user_can! ( permission ) if permission value ||= model . try ( name ) || default if value . is_a? ( Proc ) value = value . arity > 0 ? value . call ( model ) : value . call end value = value . order_by ( order_by ) if order_by and value . respond_to? ( :order_by ) if value if value . respond_to? ( :each ) builder . set! ( name , array ( value , serializer , current_pathname ) ) else builder . set! ( name , partial ( value , serializer , current_pathname ) ) end elsif include_nil and allow_nil builder . set! ( name , nil ) end end
used to map a relation (either a collection or single item) and build its partial.
used to map a relation ( either a collection or single item ) and build its partial .
# early return if this includable relationship wasn't requested # early return if this includable relationship was cancelled by the lazy permission check # allow a proc to be passed in, which can be used to lazy load the value
name
<not_specific>
includable
<not_specific>
serializer
<not_specific>
value
<not_specific>
allow_nil
<not_specific>
default
<not_specific>
permission
<not_specific>
order_by
<not_specific>
model
<not_specific>
block
<not_specific>