module Safrano::ExpandHandler
this module has all methods related to expand/defered output preparation and will be included in Service class
Constants
- COUNT_K
- DEFERRED
- EMPTYH
- METADATA_K
- PATH_SPLITTER
- RESULTS_K
default v2 overriden in
ServiceV1
- URI
Public Instance Methods
get_coll_odata_h(array:, template:, icount: nil)
click to toggle source
# File lib/safrano/service.rb, line 30 def get_coll_odata_h(array:, template:, icount: nil) array.map! do |w| get_entity_odata_h(entity: w, template: template) end icount ? { RESULTS_K => array, COUNT_K => icount } : { RESULTS_K => array } end
get_deferred_odata_h(entity_uri:, attrib:)
click to toggle source
# File lib/safrano/service.rb, line 22 def get_deferred_odata_h(entity_uri:, attrib:) { DEFERRED => { URI => "#{entity_uri}/#{attrib}" } } end
get_entity_odata_h(entity:, template:)
click to toggle source
# File lib/safrano/service.rb, line 45 def get_entity_odata_h(entity:, template:) # start with metadata hres = { METADATA_K => entity.metadata_h } template.each do |elmt, arg| case elmt when :all_values hres.merge! entity.casted_values when :selected_vals hres.merge! entity.casted_values(arg) when :expand_e arg.each do |attr, templ| enval = entity.send(attr) hres[attr] = if enval get_entity_odata_h(entity: enval, template: templ) else # FK is NULL --> nav_value is nil --> return empty json EMPTYH end end when :expand_c arg.each do |attr, templ| next unless (encoll = entity.send(attr)) # nav attributes that are a collection (x..n) hres[attr] = get_coll_odata_h(array: encoll, template: templ) # else error ? end when :deferr euri = entity.uri arg.each do |attr| hres[attr] = get_deferred_odata_h(entity_uri: euri, attrib: attr) end end end hres end
get_entity_odata_link_h(entity:)
click to toggle source
handle $links … Note: $expand seems to be ignored when $links are requested
# File lib/safrano/service.rb, line 39 def get_entity_odata_link_h(entity:) { uri: entity.uri } end