Class: Avo::Loaders::FieldsLoader

Inherits:
Loader
  • Object
show all
Defined in:
lib/avo/loaders/fields_loader.rb

Instance Attribute Summary

Attributes inherited from Loader

#bag

Instance Method Summary collapse

Methods inherited from Loader

#initialize, #use

Constructor Details

This class inherits a constructor from Avo::Loaders::Loader

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/avo/loaders/fields_loader.rb', line 8

def method_missing(method, *args, &block)
  matched_field = Avo.field_manager.find do |field|
    field[:name].to_s == method.to_s
  end

  if matched_field.present? && matched_field[:class].present?
    klass = matched_field[:class]

    field = if block.present?
      klass.new(args[0], **args[1] || {}, &block)
    else
      klass.new(args[0], **args[1] || {})
    end

    add_field field
  end
end

Instance Method Details

#add_field(field) ⇒ Object



4
5
6
# File 'lib/avo/loaders/fields_loader.rb', line 4

def add_field(field)
  @bag.push field
end

#respond_to_missing?(method) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
29
30
# File 'lib/avo/loaders/fields_loader.rb', line 26

def respond_to_missing?(method)
  Avo.field_manager.find do |field|
    field[:name].to_s == method.to_s
  end
end