Module: Lifter::Webhook::ParamNester

Defined in:
lib/lifter/webhook.rb

Overview

Class Method Summary collapse

Class Method Details

.append_key(root_key, key) ⇒ Object



23
24
25
# File 'lib/lifter/webhook.rb', line 23

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

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



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/lifter/webhook.rb', line 7

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