Class: OpenAPIRest::QueryBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/openapi_rest/query_builder.rb

Overview

Rest Query Builder

Instance Attribute Summary collapse

Instance Method Summary collapse

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_modelObject (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

#fieldsObject (readonly)

Returns the value of attribute fields.



10
11
12
# File 'lib/openapi_rest/query_builder.rb', line 10

def fields
  @fields
end

#limitObject (readonly)

Returns the value of attribute limit.



8
9
10
# File 'lib/openapi_rest/query_builder.rb', line 8

def limit
  @limit
end

#offsetObject (readonly)

Returns the value of attribute offset.



9
10
11
# File 'lib/openapi_rest/query_builder.rb', line 9

def offset
  @offset
end

#openapi_pathObject (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

#paramsObject (readonly)

Returns the value of attribute params.



12
13
14
# File 'lib/openapi_rest/query_builder.rb', line 12

def params
  @params
end

#queryObject (readonly)

Returns the value of attribute query.



6
7
8
# File 'lib/openapi_rest/query_builder.rb', line 6

def query
  @query
end

#sortObject (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

#entityObject



50
51
52
# File 'lib/openapi_rest/query_builder.rb', line 50

def entity
  @api_model.type.to_s.downcase.pluralize
end

#raw_modelObject



54
55
56
# File 'lib/openapi_rest/query_builder.rb', line 54

def raw_model
  @api_model.model
end

#resourceObject



46
47
48
# File 'lib/openapi_rest/query_builder.rb', line 46

def resource
  entity.to_s.singularize
end

#responseObject



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?

Returns:

  • (Boolean)


41
42
43
# File 'lib/openapi_rest/query_builder.rb', line 41

def single_result?
  creating? || @single
end