Class: FrederickAPI::V2::Helpers::QueryBuilder
- Inherits:
-
JsonApiClient::Query::Builder
- Object
- JsonApiClient::Query::Builder
- FrederickAPI::V2::Helpers::QueryBuilder
- Defined in:
- lib/frederick_api/v2/helpers/query_builder.rb
Overview
Used to convert nested params to dot notation for Frederick API
Instance Attribute Summary collapse
-
#requestor ⇒ Object
readonly
Returns the value of attribute requestor.
Instance Method Summary collapse
- #all_records ⇒ Object
- #filter_params ⇒ Object
-
#initialize(klass, opts = {}) ⇒ QueryBuilder
constructor
A new instance of QueryBuilder.
- #params ⇒ Object
- #to_dot_params(object, prefix = nil) ⇒ Object
Constructor Details
#initialize(klass, opts = {}) ⇒ QueryBuilder
Returns a new instance of QueryBuilder.
12 13 14 15 |
# File 'lib/frederick_api/v2/helpers/query_builder.rb', line 12 def initialize(klass, opts = {}) super(klass, opts) @requestor = opts[:requestor] || klass.requestor end |
Instance Attribute Details
#requestor ⇒ Object (readonly)
Returns the value of attribute requestor.
10 11 12 |
# File 'lib/frederick_api/v2/helpers/query_builder.rb', line 10 def requestor @requestor end |
Instance Method Details
#all_records ⇒ Object
38 39 40 |
# File 'lib/frederick_api/v2/helpers/query_builder.rb', line 38 def all_records self.all.pages.all_records end |
#filter_params ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/frederick_api/v2/helpers/query_builder.rb', line 26 def filter_params super_filter_params = super if (filters = super_filter_params[:filter]) filters.each do |filter_name, filter_val| filters[filter_name] = filter_val.join(',') if filter_val.is_a?(Array) end end super_filter_params end |
#params ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/frederick_api/v2/helpers/query_builder.rb', line 17 def params to_dot_params( filter_params.merge(pagination_params.merge(includes_params).merge(select_params)) ).merge(order_params) .merge(primary_key_params) .merge(path_params) .merge(additional_params) end |
#to_dot_params(object, prefix = nil) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/frederick_api/v2/helpers/query_builder.rb', line 42 def to_dot_params(object, prefix = nil) return {} if object == {} if object.is_a? Hash object.map do |key, value| if prefix to_dot_params value, "#{prefix}.#{key}" else to_dot_params value, key.to_s end end.reduce(&:merge) else { prefix => object } end end |