Class: Formalist::Definition
- Inherits:
-
Object
- Object
- Formalist::Definition
- Defined in:
- lib/formalist/definition.rb
Constant Summary collapse
- DuplicateElementError =
Class.new(StandardError)
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#elements ⇒ Object
readonly
Returns the value of attribute elements.
-
#form ⇒ Object
readonly
Returns the value of attribute form.
Instance Method Summary collapse
-
#initialize(form, config, &block) ⇒ Definition
constructor
A new instance of Definition.
- #method_missing(name, *args, &block) ⇒ Object
- #with(**new_options, &block) ⇒ Object
Constructor Details
#initialize(form, config, &block) ⇒ Definition
9 10 11 12 13 14 15 |
# File 'lib/formalist/definition.rb', line 9 def initialize(form, config, &block) @form = form @config = config @elements = [] instance_eval(&block) if block end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/formalist/definition.rb', line 25 def method_missing(name, *args, &block) if element_type?(name) add_element(name, *args, &block) elsif form.respond_to?(name, include_private = true) form.send(name, *args, &block) else super end end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
6 7 8 |
# File 'lib/formalist/definition.rb', line 6 def config @config end |
#elements ⇒ Object (readonly)
Returns the value of attribute elements.
7 8 9 |
# File 'lib/formalist/definition.rb', line 7 def elements @elements end |
#form ⇒ Object (readonly)
Returns the value of attribute form.
5 6 7 |
# File 'lib/formalist/definition.rb', line 5 def form @form end |
Instance Method Details
#with(**new_options, &block) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/formalist/definition.rb', line 17 def with(**, &block) new_config = .each_with_object(config.dup) { |(key, value), config| config.send :"#{key}=", value } self.class.new(form, new_config, &block) end |