Class: Ippon::Form::HashField
Instance Attribute Summary
Attributes inherited from Field
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, field) ⇒ Object
- #each_param(key, &blk) ⇒ Object
- #fill_output_from_children ⇒ Object
- #get(key, klass) ⇒ Object
-
#initialize ⇒ HashField
constructor
A new instance of HashField.
Methods inherited from Field
Constructor Details
#initialize ⇒ HashField
Returns a new instance of HashField.
61 62 63 |
# File 'lib/ippon/form.rb', line 61 def initialize @input = {} end |
Instance Method Details
#[](key) ⇒ Object
65 66 67 |
# File 'lib/ippon/form.rb', line 65 def [](key) @input[key] end |
#[]=(key, field) ⇒ Object
69 70 71 |
# File 'lib/ippon/form.rb', line 69 def []=(key, field) @input[key] = field end |
#each_param(key, &blk) ⇒ Object
99 100 101 102 103 |
# File 'lib/ippon/form.rb', line 99 def each_param(key, &blk) @input.each do |child_key, child_field| child_field.each_param(key[child_key], &blk) end end |
#fill_output_from_children ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/ippon/form.rb', line 82 def fill_output_from_children @output = {} input.each do |child_key, child_field| @output[child_key] = child_field.output end self end |
#get(key, klass) ⇒ Object
73 74 75 76 77 78 79 80 |
# File 'lib/ippon/form.rb', line 73 def get(key, klass) if field = @input[key] raise TypeError, "#{key.inspect} is already of class #{field.class}" if !field.is_a?(klass) field else @input[key] = klass.new end end |