Class: Protocol::URL::FormData::Nested
- Inherits:
-
Object
- Object
- Protocol::URL::FormData::Nested
- Defined in:
- lib/protocol/url/form_data/nested.rb
Overview
Builds nested form data from names and values.
Constant Summary collapse
- DEPTH_LIMIT =
The bracketed form name depth limit.
8
Instance Method Summary collapse
-
#add(name, value) ⇒ Object
Add a form data value using its bracketed name.
-
#initialize(depth_limit: DEPTH_LIMIT) ⇒ Nested
constructor
Initialize the nested form data.
-
#to_h ⇒ Object
Convert the arguments to a nested hash.
Constructor Details
#initialize(depth_limit: DEPTH_LIMIT) ⇒ Nested
Initialize the nested form data.
19 20 21 22 |
# File 'lib/protocol/url/form_data/nested.rb', line 19 def initialize(depth_limit: DEPTH_LIMIT) @depth_limit = depth_limit @root = {} end |
Instance Method Details
#add(name, value) ⇒ Object
Add a form data value using its bracketed name.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/protocol/url/form_data/nested.rb', line 28 def add(name, value) keys = Encoding.split(name) if keys.empty? raise ArgumentError, "Invalid form data name: #{name.inspect}!" end if @depth_limit and keys.size > @depth_limit raise LimitError, "Form data depth exceeded limit of #{@depth_limit}!" end Encoding.assign(keys, value, @root) return self end |
#to_h ⇒ Object
Convert the arguments to a nested hash.
46 47 48 |
# File 'lib/protocol/url/form_data/nested.rb', line 46 def to_h return @root end |