Sha256: 9a080b74358a68c384e6eae2e4016c83821add2cf1d22aa90f116ad3388ac9e3

Contents?: true

Size: 879 Bytes

Versions: 4

Compression:

Stored size: 879 Bytes

Contents

# frozen_string_literal: true

module Magicka
  class Aggregator
    # @api private
    #
    # Class responsible for building an {Aggregator} method
    class MethodBuilder < Sinclair
      def initialize(klass, element_class, method_name = nil)
        super(klass)

        @element_class = element_class
        @method_name = method_name
      end

      def prepare
        element_klass = element_class

        add_method(method_name) do |field, model: self.model, **args|
          element_klass.render(
            renderer: renderer, field: field, model: model, **args
          )
        end

        self
      end

      private

      attr_reader :element_class

      def method_name
        @method_name ||= element_class
                         .name
                         .underscore
                         .gsub(%r{.*/}, '')
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
magicka-0.5.3 lib/magicka/aggregator/method_builder.rb
magicka-0.5.2 lib/magicka/aggregator/method_builder.rb
magicka-0.5.1 lib/magicka/aggregator/method_builder.rb
magicka-0.5.0 lib/magicka/aggregator/method_builder.rb