Sha256: c45c3b4f7aa8aa67d80eebf9ecdc1e05d9acbea77bd8b7531bd878d501593e67

Contents?: true

Size: 977 Bytes

Versions: 3

Compression:

Stored size: 977 Bytes

Contents

# frozen_string_literal: true

module Magicka
  # @api public
  #
  # Class representing an element agregator, representing a model
  class Aggregator
    autoload :MethodBuilder, 'magicka/aggregator/method_builder'

    class << self
      def with_element(element_class, method_name = nil, template: nil)
        MethodBuilder
          .new(self, element_class, method_name, template: template)
          .prepare
          .build
      end
    end

    attr_reader :model

    def initialize(renderer, model)
      @renderer = renderer
      @model    = model
    end

    def with_model(model, base: self.model)
      new_model = [base, model].compact.join('.')

      yield self.class.new(renderer, new_model)
    end

    def equal?(other)
      return unless other.class == self.class

      other.renderer == renderer &&
        other.model == model
    end

    alias == equal?

    protected

    attr_reader :renderer

    delegate :render, to: :renderer
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
magicka-0.5.6 lib/magicka/aggregator.rb
magicka-0.5.5 lib/magicka/aggregator.rb
magicka-0.5.4 lib/magicka/aggregator.rb