Class: GoodData::Bricks::UndotParamsMiddleware

Inherits:
Middleware show all
Defined in:
lib/gooddata/bricks/middleware/undot_params_middleware.rb

Overview

Converts params from double underscore notation to nested hash under 'config' Parameters starting GDC_ are considered system params and aren't converted.

This is useful because the executor platform can currently do just key-value parameters. Also it makes it easier for a user, as there aren't as much curly braces.

Examples

If you pass params in form: "value"

you'll get: {"namespace": {"param": value}}

Instance Attribute Summary

Attributes inherited from Middleware

#app

Instance Method Summary collapse

Methods inherited from Middleware

#initialize, #load_defaults

Methods included from Utils

#returning

Constructor Details

This class inherits a constructor from GoodData::Bricks::Middleware

Instance Method Details

#call(params) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/gooddata/bricks/middleware/undot_params_middleware.rb', line 26

def call(params)
  params = params.to_hash
  unless params['config']
    # split the params to those starting with GDC and those that don't, put other params under config
    gdc_params, other_params = params.partition { |k, _| k =~ /GDC_.*/ }.map { |h| Hash[h] }
    params = gdc_params.merge('config' => other_params.undot)
  end
  @app.call(params)
end