class ActiveReporting::Dimension

Constants

TYPES

Attributes

name[R]

Public Class Methods

new(fact_model, name:) click to toggle source

@param model [ActiveRecord::Base] @param name [Symbol]

# File lib/active_reporting/dimension.rb, line 10
def initialize(fact_model, name:)
  @fact_model = fact_model
  @name       = name.to_s
end

Public Instance Methods

association() click to toggle source

Returns the reflected association of the fact model to dimension name

@return [ActiveRecord::Reflection]

# File lib/active_reporting/dimension.rb, line 58
def association
  @association ||= model.reflect_on_association(@name)
end
hierarchical?() click to toggle source

Tells if the dimension is hierarchical

@return [Boolean]

# File lib/active_reporting/dimension.rb, line 36
def hierarchical?
  @hierarchical ||= !klass.fact_model.hierarchical_levels.empty?
end
klass() click to toggle source

Returns either the model of the dimension's association or the model itself if the dimension lives on the fact model

@return [Boolean]

# File lib/active_reporting/dimension.rb, line 44
def klass
  @klass ||= association ? association.klass : model
end
model() click to toggle source

Returns the fact model's dimension

@return [ActiveRecord::Base]

# File lib/active_reporting/dimension.rb, line 51
def model
  @model ||= @fact_model.model
end
type() click to toggle source

Determins the type of the dimension

A dimension type is either:

  • standard - The dimension is a relation to the fact model's model

  • degenerate - The dimension is the model's attribute

@return [Symbol]

# File lib/active_reporting/dimension.rb, line 23
def type
  @type ||= if model.column_names.include?(@name)
              TYPES[:degenerate]
            elsif association
              TYPES[:standard]
            else
              raise UnknownDimension, "Dimension '#{@name}' not found on fact model '#{@fact_model}'"
            end
end