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 Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, element_class, method_name = nil, template: nil) ⇒ MethodBuilder #initialize(klass, element_class_name, 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.

Overloads:

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

    Parameters:

    • element_class (Class<Magicka::Element>)

      Class of the element to be rendered

    • klass (Class<Aggregator>)

      Aggragator class to receive the method

    • 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

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

    Parameters:

    • element_class_name (String)

      String name of Class of the element to be rendered

    • klass (Class<Aggregator>)

      Aggragator class to receive the method

    • 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



26
27
28
29
30
31
32
# File 'lib/magicka/aggregator/method_builder.rb', line 26

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

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

Instance Attribute Details

#templateString (readonly)

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.

Template file

Returns:

  • (String)


64
65
66
# File 'lib/magicka/aggregator/method_builder.rb', line 64

def template
  @template
end

Instance Method Details

#element_classClass<Magicka::Element>

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.

Class of the element to be rendered by the method

Returns:



52
53
54
55
56
# File 'lib/magicka/aggregator/method_builder.rb', line 52

def element_class
  return @element_class if @element_class.is_a?(Class)

  @element_class = @element_class.constantize
end

#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:



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/magicka/aggregator/method_builder.rb', line 37

def prepare
  tap do |builder|
    add_method(method_name) do |field, model: self.model, **args|
      builder.element_class.render(
        renderer: renderer, field: field,
        model: model, template: builder.template,
        **args
      )
    end
  end
end