Module: Tito::Base::ParamNester

Defined in:
lib/tito/base.rb

Overview

Class Method Summary collapse

Class Method Details

.append_key(root_key, key) ⇒ Object



178
179
180
# File 'lib/tito/base.rb', line 178

def self.append_key(root_key, key)
  root_key.nil? ? :"#{key}" : :"#{root_key}[#{key.to_s}]"
end

.encode(value, key = nil, out_hash = {}) ⇒ Object



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/tito/base.rb', line 162

def self.encode(value, key = nil, out_hash = {})
  case value
  when Hash
    value.each { |k,v| encode(v, append_key(key, k), out_hash) }
    out_hash
  when Array
    value.each { |v| encode(v, "#{key}[]", out_hash) }
    out_hash
  when nil
    ''
  else
    out_hash[key] = value
    out_hash
  end
end