Class: ForestLiana::ResourceGetter

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseGetter

#get_collection, #get_resource

Constructor Details

#initialize(resource, params) ⇒ ResourceGetter

Returns a new instance of ResourceGetter.



5
6
7
8
# File 'app/services/forest_liana/resource_getter.rb', line 5

def initialize(resource, params)
  @resource = resource
  @params = params
end

Instance Attribute Details

#recordObject

Returns the value of attribute record.



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

def record
  @record
end

Instance Method Details

#includesObject



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

def includes
  SchemaUtils.one_associations(@resource)
    .select { |association| SchemaUtils.model_included?(association.klass) }
    .map(&:name)
end

#performObject



10
11
12
# File 'app/services/forest_liana/resource_getter.rb', line 10

def perform
  @record = get_resource().eager_load(includes).find(@params[:id])
end