Class: Basepack::Forms::Factories::Base
- Inherits:
-
Object
- Object
- Basepack::Forms::Factories::Base
- Defined in:
- lib/basepack/forms/factories/base.rb
Direct Known Subclasses
Constant Summary collapse
- FIELDS =
{ has_one_association: Fields::HasOneAssociation, has_many_association: Fields::HasManyAssociation, belongs_to_association: Fields::BelongsToAssociation, has_and_belongs_to_many_association: Fields::HasAndBelongsToManyAssociation, color: Fields::ColorPicker, }
Instance Method Summary collapse
- #build_form(form) ⇒ Object
-
#initialize(form_class = Forms::Base, group_class = Groups::Base) ⇒ Base
constructor
A new instance of Base.
- #new_field(name, form, attributes) ⇒ Object
- #new_form(*args) ⇒ Object
- #new_group(form, attributes) ⇒ Object
Constructor Details
#initialize(form_class = Forms::Base, group_class = Groups::Base) ⇒ Base
Returns a new instance of Base.
14 15 16 17 |
# File 'lib/basepack/forms/factories/base.rb', line 14 def initialize(form_class = Forms::Base, group_class = Groups::Base) @form_class = form_class @group_class = group_class end |
Instance Method Details
#build_form(form) ⇒ Object
19 20 21 |
# File 'lib/basepack/forms/factories/base.rb', line 19 def build_form(form) form end |
#new_field(name, form, attributes) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/basepack/forms/factories/base.rb', line 31 def new_field(name, form, attributes) if klass = FIELDS[field_attr(attributes, :type)] klass.new(name, form, attributes) else Fields::Base.new(name, form, attributes) end end |
#new_form(*args) ⇒ Object
23 24 25 |
# File 'lib/basepack/forms/factories/base.rb', line 23 def new_form(*args) @form_class.new(self, *args).build_from_factory end |
#new_group(form, attributes) ⇒ Object
27 28 29 |
# File 'lib/basepack/forms/factories/base.rb', line 27 def new_group(form, attributes) @group_class.new(form, attributes) end |