Class: Spree::Reporting::Base

Inherits:
Struct
  • Object
show all
Defined in:
lib/spree/reporting/registry.rb

Overview

A relation metrics aggregate over, and the family it belongs to.

Bases exist because the things a store measures sit at different grains: an order has no payment method, a payment has no line items, a stock movement has neither a customer nor a currency. A base names one grain, says how to reach it store-scoped, and declares which family it can be queried alongside.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#clock ⇒ Object

What this base's time column means, in a merchant's words ("anchored on when the order completed"). Named in the cross-family refusal so a caller can see why two metrics cannot share a row.



195
196
197
198
199
200
201
# File 'lib/spree/reporting/registry.rb', line 195

Base = Struct.new(:name, :family, :table, :relation, :time_column, :reaches, :clock, keyword_init: true) do
  def reaches?(dimension_base) = reaches.key?(dimension_base)

  # The association a dimension on `dimension_base` is joined through from
  # here — nil when it is this base's own, so the join needs no hop.
  def path_to(dimension_base) = reaches[dimension_base]
end

#family ⇒ Object

Bases sharing a family combine in one query (:orders and :line_items both answer questions about sales). Bases in different families never do — the query refuses the mix rather than inventing a join between grains that have no honest relationship.



195
196
197
198
199
200
201
# File 'lib/spree/reporting/registry.rb', line 195

Base = Struct.new(:name, :family, :table, :relation, :time_column, :reaches, :clock, keyword_init: true) do
  def reaches?(dimension_base) = reaches.key?(dimension_base)

  # The association a dimension on `dimension_base` is joined through from
  # here — nil when it is this base's own, so the join needs no hop.
  def path_to(dimension_base) = reaches[dimension_base]
end

#name ⇒ Object

Returns the value of attribute name

Returns:

  • (Object) —

    the current value of name



195
196
197
# File 'lib/spree/reporting/registry.rb', line 195

def name
  @name
end

#reaches ⇒ Object

Bases whose dimensions this one can group by, itself included. An :orders dimension is reachable from :line_items through the order join; not the reverse.



195
196
197
198
199
200
201
# File 'lib/spree/reporting/registry.rb', line 195

Base = Struct.new(:name, :family, :table, :relation, :time_column, :reaches, :clock, keyword_init: true) do
  def reaches?(dimension_base) = reaches.key?(dimension_base)

  # The association a dimension on `dimension_base` is joined through from
  # here — nil when it is this base's own, so the join needs no hop.
  def path_to(dimension_base) = reaches[dimension_base]
end

#relation ⇒ Object

->(store, range, currency) returning the store-scoped, range-filtered relation. Money bases filter the currency; countable ones ignore it.



195
196
197
198
199
200
201
# File 'lib/spree/reporting/registry.rb', line 195

Base = Struct.new(:name, :family, :table, :relation, :time_column, :reaches, :clock, keyword_init: true) do
  def reaches?(dimension_base) = reaches.key?(dimension_base)

  # The association a dimension on `dimension_base` is joined through from
  # here — nil when it is this base's own, so the join needs no hop.
  def path_to(dimension_base) = reaches[dimension_base]
end

#table ⇒ Object

The base's own table, as a %placeholder. Where a bare column: symbol on one of its dimensions is read from. Deliberately separate from time_column: a line item's clock lives on its order.



195
196
197
198
199
200
201
# File 'lib/spree/reporting/registry.rb', line 195

Base = Struct.new(:name, :family, :table, :relation, :time_column, :reaches, :clock, keyword_init: true) do
  def reaches?(dimension_base) = reaches.key?(dimension_base)

  # The association a dimension on `dimension_base` is joined through from
  # here — nil when it is this base's own, so the join needs no hop.
  def path_to(dimension_base) = reaches[dimension_base]
end

#time_column ⇒ Object

Table-qualified column the range filters on, named in the schema so a caller knows what "last 30 days" means for this base.



195
196
197
198
199
200
201
# File 'lib/spree/reporting/registry.rb', line 195

Base = Struct.new(:name, :family, :table, :relation, :time_column, :reaches, :clock, keyword_init: true) do
  def reaches?(dimension_base) = reaches.key?(dimension_base)

  # The association a dimension on `dimension_base` is joined through from
  # here — nil when it is this base's own, so the join needs no hop.
  def path_to(dimension_base) = reaches[dimension_base]
end

Instance Method Details

#path_to(dimension_base) ⇒ Object

The association a dimension on dimension_base is joined through from here — nil when it is this base's own, so the join needs no hop.



200
# File 'lib/spree/reporting/registry.rb', line 200

def path_to(dimension_base) = reaches[dimension_base]

#reaches?(dimension_base) ⇒ Boolean

Returns:

  • (Boolean)


196
# File 'lib/spree/reporting/registry.rb', line 196

def reaches?(dimension_base) = reaches.key?(dimension_base)