Class: Ippon::Form::HashField

Inherits:
Field
  • Object
show all
Defined in:
lib/ippon/form.rb

Instance Attribute Summary

Attributes inherited from Field

#error, #input, #output

Instance Method Summary collapse

Methods inherited from Field

#fill_from_data

Constructor Details

#initializeHashField

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_childrenObject



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