Sha256: 50eb41338e2b5edc34799a5174b2ef812059d2aa543312ddd2d80a7b33695341

Contents?: true

Size: 1.27 KB

Versions: 37

Compression:

Stored size: 1.27 KB

Contents

# encoding: UTF-8
#
# Copyright (c) 2010-2015 GoodData Corporation. All rights reserved.
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

require_relative 'base_middleware'

module GoodData
  module Bricks
    # 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:
    # {"my__namespace__param": "value"}
    #
    # you'll get:
    # {"my": {"namespace": {"param": value}}}
    class UndotParamsMiddleware < Bricks::Middleware
      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
    end
  end
end

Version data entries

37 entries across 37 versions & 3 rubygems

Version Path
gooddata-0.6.33 lib/gooddata/bricks/middleware/undot_params_middleware.rb
gooddata-0.6.32 lib/gooddata/bricks/middleware/undot_params_middleware.rb
gooddata-0.6.31 lib/gooddata/bricks/middleware/undot_params_middleware.rb
gooddata-0.6.30 lib/gooddata/bricks/middleware/undot_params_middleware.rb
gooddata-0.6.29 lib/gooddata/bricks/middleware/undot_params_middleware.rb
gooddata-bricks-0.5.0 lib/gooddata/bricks/middleware/undot_params_middleware.rb
gooddata-0.6.28 lib/gooddata/bricks/middleware/undot_params_middleware.rb
gooddata-0.6.27 lib/gooddata/bricks/middleware/undot_params_middleware.rb
gooddata-bricks-0.4.0 lib/gooddata/bricks/middleware/undot_params_middleware.rb
gooddata-bricks-0.3.0 lib/gooddata/bricks/middleware/undot_params_middleware.rb
gooddata-0.6.26 lib/gooddata/bricks/middleware/undot_params_middleware.rb
gooddata-bricks-0.2.0 lib/gooddata/bricks/middleware/undot_params_middleware.rb
gooddata-bricks-0.1.0 lib/gooddata/bricks/middleware/undot_params_middleware.rb
gooddata-0.6.25 lib/gooddata/bricks/middleware/undot_params_middleware.rb
gooddata-0.6.24 lib/gooddata/bricks/middleware/undot_params_middleware.rb
gooddata-0.6.23 lib/gooddata/bricks/middleware/undot_params_middleware.rb
gooddata-0.6.22 lib/gooddata/bricks/middleware/undot_params_middleware.rb