Class: OpenAPIRest::QueryBuilder
- Inherits:
-
Object
- Object
- OpenAPIRest::QueryBuilder
- Defined in:
- lib/openapi_rest/query_builder.rb
Overview
Rest Query Builder
Instance Attribute Summary collapse
-
#api_model ⇒ Object
readonly
Returns the value of attribute api_model.
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
-
#offset ⇒ Object
readonly
Returns the value of attribute offset.
-
#openapi_path ⇒ Object
readonly
Returns the value of attribute openapi_path.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
-
#sort ⇒ Object
readonly
Returns the value of attribute sort.
Instance Method Summary collapse
- #entity ⇒ Object
-
#initialize(api_model, params) ⇒ QueryBuilder
constructor
A new instance of QueryBuilder.
- #raw_model ⇒ Object
- #resource ⇒ Object
- #response ⇒ Object
- #single_result? ⇒ Boolean (also: #single?)
Constructor Details
#initialize(api_model, params) ⇒ QueryBuilder
Returns a new instance of QueryBuilder.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/openapi_rest/query_builder.rb', line 15 def initialize(api_model, params) @fields = params.fetch(:fields, '') @offset = params.fetch(:offset, 0) @limit = params.fetch(:limit, 10) @sort = params[:sort] @embed = params[:embed] @query = params.fetch(:query, {}) @openapi_path = params.fetch(:openapi_path) @single = params[:operation] == :squery @params = params @api_model = api_model set_fields unless creating? [OpenAPIRest::Operations::Filter.new(self), OpenAPIRest::Operations::Sort.new(self), OpenAPIRest::Operations::Paginate.new(self)].each { |operations| operations.execute } end end |
Instance Attribute Details
#api_model ⇒ Object (readonly)
Returns the value of attribute api_model.
11 12 13 |
# File 'lib/openapi_rest/query_builder.rb', line 11 def api_model @api_model end |
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
10 11 12 |
# File 'lib/openapi_rest/query_builder.rb', line 10 def fields @fields end |
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
8 9 10 |
# File 'lib/openapi_rest/query_builder.rb', line 8 def limit @limit end |
#offset ⇒ Object (readonly)
Returns the value of attribute offset.
9 10 11 |
# File 'lib/openapi_rest/query_builder.rb', line 9 def offset @offset end |
#openapi_path ⇒ Object (readonly)
Returns the value of attribute openapi_path.
13 14 15 |
# File 'lib/openapi_rest/query_builder.rb', line 13 def openapi_path @openapi_path end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
12 13 14 |
# File 'lib/openapi_rest/query_builder.rb', line 12 def params @params end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
6 7 8 |
# File 'lib/openapi_rest/query_builder.rb', line 6 def query @query end |
#sort ⇒ Object (readonly)
Returns the value of attribute sort.
7 8 9 |
# File 'lib/openapi_rest/query_builder.rb', line 7 def sort @sort end |
Instance Method Details
#entity ⇒ Object
50 51 52 |
# File 'lib/openapi_rest/query_builder.rb', line 50 def entity @api_model.type.to_s.downcase.pluralize end |
#raw_model ⇒ Object
54 55 56 |
# File 'lib/openapi_rest/query_builder.rb', line 54 def raw_model @api_model.model end |
#resource ⇒ Object
46 47 48 |
# File 'lib/openapi_rest/query_builder.rb', line 46 def resource entity.to_s.singularize end |
#response ⇒ Object
36 37 38 39 |
# File 'lib/openapi_rest/query_builder.rb', line 36 def response @response ||= OpenAPIRest::QueryResponse.new(self) @response end |
#single_result? ⇒ Boolean Also known as: single?
41 42 43 |
# File 'lib/openapi_rest/query_builder.rb', line 41 def single_result? creating? || @single end |