Class: Report::OrdersOriginReport::OrdersReportCommand

Inherits:
BaseCommand
  • Object
show all
Defined in:
app/services/report/orders_origin_report/orders_report_command.rb

Overview

Command pattern to encapsulate parameters necessary to run a presence report

Constant Summary collapse

GROUPING_OPTIONS =

Available grouping options.

[%w[quarter quarter], %w[month month], %w[week week]].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#groupingObject (readonly)

Bucketing for the report rows; must be one of GROUPING_OPTIONS.

Validations:

  • Inclusion ({ in: GROUPING_OPTIONS.map(&:first) })


13
# File 'app/services/report/orders_origin_report/orders_report_command.rb', line 13

validates :grouping, inclusion: { in: GROUPING_OPTIONS.map(&:first) }

Instance Method Details

#executeObject

Run the report with the given filters and store the result.

Returns:

  • (Object)


17
18
19
20
21
# File 'app/services/report/orders_origin_report/orders_report_command.rb', line 17

def execute
  return unless valid?

  @result = Report::OrdersOriginReport::OrdersReport.opportunity_report(attributes)
end

#success?Boolean

Whether the command validated and ran successfully.

Returns:

  • (Boolean)


25
26
27
# File 'app/services/report/orders_origin_report/orders_report_command.rb', line 25

def success?
  valid? && @result.success?
end