Class: GoodData::LCM2::SegmentsFilter

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

Constant Summary collapse

DESCRIPTION =
'Filter Segments'
PARAMS =
define_params(self) do
  description 'Client Used for Connecting to GD'
  param :gdc_gd_client, instance_of(Type::GdClientType), required: true

  description 'Segments to manage'
  param :segments, array_of(instance_of(Type::SegmentType)), required: true

  description 'Segments to provision'
  param :segments_filter, array_of(instance_of(Type::StringType)), required: false
end

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



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/gooddata/lcm/actions/segments_filter.rb', line 26

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

  filtered_segments = params.segments
  if params.segments_filter
    segments_filter = params.segments_filter.map(&:downcase)

    filtered_segments = params.segments.select do |segment|
      segments_filter.include?(segment.segment_id.downcase)
    end
  end

  # Return results
  {
    results: filtered_segments,
    params: {
      segments: filtered_segments
    }
  }
end