class Safrano::MultiExpand

Multi expanding logic

Constants

COMASPLIT

Attributes

template[R]

Public Class Methods

new(expandstr, model) click to toggle source

Note: if you change this method, please also update arity_full_monkey?

see below
# File lib/odata/expand.rb, line 87
def initialize(expandstr, model)
  expandstr.strip!
  @model = model
  @expandp = expandstr

  @exstrlist = expandstr.split(COMASPLIT)
  @exlist = @exstrlist.map { |exstr| Expand.new(exstr) }
  build_template
end

Public Instance Methods

apply_to_dataset(dtcx) click to toggle source
# File lib/odata/expand.rb, line 97
def apply_to_dataset(dtcx)
  # use eager loading for each used association
  @exlist.each { |exp| dtcx = dtcx.eager(exp.arg) }
  Contract.valid(dtcx)
end
build_template() click to toggle source
# File lib/odata/expand.rb, line 103
def build_template
  #   'a/b/c/d,xy'  ==> [ {'a' =>{ 'b' => {'c' => {'d' => {} } }}},
  #                       { 'xy' => {} }]
  #
  @template = @exlist.map(&:template)

  # { 'a'  => { 'b' => {'c' => 'd' }},
  #   'xy' => {} }
  @template = @template.inject({}) { |mrg, elmt| mrg.merge elmt }
end
empty?() click to toggle source
# File lib/odata/expand.rb, line 122
def empty?
  false
end
parse_error?() click to toggle source
# File lib/odata/expand.rb, line 114
def parse_error?
  @exstrlist.each do |expstr|
    return BadRequestExpandInvalidPath.new(@model, expstr) unless @model.expand_path_valid? expstr
  end

  Contract::OK
end