Class: ForestLiana::StatGetter

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseGetter

#get_collection, #includes_for_serialization

Constructor Details

#initialize(resource, params, forest_user) ⇒ StatGetter

Returns a new instance of StatGetter.



5
6
7
8
9
10
11
12
# File 'app/services/forest_liana/stat_getter.rb', line 5

def initialize(resource, params, forest_user)
  @resource = resource
  @params = params
  @user = forest_user

  validate_params
  compute_includes
end

Instance Attribute Details

#recordObject

Returns the value of attribute record.



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

def record
  @record
end

Instance Method Details

#get_resourceObject



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

def get_resource
  super
  @resource.reorder('')
end

#validate_paramsObject



14
15
16
17
18
# File 'app/services/forest_liana/stat_getter.rb', line 14

def validate_params
  if @params.key?(:aggregator) && !%w[count sum avg max min].include?(@params[:aggregator].downcase)
    raise ForestLiana::Errors::HTTP422Error.new('Invalid aggregate function')
  end
end