Class: GoodData::LCM2::PrintModes

Inherits:
BaseAction show all
Defined in:
lib/gooddata/lcm/actions/print_modes.rb

Constant Summary collapse

DESCRIPTION =
'Print Modes'
PARAMS =
{
}

Constants included from Dsl::Dsl

Dsl::Dsl::DEFAULT_OPTS, Dsl::Dsl::TYPES

Class Method Summary collapse

Methods inherited from BaseAction

check_params

Methods included from Dsl::Dsl

#define_params, #define_type, #process

Class Method Details

.call(params) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/gooddata/lcm/actions/print_modes.rb', line 18

def call(params)
  # Check if all required parameters were passed
  BaseAction.check_params(PARAMS, params)

  results = []
  GoodData::LCM2::MODES.keys.each_with_index do |mode, index|
    actions = GoodData::LCM2::MODES[mode]
    action_names = actions.map do |k, _action|
      params_length = k.const_get(:PARAMS).keys.length
      k.short_name + ("\n" * (params_length > 1 ? params_length - 1 : 0))
    end

    params = actions.map do |action|
      action.const_get(:PARAMS).map do |_k, param|
        param[:name]
      end
    end

    types = actions.map do |action|
      action.const_get(:PARAMS).map do |_k, param|
        param[:type]
        # param[:type].class.short_name
      end
    end

    required = actions.map do |action|
      action.const_get(:PARAMS).map do |_k, param|
        param[:opts][:required]
      end
    end

    defaults = actions.map do |action|
      action.const_get(:PARAMS).map do |_k, param|
        param[:opts][:default]
      end
    end

    results << {
      '#' => index,
      mode: mode,
      actions: action_names.join("\n"),
      params: params.join("\n"),
      types: types.join("\n"),
      required: required.join("\n"),
      default: defaults.join("\n")
    }
  end

  # Return results
  results
end