module HalApi::Representer::Embeds::HalApiRailsRenderPipeline
Public Instance Methods
embed_zoomed?(name, zoom_def = nil, zoom_param = nil)
click to toggle source
# File lib/hal_api/representer/embeds.rb, line 47 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
render_functions()
click to toggle source
Calls superclass method
# File lib/hal_api/representer/embeds.rb, line 19 def render_functions funcs = super f = ->(input, options) do if suppress_embed?(input, options) return Representable::Pipeline::Stop end end [f] + funcs end
skip_property?(binding, private_options)
click to toggle source
Calls superclass method
# File lib/hal_api/representer/embeds.rb, line 15 def skip_property?(binding, private_options) super(binding, private_options) || suppress_embed?(binding, private_options) end
suppress_embed?(input, options)
click to toggle source
embed if zoomed
# File lib/hal_api/representer/embeds.rb, line 30 def suppress_embed?(input, options) binding = options[:binding] # guard against non-hal representers return false unless binding[:as].present? name = binding.evaluate_option(:as, input, options) embedded = binding[:embedded] return false if !embedded ## check if it should be zoomed, suppress if not user_zooms = options[:options].try(:[], :user_options).try(:[], :zoom) !embed_zoomed?(name, binding[:zoom], user_zooms) end