Sha256: cd35e1ee108c2d3d30aaee91625d6eb6f69a565f16566d5a4f4e9c9a55875802

Contents?: true

Size: 809 Bytes

Versions: 3

Compression:

Stored size: 809 Bytes

Contents

# Fetch the definition for a counter
# counter.definition # => Counter::Definition
module Counter::Definable
  extend ActiveSupport::Concern

  included do
    def definition= definition
      @definition = definition
    end

    # Fetch the definition for this counter
    def definition
      @definition ||= begin
        if parent.nil?
          # We don't have a parent, so we're a global counter
          Counter::Definition.find_definition name
        else
          parent.class.ancestors.find do |ancestor|
            return nil if ancestor == ApplicationRecord
            next unless ancestor.respond_to?(:counter_configs)
            config = ancestor.counter_configs.find { |c| c.record_name == name }
            return config if config
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
counterwise-0.1.5 app/models/concerns/counter/definable.rb
counterwise-0.1.4 app/models/concerns/counter/definable.rb
counterwise-0.1.3 app/models/concerns/counter/definable.rb