Module: ActiveWarehouse::SlowlyChangingDimension::ClassMethods

Defined in:
lib/active_warehouse/dimension/slowly_changing_dimension.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_slowly_changing_dimension(options = {}) ⇒ Object

Indicate that the dimension is a Type 2 Slowly Changing Dimension (SDC).

A word of warning:

The expiration_date field must never be null. For the current effective record use the maximum date allowed. This is necessary because the find query used when :valid_on is specified is implemented using a between clause.

Options:

  • :identifier:

  • :lastest_version: Define the attribute name which represents the latest version flag

  • :effective_date: Define the attribute name which represents the effective date column

  • :expiration_date: Define the attribute name which represents the expiration date column



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/active_warehouse/dimension/slowly_changing_dimension.rb', line 37

def acts_as_slowly_changing_dimension(options = {})
  unless slowly_changing_dimension? # don't let AR call this twice
    cattr_accessor :identifier
    cattr_accessor :latest_version_attribute
    cattr_accessor :effective_date_attribute
    cattr_accessor :expiration_date_attribute
    self.identifier = options[:identifier] || :identifier
    self.latest_version_attribute = options[:with] || :latest_version
    self.effective_date_attribute = options[:effective_date_attribute] || :effective_date
    self.expiration_date_attribute = options[:expiration_date_attribute] || :expiration_date
    class << self
      alias_method :find_every_with_older,    :find_every
      alias_method :calculate_with_older,     :calculate
      alias_method :core_validate_find_options, :validate_find_options
      VALID_FIND_OPTIONS << :with_older
      VALID_FIND_OPTIONS << :valid_on
      VALID_FIND_OPTIONS << :valid_during
    end
  end
  include InstanceMethods
end

#slowly_changing_dimension?Boolean

Return true if this dimension is a slowly changing dimension

Returns:

  • (Boolean)


60
61
62
# File 'lib/active_warehouse/dimension/slowly_changing_dimension.rb', line 60

def slowly_changing_dimension?
  self.included_modules.include?(InstanceMethods)
end