Module: Encore::Serializer::LinksReflectionIncluder::NotLoaded

Defined in:
lib/encore/serializer/links_reflection_includer.rb

Class Method Summary collapse

Class Method Details

.reflection_belongs_to(object, reflection) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/encore/serializer/links_reflection_includer.rb', line 38

def self.reflection_belongs_to(object, reflection)
  reflection_type = plural_path(reflection.klass)
  reflection_id = object.send(reflection.foreign_key).try(:to_s)

  return nil if reflection_id.blank?

  {
    href: "/#{reflection_type}/#{reflection_id}",
    id: reflection_id,
    type: reflection_type
  }
end

.reflection_has_many(object, reflection) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/encore/serializer/links_reflection_includer.rb', line 19

def self.reflection_has_many(object, reflection)
  reflection_type = plural_path(reflection.klass)

  {
    href: "/#{reflection_type}?#{object.class.name.underscore}_id=#{object.id}",
    type: reflection_type
  }
end

.reflection_has_one(object, reflection) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/encore/serializer/links_reflection_includer.rb', line 28

def self.reflection_has_one(object, reflection)
  root_type = plural_path(object.class)
  reflection_type = singular_path(reflection.klass)

  {
    href: "/#{root_type}/#{object.id}/#{reflection_type}",
    type: reflection_type.pluralize
  }
end