module Jat::DSLInstanceMethods

:reek: ModuleInitialize

Attributes

_context[R]

Public Class Methods

new(context = {}, full_map = nil) click to toggle source
# File lib/jat.rb, line 128
def initialize(context = {}, full_map = nil)
  @_context = context.dup
  @_full_map = full_map
end

Public Instance Methods

_copy_to(nested_serializer) click to toggle source
# File lib/jat.rb, line 152
def _copy_to(nested_serializer)
  nested_serializer.().new(_context, _full_map)
end
_full_map() click to toggle source
# File lib/jat.rb, line 156
def _full_map
  @_full_map ||= begin
    params = _context[:params]
    fields = params && (params[:fields] || params['fields'])
    includes = params && (params[:include] || params['include'])
    Map.(self.class, fields, includes)
  end
end
_map() click to toggle source
# File lib/jat.rb, line 165
def _map
  @_map ||= _full_map.fetch(type)
end
_preloads() click to toggle source
# File lib/jat.rb, line 148
def _preloads
  Preloads.new(_full_map).for(self.class)
end
id(object) click to toggle source
# File lib/jat.rb, line 144
def id(object)
  object.id
end
to_h(object, context = {}) click to toggle source
# File lib/jat.rb, line 133
def to_h(object, context = {})
  _reinitialize(context)

  Response.new(self, object).to_h
end
to_str(object, context = {}) click to toggle source
# File lib/jat.rb, line 139
def to_str(object, context = {})
  _reinitialize(context)
  Response.new(self, object).to_str
end

Private Instance Methods

_reinitialize(context) click to toggle source
# File lib/jat.rb, line 171
def _reinitialize(context)
  new_params = context[:params]
  old_params = _context[:params]

  # maps depend on params, so we should clear them when params changed
  if new_params != old_params
    @_full_map = nil
    @_map = nil
  end

  @_context = _context.merge!(context)
end