Class: ActiveadminMcp::FormFieldCollector
- Inherits:
-
Object
- Object
- ActiveadminMcp::FormFieldCollector
show all
- Defined in:
- lib/activeadmin_mcp/form_field_collector.rb
Overview
Records the field names declared by an ActiveAdmin form do ... end block.
ActiveAdmin form blocks are arbitrary Formtastic DSL — input, inputs,
actions, helper calls, conditionals — so the block is run against this
stand-in form builder. Every input :field records :field; every other
message (including unknown helpers) is swallowed and returns self, so the
block executes without a real view context. Nested has_many associations
are intentionally not descended into: the updater only writes flat
attributes, and descending would record association fields as top-level.
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#collect(&block) ⇒ Object
-
#has_many(*_args, **_opts) ⇒ Object
-
#initialize ⇒ FormFieldCollector
constructor
A new instance of FormFieldCollector.
-
#input(name, *_args, **_opts, &_block) ⇒ Object
-
#inputs(*_args, **_opts, &block) ⇒ Object
-
#method_missing(_name, *_args, **_opts, &block) ⇒ Object
-
#respond_to_missing?(_name, _include_private = false) ⇒ Boolean
Constructor Details
Returns a new instance of FormFieldCollector.
16
17
18
|
# File 'lib/activeadmin_mcp/form_field_collector.rb', line 16
def initialize
@fields = []
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(_name, *_args, **_opts, &block) ⇒ Object
39
40
41
42
|
# File 'lib/activeadmin_mcp/form_field_collector.rb', line 39
def method_missing(_name, *_args, **_opts, &block)
instance_exec(self, &block) if block
self
end
|
Instance Attribute Details
#fields ⇒ Object
Returns the value of attribute fields.
14
15
16
|
# File 'lib/activeadmin_mcp/form_field_collector.rb', line 14
def fields
@fields
end
|
Instance Method Details
#collect(&block) ⇒ Object
20
21
22
23
|
# File 'lib/activeadmin_mcp/form_field_collector.rb', line 20
def collect(&block)
instance_exec(self, &block)
@fields.uniq
end
|
#has_many(*_args, **_opts) ⇒ Object
35
36
37
|
# File 'lib/activeadmin_mcp/form_field_collector.rb', line 35
def has_many(*_args, **_opts)
self
end
|
25
26
27
28
|
# File 'lib/activeadmin_mcp/form_field_collector.rb', line 25
def input(name, *_args, **_opts, &_block)
@fields << name.to_sym if name.respond_to?(:to_sym)
self
end
|
30
31
32
33
|
# File 'lib/activeadmin_mcp/form_field_collector.rb', line 30
def inputs(*_args, **_opts, &block)
instance_exec(self, &block) if block
self
end
|
#respond_to_missing?(_name, _include_private = false) ⇒ Boolean
44
45
46
|
# File 'lib/activeadmin_mcp/form_field_collector.rb', line 44
def respond_to_missing?(_name, _include_private = false)
true
end
|