Class: Growth::Operations::RetentionReport::Prepare

Inherits:
Object
  • Object
show all
Includes:
Dry::Transaction::Operation
Defined in:
lib/growth/operations/retention_report/prepare.rb

Instance Method Summary collapse

Instance Method Details

#call(input) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/growth/operations/retention_report/prepare.rb', line 7

def call(input)
  begin
    source_resource, target_resource = input[:associations].split('-').map(&:constantize)
    resources = source_resource.unscoped.joins(target_resource.to_s.pluralize.underscore.to_sym)
    grouped_resources = resources.group(:id).order("#{target_resource.to_s.pluralize.underscore}.count ASC")

    Success({
        source_resource: source_resource,
        target_resource: target_resource,
        grouped_resources_count: invert(grouped_resources.count),
        resources_distinct_count: resources.distinct.count
    })
  rescue => e
    Failure({report: {resources_stats: []}, error: e})
  end
end