Class: SimpleJsonapi::Node::ObjectLinks
- Inherits:
-
Base
- Object
- Base
- SimpleJsonapi::Node::ObjectLinks
show all
- Defined in:
- lib/simple_jsonapi/node/object_links.rb
Overview
Represents a links object (a collection of links).
Instance Attribute Summary collapse
Attributes inherited from Base
#extras, #fields_spec, #include_spec, #root_node, #serializer, #serializer_inferrer, #sort_spec
Instance Method Summary
collapse
Constructor Details
#initialize(object:, link_definitions:, **options) ⇒ ObjectLinks
14
15
16
17
18
19
|
# File 'lib/simple_jsonapi/node/object_links.rb', line 14
def initialize(object:, link_definitions:, **options)
super(options)
@object = object
@link_definitions = link_definitions
end
|
Instance Attribute Details
#link_definitions ⇒ Hash{Symbol => Definition::Link}
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/simple_jsonapi/node/object_links.rb', line 8
class ObjectLinks < Base
attr_reader :object, :link_definitions
def initialize(object:, link_definitions:, **options)
super(options)
@object = object
@link_definitions = link_definitions
end
def as_jsonapi
if link_definitions_to_render.any?
json = {}
link_definitions_to_render.each do |name, defn|
json[name] = evaluate(defn.value_proc, object)
end
{ links: json }
else
{}
end
end
private
def link_definitions_to_render
@link_definitions_to_render ||= link_definitions.select { |_, defn| render?(defn, object) }
end
end
|
#object ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/simple_jsonapi/node/object_links.rb', line 8
class ObjectLinks < Base
attr_reader :object, :link_definitions
def initialize(object:, link_definitions:, **options)
super(options)
@object = object
@link_definitions = link_definitions
end
def as_jsonapi
if link_definitions_to_render.any?
json = {}
link_definitions_to_render.each do |name, defn|
json[name] = evaluate(defn.value_proc, object)
end
{ links: json }
else
{}
end
end
private
def link_definitions_to_render
@link_definitions_to_render ||= link_definitions.select { |_, defn| render?(defn, object) }
end
end
|
Instance Method Details
#as_jsonapi ⇒ Hash{Symbol => Hash}
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/simple_jsonapi/node/object_links.rb', line 22
def as_jsonapi
if link_definitions_to_render.any?
json = {}
link_definitions_to_render.each do |name, defn|
json[name] = evaluate(defn.value_proc, object)
end
{ links: json }
else
{}
end
end
|