Class: Field::Form

Inherits:
Base
  • Object
show all
Extended by:
FormProxy
Defined in:
lib/field/form.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#form, #name, #options

Instance Method Summary collapse

Methods included from FormProxy

[]

Methods inherited from Base

factory, #initialize, #presenter_class, #setup_container, #value

Constructor Details

This class inherits a constructor from Field::Base

Instance Attribute Details

#form_classObject

Returns the value of attribute form_class.



7
8
9
# File 'lib/field/form.rb', line 7

def form_class
  @form_class
end

Instance Method Details

#attributeObject



26
27
28
# File 'lib/field/form.rb', line 26

def attribute
  @form_class
end

#inject_attributesObject



9
10
11
# File 'lib/field/form.rb', line 9

def inject_attributes
  @container.attribute @name, attribute, default: attribute.new
end

#inject_validationsObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/field/form.rb', line 13

def inject_validations
  @container.class_eval %Q{
    method = "__ensure_valid_#{name.to_s}__"
    validate method

    define_method method do
      unless send('#{name}').send(:valid?)
        errors.add(:base, "Invalid #{name.to_s}")
      end
    end
  }
end