Module: QuasarRestClient::MogrifyVars

Included in:
Proxy
Defined in:
lib/quasar_rest_client/mogrify_vars.rb

Instance Method Summary collapse

Instance Method Details

#mogrify_vars(hash) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/quasar_rest_client/mogrify_vars.rb', line 8

def mogrify_vars(hash)
  vars = hash[:var]&.map do |k, v|
    new_key = "var.#{k}"

    # This is hacky-hack, at best
    # E.g. given var: { email: "[email protected]"} =>
    #            var.email: '"[email protected]"'
    # i.e. quasar requires the double quotes
    # Note that the documentation says single quotes, but it is WRONG
    new_val = case v
              when String
                v.inspect
              # NOTE: order is important: DateTime must precede Date
              when DateTime
                "TIMESTAMP '#{v.strftime("%F %T")}'"
              when Date
                "DATE '#{v.strftime("%F")}'"
              when Time
                "TIME '#{v.strftime("%T")}'"
              when Array
                v.inspect
              else
                v
              end

    [new_key, new_val]
  end.to_h

  hash.delete(:var)
  hash.merge(vars)
end