Class: Spree::Reporting::Dimension
- Inherits:
-
Struct
- Object
- Struct
- Spree::Reporting::Dimension
- Defined in:
- lib/spree/reporting/registry.rb
Overview
A dimension groups rows. The definition owns every behavior keyed off it, so an extension-registered dimension works end-to-end (filtering, hydration, authorization) without touching core.
Instance Attribute Summary collapse
-
#base ⇒ Object
The finest base able to express this grouping (:orders groupings are also reachable from :line_items via the order join; not vice versa).
-
#column ⇒ Object
Group-by column (symbol on the base table, or a table-qualified string).
-
#expression ⇒ Object
Returns the value of attribute expression.
-
#grains ⇒ Object
Returns the value of attribute grains.
-
#hydrate ⇒ Object
->(store, keys, params) returning { raw_key => { id:, label:, meta: } } display payloads for the API layer.
-
#joins ⇒ Object
Extra association joins the grouping needs (from the base relation).
-
#key_scope ⇒ Object
API-key scope (e.g. 'read_products') required alongside
read_reportsfor secret keys to reference the member. -
#lookup ⇒ Object
Schema tag naming what the dimension's keys identify (e.g. :product) — set alongside
hydrateso clients know display payloads are coming. -
#name ⇒ Object
Returns the value of attribute name.
-
#population ⇒ Object
Lambda (store) -> relation enumerating every record the dimension can group by.
-
#resolve ⇒ Object
->(store, value) resolving filter values (prefixed ids) to raw keys, always through store-scoped collections.
-
#subject ⇒ Object
-> { SomeClass } authorization subject.
-
#type ⇒ Object
:value | :time — :time dimensions take a grain and zero-fill buckets.
-
#values ⇒ Object
Enumerable raw values for status-like dimensions (an Array, or a lambda returning one so model constants load lazily).
Instance Method Summary collapse
- #enumerated_values ⇒ Object
-
#expression? ⇒ Boolean
A dimension whose key is computed rather than read from a column.
- #population? ⇒ Boolean
- #time? ⇒ Boolean
Instance Attribute Details
#base ⇒ Object
The finest base able to express this grouping (:orders groupings are also reachable from :line_items via the order join; not vice versa).
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/spree/reporting/registry.rb', line 147 Dimension = Struct.new(:name, :base, :column, :expression, :joins, :type, :grains, :lookup, :resolve, :hydrate, :subject, :key_scope, :values, :population, keyword_init: true) do def time? = type == :time def population? = population.present? # A dimension whose key is computed rather than read from a column. The # compiler validates `column` down to `table.column` so registration # cannot smuggle SQL by accident; `expression` is how a developer says # the SQL is deliberate, and it carries the same trust as a metric's. def expression? = expression.present? def enumerated_values values.respond_to?(:call) ? values.call : values end end |
#column ⇒ Object
Group-by column (symbol on the base table, or a table-qualified string).
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/spree/reporting/registry.rb', line 147 Dimension = Struct.new(:name, :base, :column, :expression, :joins, :type, :grains, :lookup, :resolve, :hydrate, :subject, :key_scope, :values, :population, keyword_init: true) do def time? = type == :time def population? = population.present? # A dimension whose key is computed rather than read from a column. The # compiler validates `column` down to `table.column` so registration # cannot smuggle SQL by accident; `expression` is how a developer says # the SQL is deliberate, and it carries the same trust as a metric's. def expression? = expression.present? def enumerated_values values.respond_to?(:call) ? values.call : values end end |
#expression ⇒ Object
Returns the value of attribute expression
147 148 149 |
# File 'lib/spree/reporting/registry.rb', line 147 def expression @expression end |
#grains ⇒ Object
Returns the value of attribute grains
147 148 149 |
# File 'lib/spree/reporting/registry.rb', line 147 def grains @grains end |
#hydrate ⇒ Object
->(store, keys, params) returning { raw_key => { id:, label:, meta: } } display payloads for the API layer. Omitted = raw keys on the wire.
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/spree/reporting/registry.rb', line 147 Dimension = Struct.new(:name, :base, :column, :expression, :joins, :type, :grains, :lookup, :resolve, :hydrate, :subject, :key_scope, :values, :population, keyword_init: true) do def time? = type == :time def population? = population.present? # A dimension whose key is computed rather than read from a column. The # compiler validates `column` down to `table.column` so registration # cannot smuggle SQL by accident; `expression` is how a developer says # the SQL is deliberate, and it carries the same trust as a metric's. def expression? = expression.present? def enumerated_values values.respond_to?(:call) ? values.call : values end end |
#joins ⇒ Object
Extra association joins the grouping needs (from the base relation).
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/spree/reporting/registry.rb', line 147 Dimension = Struct.new(:name, :base, :column, :expression, :joins, :type, :grains, :lookup, :resolve, :hydrate, :subject, :key_scope, :values, :population, keyword_init: true) do def time? = type == :time def population? = population.present? # A dimension whose key is computed rather than read from a column. The # compiler validates `column` down to `table.column` so registration # cannot smuggle SQL by accident; `expression` is how a developer says # the SQL is deliberate, and it carries the same trust as a metric's. def expression? = expression.present? def enumerated_values values.respond_to?(:call) ? values.call : values end end |
#key_scope ⇒ Object
API-key scope (e.g. 'read_products') required alongside read_reports
for secret keys to reference the member. Mandatory whenever subject
is declared, so key access is decided at registration, never skipped.
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/spree/reporting/registry.rb', line 147 Dimension = Struct.new(:name, :base, :column, :expression, :joins, :type, :grains, :lookup, :resolve, :hydrate, :subject, :key_scope, :values, :population, keyword_init: true) do def time? = type == :time def population? = population.present? # A dimension whose key is computed rather than read from a column. The # compiler validates `column` down to `table.column` so registration # cannot smuggle SQL by accident; `expression` is how a developer says # the SQL is deliberate, and it carries the same trust as a metric's. def expression? = expression.present? def enumerated_values values.respond_to?(:call) ? values.call : values end end |
#lookup ⇒ Object
Schema tag naming what the dimension's keys identify (e.g. :product) —
set alongside hydrate so clients know display payloads are coming.
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/spree/reporting/registry.rb', line 147 Dimension = Struct.new(:name, :base, :column, :expression, :joins, :type, :grains, :lookup, :resolve, :hydrate, :subject, :key_scope, :values, :population, keyword_init: true) do def time? = type == :time def population? = population.present? # A dimension whose key is computed rather than read from a column. The # compiler validates `column` down to `table.column` so registration # cannot smuggle SQL by accident; `expression` is how a developer says # the SQL is deliberate, and it carries the same trust as a metric's. def expression? = expression.present? def enumerated_values values.respond_to?(:call) ? values.call : values end end |
#name ⇒ Object
Returns the value of attribute name
147 148 149 |
# File 'lib/spree/reporting/registry.rb', line 147 def name @name end |
#population ⇒ Object
Lambda (store) -> relation enumerating every record the dimension can
group by. Declared rather than inferred from lookup, because it is
what include_empty reads to produce rows for members with no
matching facts ("which products never sold"); a dimension without one
refuses include_empty instead of quietly returning only what sold.
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/spree/reporting/registry.rb', line 147 Dimension = Struct.new(:name, :base, :column, :expression, :joins, :type, :grains, :lookup, :resolve, :hydrate, :subject, :key_scope, :values, :population, keyword_init: true) do def time? = type == :time def population? = population.present? # A dimension whose key is computed rather than read from a column. The # compiler validates `column` down to `table.column` so registration # cannot smuggle SQL by accident; `expression` is how a developer says # the SQL is deliberate, and it carries the same trust as a metric's. def expression? = expression.present? def enumerated_values values.respond_to?(:call) ? values.call : values end end |
#resolve ⇒ Object
->(store, value) resolving filter values (prefixed ids) to raw keys, always through store-scoped collections. Omitted = values pass through.
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/spree/reporting/registry.rb', line 147 Dimension = Struct.new(:name, :base, :column, :expression, :joins, :type, :grains, :lookup, :resolve, :hydrate, :subject, :key_scope, :values, :population, keyword_init: true) do def time? = type == :time def population? = population.present? # A dimension whose key is computed rather than read from a column. The # compiler validates `column` down to `table.column` so registration # cannot smuggle SQL by accident; `expression` is how a developer says # the SQL is deliberate, and it carries the same trust as a metric's. def expression? = expression.present? def enumerated_values values.respond_to?(:call) ? values.call : values end end |
#subject ⇒ Object
-> { SomeClass } authorization subject. JWT admin sessions must be
able to :read the class to reference the member; order data itself
is covered by the base Spree::Order check. Lazy so registration never
autoloads models.
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/spree/reporting/registry.rb', line 147 Dimension = Struct.new(:name, :base, :column, :expression, :joins, :type, :grains, :lookup, :resolve, :hydrate, :subject, :key_scope, :values, :population, keyword_init: true) do def time? = type == :time def population? = population.present? # A dimension whose key is computed rather than read from a column. The # compiler validates `column` down to `table.column` so registration # cannot smuggle SQL by accident; `expression` is how a developer says # the SQL is deliberate, and it carries the same trust as a metric's. def expression? = expression.present? def enumerated_values values.respond_to?(:call) ? values.call : values end end |
#type ⇒ Object
:value | :time — :time dimensions take a grain and zero-fill buckets.
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/spree/reporting/registry.rb', line 147 Dimension = Struct.new(:name, :base, :column, :expression, :joins, :type, :grains, :lookup, :resolve, :hydrate, :subject, :key_scope, :values, :population, keyword_init: true) do def time? = type == :time def population? = population.present? # A dimension whose key is computed rather than read from a column. The # compiler validates `column` down to `table.column` so registration # cannot smuggle SQL by accident; `expression` is how a developer says # the SQL is deliberate, and it carries the same trust as a metric's. def expression? = expression.present? def enumerated_values values.respond_to?(:call) ? values.call : values end end |
#values ⇒ Object
Enumerable raw values for status-like dimensions (an Array, or a lambda returning one so model constants load lazily). Published in the schema as the filter value list.
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/spree/reporting/registry.rb', line 147 Dimension = Struct.new(:name, :base, :column, :expression, :joins, :type, :grains, :lookup, :resolve, :hydrate, :subject, :key_scope, :values, :population, keyword_init: true) do def time? = type == :time def population? = population.present? # A dimension whose key is computed rather than read from a column. The # compiler validates `column` down to `table.column` so registration # cannot smuggle SQL by accident; `expression` is how a developer says # the SQL is deliberate, and it carries the same trust as a metric's. def expression? = expression.present? def enumerated_values values.respond_to?(:call) ? values.call : values end end |
Instance Method Details
#enumerated_values ⇒ Object
159 160 161 |
# File 'lib/spree/reporting/registry.rb', line 159 def enumerated_values values.respond_to?(:call) ? values.call : values end |
#expression? ⇒ Boolean
A dimension whose key is computed rather than read from a column. The
compiler validates column down to table.column so registration
cannot smuggle SQL by accident; expression is how a developer says
the SQL is deliberate, and it carries the same trust as a metric's.
157 |
# File 'lib/spree/reporting/registry.rb', line 157 def expression? = expression.present? |
#population? ⇒ Boolean
151 |
# File 'lib/spree/reporting/registry.rb', line 151 def population? = population.present? |
#time? ⇒ Boolean
149 |
# File 'lib/spree/reporting/registry.rb', line 149 def time? = type == :time |