Class: ErpIntegration::Fulfil::Query
- Inherits:
-
Object
- Object
- ErpIntegration::Fulfil::Query
- Defined in:
- lib/erp_integration/fulfil/query.rb
Overview
The ‘Query` class transforms where clauses and included fields into a queryable object that Fulfil understands.
The instance of the ‘Query` class is meant to be passed to `Faraday` or a third-party vendor client (e.g. `Fulfil::Client`) that uses `Faraday`.
‘Faraday` will call the `.to_json` method before sending the data to Fulfil. So, there is no need to explicitly call `.to_json` on the `Query` instance.
Constant Summary collapse
- DEFAULT_FIELDS =
%w[id].freeze
Instance Attribute Summary collapse
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#filters ⇒ Object
readonly
Returns the value of attribute filters.
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
-
#offset ⇒ Object
readonly
Returns the value of attribute offset.
Instance Method Summary collapse
-
#initialize(fields:, filters:, alternative_filters: [], offset: nil, limit: nil) ⇒ Query
constructor
A new instance of Query.
- #to_h ⇒ Object
Constructor Details
#initialize(fields:, filters:, alternative_filters: [], offset: nil, limit: nil) ⇒ Query
Returns a new instance of Query.
32 33 34 35 36 37 38 |
# File 'lib/erp_integration/fulfil/query.rb', line 32 def initialize(fields:, filters:, alternative_filters: [], offset: nil, limit: nil) @fields = (fields || DEFAULT_FIELDS).map(&:to_s).uniq @filters = (filters || []).map(&:to_filter).uniq @filters += alternative_filters.map(&:to_filter).uniq if alternative_filters&.any? @offset = offset @limit = limit end |
Instance Attribute Details
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
23 24 25 |
# File 'lib/erp_integration/fulfil/query.rb', line 23 def fields @fields end |
#filters ⇒ Object (readonly)
Returns the value of attribute filters.
23 24 25 |
# File 'lib/erp_integration/fulfil/query.rb', line 23 def filters @filters end |
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
23 24 25 |
# File 'lib/erp_integration/fulfil/query.rb', line 23 def limit @limit end |
#offset ⇒ Object (readonly)
Returns the value of attribute offset.
23 24 25 |
# File 'lib/erp_integration/fulfil/query.rb', line 23 def offset @offset end |
Instance Method Details
#to_h ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/erp_integration/fulfil/query.rb', line 40 def to_h {}.tap do |hash| hash[:fields] = @fields hash[:filters] = @filters hash[:limit] = @limit if @limit hash[:offset] = @offset if @offset end end |