class Safrano::UrlParameters4Coll
url parameters for a collection expand/select + filter/order
Attributes
filt[R]
ordby[R]
Public Class Methods
new(dataset, params = {})
click to toggle source
Calls superclass method
Safrano::UrlParametersBase::new
# File lib/odata/url_parameters.rb, line 56 def initialize(dataset, params = {}) super # join helper is only needed for odering or filtering @jh = @model.join_by_paths_helper if params['$orderby'] || params['$filter'] @params = params @ordby = OrderBase.factory(@params['$orderby'], @jh) @filt = FilterBase.factory(@params['$filter']) @expand = ExpandBase.factory(@params['$expand'], @model) @select = SelectBase.factory(@params['$select'], @model) end
Public Instance Methods
apply_expand_to_dataset(dtcx)
click to toggle source
# File lib/odata/url_parameters.rb, line 104 def apply_expand_to_dataset(dtcx) return Contract.valid(dtcx) if @expand.empty? @expand.apply_to_dataset(dtcx) end
apply_filter_order_to_dataset(dtcx)
click to toggle source
Warning, the @ordby and @filt objects are coupled by way of the join helper
# File lib/odata/url_parameters.rb, line 111 def apply_filter_order_to_dataset(dtcx) return Contract.valid(dtcx) if @filt.empty? && @ordby.empty? # filter object and join-helper need to be finalized after filter # has been parsed and checked @filt.finalize(@jh).if_valid do # start with the join dtcx = @jh.dataset(dtcx) @filt.apply_to_dataset(dtcx).map_result! do |dataset| dtcx = dataset dtcx = @ordby.apply_to_dataset(dtcx) dtcx.select_all(@jh.start_model.table_name) end end end
apply_to_dataset(dtcx)
click to toggle source
# File lib/odata/url_parameters.rb, line 98 def apply_to_dataset(dtcx) apply_expand_to_dataset(dtcx).if_valid do |dataset| apply_filter_order_to_dataset(dataset) end end
check_all()
click to toggle source
# File lib/odata/url_parameters.rb, line 129 def check_all return Contract::OK unless @params # lazy nested proc evaluation. # if one check fails, it will be passed up the chain and the ones # below will not be evaluated check_top.if_valid do check_skip.if_valid do check_orderby.if_valid do check_filter.if_valid do check_expand.if_valid do check_select.if_valid do check_inlinecount end end end end end end end
check_filter()
click to toggle source
# File lib/odata/url_parameters.rb, line 87 def check_filter (err = @filt.parse_error?) ? err : Contract::OK end
check_inlinecount()
click to toggle source
# File lib/odata/url_parameters.rb, line 81 def check_inlinecount return Contract::OK unless (icp = @params['$inlinecount']) ((icp == 'allpages') || (icp == 'none')) ? Contract::OK : BadRequestInlineCountParamError end
check_orderby()
click to toggle source
# File lib/odata/url_parameters.rb, line 91 def check_orderby return Contract::OK if @ordby.empty? return BadRequestOrderParseError if @ordby.parse_error? Contract::OK end
check_skip()
click to toggle source
# File lib/odata/url_parameters.rb, line 74 def check_skip return Contract::OK unless @params['$skip'] iskip = number_or_nil(@params['$skip']) (iskip.nil? || iskip.negative?) ? BadRequestError : Contract::OK end
check_top()
click to toggle source
# File lib/odata/url_parameters.rb, line 67 def check_top return Contract::OK unless @params['$top'] itop = number_or_nil(@params['$top']) (itop.nil? || itop.zero?) ? BadRequestError : Contract::OK end