Module: HalApi::Representer::Embeds::Resources

Defined in:
lib/hal_api/representer/embeds.rb

Instance Method Summary collapse

Instance Method Details

#embed_zoomed?(name, zoom_def = nil, zoom_param = nil) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/hal_api/representer/embeds.rb', line 31

def embed_zoomed?(name, zoom_def=nil, zoom_param=nil)
  # if the embed in the representer definition has `zoom: :always` defined
  # always embed it, even if it is in another embed
  # (this is really meant for collections where embedded items must be included)
  return true if zoom_def == :always

  # passing nil explicitly overwrites defaults in signature,
  # so we default to nil and fix in the method body
  zoom_def = true if zoom_def.nil?

  # if there is no zoom specified in the request params (options)
  # then embed based on the zoom option in the representer definition

  # if there is a zoom specified in the request params (options)
  # then do not zoom when this name is not in the request
  zoom_param.nil? ? zoom_def : zoom_param.include?(name)
end

#skip_property?(binding, options) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/hal_api/representer/embeds.rb', line 15

def skip_property?(binding, options)
  super(binding, options) || suppress_embed?(binding, options)
end

#suppress_embed?(binding, options) ⇒ Boolean

embed if zoomed

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
28
29
# File 'lib/hal_api/representer/embeds.rb', line 20

def suppress_embed?(binding, options)
  name     = (binding[:as] || binding.name).to_s
  embedded = !!binding[:embedded]

  # not embedded, return false - nothing to suppress
  return false if !embedded

  # check if it should be zoomed, suppress if not
  !embed_zoomed?(name, binding[:zoom], options[:zoom])
end