Sha256: 7476fe218f121f82aaf00fc5222b0b209ffdee4c9ebf154d13f808c9f03a5a3b
Contents?: true
Size: 1.32 KB
Versions: 4
Compression:
Stored size: 1.32 KB
Contents
module Basepack module Forms module Factories class Base 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, } def initialize(form_class = Forms::Base, group_class = Groups::Base) @form_class = form_class @group_class = group_class end def build_form(form) form end def new_form(*args) @form_class.new(self, *args).build_from_factory end def new_group(form, attributes) @group_class.new(form, attributes) end 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 private def field_attr(attributes, name) if attributes if attributes.respond_to? name attributes.send(name) else attributes[name] end end end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems