Class: Safrano::FilterByParse

Inherits:
FilterBase show all
Defined in:
lib/odata/collection_filter.rb

Overview

should handle everything by parsing

Constant Summary

Constants inherited from FilterBase

Safrano::FilterBase::EmptyFilter

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from FilterBase

factory

Constructor Details

#initialize(filterstr) ⇒ FilterByParse

Returns a new instance of FilterByParse.



40
41
42
43
# File 'lib/odata/collection_filter.rb', line 40

def initialize(filterstr)
  @filterstr = filterstr.dup
  @ast = Safrano::Filter::Parser.new(@filterstr).build
end

Instance Attribute Details

#filterstrObject (readonly)

Returns the value of attribute filterstr.



38
39
40
# File 'lib/odata/collection_filter.rb', line 38

def filterstr
  @filterstr
end

Instance Method Details

#apply_to_dataset(dtcx) ⇒ Object



53
54
55
56
# File 'lib/odata/collection_filter.rb', line 53

def apply_to_dataset(dtcx)
  #     normally finalize is called before, and thus @filtexpr is set
  @filtexpr.map_result! { |f| dtcx.where(f) }
end

#empty?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/odata/collection_filter.rb', line 66

def empty?
  false
end

#finalize(jh) ⇒ Object

this build’s up the Sequel Filter Expression, and as a side effect, it also finalizes the join helper that we need for the start dataset join the join-helper is shared by the order-by object and was potentially already partly built on order-by object creation.



49
50
51
# File 'lib/odata/collection_filter.rb', line 49

def finalize(jh)
  @filtexpr = @ast.if_valid { |ast| ast.sequel_expr(jh) }
end

#parse_error?Boolean

Note: this is really only parse error, ie the error encounterd while trying to build the AST Later when evaluating the AST, there can be other errors, they shall be tracked with @error

Returns:

  • (Boolean)


62
63
64
# File 'lib/odata/collection_filter.rb', line 62

def parse_error?
  @ast.error
end