Class: ForestLiana::HasManyGetter

Inherits:
BaseGetter show all
Defined in:
app/services/forest_liana/has_many_getter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseGetter

#get_collection, #get_resource, #includes_for_serialization

Constructor Details

#initialize(resource, association, params) ⇒ HasManyGetter

Returns a new instance of HasManyGetter.



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/services/forest_liana/has_many_getter.rb', line 6

def initialize(resource, association, params)
  @resource = resource
  @association = association
  @params = params
  @collection_name = ForestLiana.name_for(model_association)
  @field_names_requested = field_names_requested
  @collection = get_collection(@collection_name)
  compute_includes()
  includes_symbols = @includes.map { |association| association.to_sym }
  @search_query_builder = SearchQueryBuilder.new(@params, includes_symbols, {}, @collection)

  prepare_query()
end

Instance Attribute Details

#records_countObject (readonly)

Returns the value of attribute records_count.



4
5
6
# File 'app/services/forest_liana/has_many_getter.rb', line 4

def records_count
  @records_count
end

#search_query_builderObject (readonly)

Returns the value of attribute search_query_builder.



3
4
5
# File 'app/services/forest_liana/has_many_getter.rb', line 3

def search_query_builder
  @search_query_builder
end

Instance Method Details

#countObject



25
26
27
# File 'app/services/forest_liana/has_many_getter.rb', line 25

def count
  @records_count = @records.count
end

#performObject



20
21
22
23
# File 'app/services/forest_liana/has_many_getter.rb', line 20

def perform
  @records = search_query
  @records = sort_query
end

#query_for_batchObject



33
34
35
# File 'app/services/forest_liana/has_many_getter.rb', line 33

def query_for_batch
  @records
end

#recordsObject



37
38
39
# File 'app/services/forest_liana/has_many_getter.rb', line 37

def records
  @records.limit(limit).offset(offset)
end

#search_queryObject



29
30
31
# File 'app/services/forest_liana/has_many_getter.rb', line 29

def search_query
  @search_query_builder.perform(@records)
end