Class: Magicka::Aggregator::MethodBuilder Private

Inherits:
Sinclair
  • Object
show all
Defined in:
lib/magicka/aggregator/method_builder.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Class responsible for building an Magicka::Aggregator method

Instance Method Summary collapse

Constructor Details

#initialize(klass, element_class, method_name = nil, template: nil) ⇒ MethodBuilder

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of MethodBuilder.

Parameters:

  • klass (Class.new<Aggregator>)

    Aggragator class to receive the method

  • element_class (Class<Magicka::ELement>)

    Class of the element to be rendered

  • method_name (String, Symbol) (defaults to: nil)

    Name of the method that will render the element

  • template (String) (defaults to: nil)

    custom template file to be used



16
17
18
19
20
21
22
# File 'lib/magicka/aggregator/method_builder.rb', line 16

def initialize(klass, element_class, method_name = nil, template: nil)
  super(klass)

  @element_class = element_class
  @method_name = method_name
  @template = template
end

Instance Method Details

#prepareAggregator::MethodBuilder

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Prepare methods to be built

Returns:



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/magicka/aggregator/method_builder.rb', line 27

def prepare
  element_klass = element_class
  template_file = template

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

  self
end