Class: Formulario::Field::FormField
Constant Summary
TYPES
Instance Attribute Summary collapse
#raw_value
Class Method Summary
collapse
Instance Method Summary
collapse
#==, #blank?, #exceptional_class, for, #inspect, #to_s, type_for
Constructor Details
#initialize(raw_value) ⇒ FormField
Returns a new instance of FormField.
36
37
38
39
40
41
42
43
44
|
# File 'lib/formulario/fields/form_field.rb', line 36
def initialize(raw_value)
@form = if raw_value.is_a?(::Formulario::Form)
raw_value
else
self.class.type.new(**raw_value)
end
super
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
58
59
60
61
62
|
# File 'lib/formulario/fields/form_field.rb', line 58
def method_missing(name, *args, &block)
return fields[name] if fields.has_key?(name)
super
end
|
Instance Attribute Details
Returns the value of attribute form.
4
5
6
|
# File 'lib/formulario/fields/form_field.rb', line 4
def form
@form
end
|
Class Method Details
.[](type) ⇒ Object
6
7
8
9
10
|
# File 'lib/formulario/fields/form_field.rb', line 6
def self.[](type)
Class.new(self) do |typed_class|
typed_class.type = type
end
end
|
.default ⇒ Object
16
17
18
|
# File 'lib/formulario/fields/form_field.rb', line 16
def self.default
new(type.default)
end
|
.type ⇒ Object
12
13
14
|
# File 'lib/formulario/fields/form_field.rb', line 12
def self.type
@type
end
|
Instance Method Details
#[](value) ⇒ Object
32
33
34
|
# File 'lib/formulario/fields/form_field.rb', line 32
def [](value)
fields[value]
end
|
#exceptional? ⇒ Boolean
24
25
26
|
# File 'lib/formulario/fields/form_field.rb', line 24
def exceptional?
! form.valid?
end
|
#fields ⇒ Object
28
29
30
|
# File 'lib/formulario/fields/form_field.rb', line 28
def fields
form.fields
end
|
#value ⇒ Object
20
21
22
|
# File 'lib/formulario/fields/form_field.rb', line 20
def value
form.params
end
|