Sha256: 7b6cb024af1172a7519d5bc8eafd2cd4d3e180d4d6641462cbff24aa85fa1b7d

Contents?: true

Size: 1.12 KB

Versions: 11

Compression:

Stored size: 1.12 KB

Contents

# This class is used in two cases:
# For facts:
#   To prevent calculation of custom metrics as user code may rely on dimension initialization during
#   the process of figuring out which keys should be initialized.
#
# For elements:
#   To prevent infinite recursion that can be caused if a cube has two custom rollups that call `locate`.
#   The result would be that the calculations oscillates between the two metrics on the newly located element.

module Martyr
  module Runtime
    class FutureMetric

      # @param element_or_fact [Element, Fact]
      # @param metric [BaseMetric]
      # @param method [:rollup, :extract]
      def self.wrap(element_or_fact, metric, method)
        if metric.is_a?(Martyr::Schema::BuiltInMetric)
          metric.send(method, element_or_fact)
        else
          proc = -> { metric.send(method, element_or_fact) }
          new(proc)
        end
      end

      def initialize(proc)
        @proc = proc
      end

      def inspect
        @value_retrieved ? @value.inspect : '?'
      end

      def value
        @value_retrieved = true
        @value ||= @proc.call
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
martyr-0.1.85.pre lib/martyr/runtime/data_set/future_metric.rb
martyr-0.1.84.pre lib/martyr/runtime/data_set/future_metric.rb
martyr-0.1.82.pre lib/martyr/runtime/data_set/future_metric.rb
martyr-0.1.81.pre lib/martyr/runtime/data_set/future_metric.rb
martyr-0.1.80.pre lib/martyr/runtime/data_set/future_metric.rb
martyr-0.1.79.pre lib/martyr/runtime/data_set/future_metric.rb
martyr-0.1.78.pre lib/martyr/runtime/data_set/future_metric.rb
martyr-0.1.77.pre lib/martyr/runtime/data_set/future_metric.rb
martyr-0.1.76.pre lib/martyr/runtime/data_set/future_metric.rb
martyr-0.1.75.pre lib/martyr/runtime/data_set/future_metric.rb
martyr-0.1.74.pre lib/martyr/runtime/data_set/future_metric.rb