Sha256: 767495f5ca8a42a54e1ce25b94fed3e60354f782712b0cacc64388d17188fe10

Contents?: true

Size: 1.71 KB

Versions: 40

Compression:

Stored size: 1.71 KB

Contents

# encoding: UTF-8
#
# Copyright (c) 2010-2017 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_action'

module GoodData
  module LCM2
    class SegmentsFilter < BaseAction
      DESCRIPTION = 'Filter Segments'

      PARAMS = define_params(self) do
        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

      class << self
        def call(params)
          filtered_segments = params.segments

          segment_ids = filtered_segments.map(&:segment_id)
          downcase_segment_ids = segment_ids.map(&:downcase)
          duplicated_segment_ids = segment_ids.select { |e| downcase_segment_ids.count(e.downcase) > 1 }.uniq
          fail "Parameter 'segments' contains duplicate segment id(s): #{duplicated_segment_ids.join(', ')}" if duplicated_segment_ids.any?

          if params.segments_filter
            fail 'Segments filter should be a non-empty array!' if !params.segments_filter.is_a?(Array) || params.segments_filter.empty?

            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
      end
    end
  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
gooddata-2.3.1-java lib/gooddata/lcm/actions/segments_filter.rb
gooddata-2.3.1 lib/gooddata/lcm/actions/segments_filter.rb
gooddata-2.3.0-java lib/gooddata/lcm/actions/segments_filter.rb
gooddata-2.3.0 lib/gooddata/lcm/actions/segments_filter.rb
gooddata-2.2.0-java lib/gooddata/lcm/actions/segments_filter.rb
gooddata-2.2.0 lib/gooddata/lcm/actions/segments_filter.rb
gooddata-2.1.19-java lib/gooddata/lcm/actions/segments_filter.rb
gooddata-2.1.19 lib/gooddata/lcm/actions/segments_filter.rb
gooddata-2.1.17-java lib/gooddata/lcm/actions/segments_filter.rb
gooddata-2.1.17 lib/gooddata/lcm/actions/segments_filter.rb
gooddata-2.1.15-java lib/gooddata/lcm/actions/segments_filter.rb
gooddata-2.1.15 lib/gooddata/lcm/actions/segments_filter.rb
gooddata-2.1.14-java lib/gooddata/lcm/actions/segments_filter.rb
gooddata-2.1.14 lib/gooddata/lcm/actions/segments_filter.rb
gooddata-2.1.13-java lib/gooddata/lcm/actions/segments_filter.rb
gooddata-2.1.13 lib/gooddata/lcm/actions/segments_filter.rb
gooddata-2.1.12-java lib/gooddata/lcm/actions/segments_filter.rb
gooddata-2.1.12 lib/gooddata/lcm/actions/segments_filter.rb
gooddata-2.1.11-java lib/gooddata/lcm/actions/segments_filter.rb
gooddata-2.1.11 lib/gooddata/lcm/actions/segments_filter.rb