Module: Formalism::Form::Fields::ClassMethods
- Defined in:
- lib/formalism/form/fields.rb
Overview
Module for class methods
Instance Method Summary collapse
- #field(name, type = nil, **options) ⇒ Object
- #fields_and_nested_forms ⇒ Object
- #included(something) ⇒ Object
- #nested(name, form = nil, **options) ⇒ Object
Instance Method Details
#field(name, type = nil, **options) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/formalism/form/fields.rb', line 31 def field(name, type = nil, **) Coercion.new(type, [:of]).check unless type.nil? fields_and_nested_forms[name] = .merge(type: type) define_field_methods(name) end |
#fields_and_nested_forms ⇒ Object
27 28 29 |
# File 'lib/formalism/form/fields.rb', line 27 def fields_and_nested_forms @fields_and_nested_forms ||= {} end |
#included(something) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/formalism/form/fields.rb', line 15 def included(something) super fields_and_nested_forms.each do |name, | if .key?(:form) something.nested name, [:form], ** else something.field name, [:type], ** end end end |
#nested(name, form = nil, **options) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/formalism/form/fields.rb', line 39 def nested(name, form = nil, **) unless form || .key?(:initialize) raise ArgumentError, 'Neither form class nor initialize block is not present' end fields_and_nested_forms[name] = .merge(form: form) define_nested_form_methods(name) end |