Class: ActiveReporting::Dimension
- Inherits:
-
Object
- Object
- ActiveReporting::Dimension
- Defined in:
- lib/active_reporting/dimension.rb
Constant Summary collapse
- TYPES =
{ degenerate: :degenerate, standard: :standard }.freeze
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#association ⇒ ActiveRecord::Reflection
Returns the reflected association of the fact model to dimension name.
-
#hierarchical? ⇒ Boolean
Tells if the dimension is hierarchical.
-
#initialize(fact_model, name:) ⇒ Dimension
constructor
A new instance of Dimension.
-
#klass ⇒ Boolean
Returns either the model of the dimension’s association or the model itself if the dimension lives on the fact model.
-
#model ⇒ ActiveRecord::Base
Returns the fact model’s dimension.
-
#type ⇒ Symbol
Determins the type of the dimension.
Constructor Details
#initialize(fact_model, name:) ⇒ Dimension
Returns a new instance of Dimension.
10 11 12 13 |
# File 'lib/active_reporting/dimension.rb', line 10 def initialize(fact_model, name:) @fact_model = fact_model @name = name.to_s end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/active_reporting/dimension.rb', line 6 def name @name end |
Instance Method Details
#association ⇒ ActiveRecord::Reflection
Returns the reflected association of the fact model to dimension name
58 59 60 |
# File 'lib/active_reporting/dimension.rb', line 58 def association @association ||= model.reflect_on_association(@name) end |
#hierarchical? ⇒ Boolean
Tells if the dimension is hierarchical
36 37 38 |
# File 'lib/active_reporting/dimension.rb', line 36 def hierarchical? @hierarchical ||= !klass.fact_model.hierarchical_levels.empty? end |
#klass ⇒ Boolean
Returns either the model of the dimension’s association or the model itself if the dimension lives on the fact model
44 45 46 |
# File 'lib/active_reporting/dimension.rb', line 44 def klass @klass ||= association ? association.klass : model end |
#model ⇒ ActiveRecord::Base
Returns the fact model’s dimension
51 52 53 |
# File 'lib/active_reporting/dimension.rb', line 51 def model @model ||= @fact_model.model end |
#type ⇒ Symbol
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
23 24 25 26 27 28 29 30 31 |
# 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 |