Class: ErpIntegration::Fulfil::WhereClause
- Inherits:
-
Object
- Object
- ErpIntegration::Fulfil::WhereClause
- Defined in:
- lib/erp_integration/fulfil/where_clause.rb
Overview
The ‘WhereClause` model encapsulates the logic for the filter options for Fulfil. It transforms the attributes passed to any of the where lookup methods into a format that Fulfil can actually understand.
For more information, see their documentation. developers.fulfil.io/guides/searching-filtering/#field-filter-expressions
Constant Summary collapse
- COMPARISON_OPERATORS =
[ '=', '!=', '<', '<=', '>=', '>', 'like', 'ilike', 'in', 'not in' ].freeze
- DEFAULT_COMPARISON_OPERATOR =
'='
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
The ‘===` allows comparing different WhereClause objects.
-
#hash ⇒ Fixnum
The ‘.hash` allows comparing two `WhereClause` instances for uniqueness.
-
#initialize(key:, value:, domain: nil, comparison_operator: DEFAULT_COMPARISON_OPERATOR) ⇒ WhereClause
constructor
A new instance of WhereClause.
-
#to_filter ⇒ Array<String>
Transforms the ‘WhereClause` into a filter object for Fulfil.
Constructor Details
#initialize(key:, value:, domain: nil, comparison_operator: DEFAULT_COMPARISON_OPERATOR) ⇒ WhereClause
Returns a new instance of WhereClause.
33 34 35 36 37 38 |
# File 'lib/erp_integration/fulfil/where_clause.rb', line 33 def initialize(key:, value:, domain: nil, comparison_operator: DEFAULT_COMPARISON_OPERATOR) @comparison_operator = verify_comparison_operator(comparison_operator) @key = key.to_s @value = to_extended_query_value(value) @domain = domain end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
The ‘===` allows comparing different WhereClause objects. Under the hood, this is used by `.uniq` to determine whether objects are equal to each other.
Note: ‘.uniq` also depends on `.hash` on the `WhereClause` instance. See the `.hash` method to see how the two objects are compared.
64 65 66 |
# File 'lib/erp_integration/fulfil/where_clause.rb', line 64 def ==(other) to_filter == other.to_filter end |
#hash ⇒ Fixnum
The ‘.hash` allows comparing two `WhereClause` instances for uniqueness. See rubyapi.org/2.3/o/object#method-i-hash
72 73 74 |
# File 'lib/erp_integration/fulfil/where_clause.rb', line 72 def hash to_filter.hash end |
#to_filter ⇒ Array<String>
Transforms the ‘WhereClause` into a filter object for Fulfil.
42 43 44 |
# File 'lib/erp_integration/fulfil/where_clause.rb', line 42 def to_filter [@key, @comparison_operator, @value, @domain].compact end |