Sha256: 6e094c84a5e2942dad693a73102a2b353756bbf78c4750ab8711ef3853ea2e6a

Contents?: true

Size: 1.57 KB

Versions: 33

Compression:

Stored size: 1.57 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
            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

33 entries across 33 versions & 1 rubygems

Version Path
gooddata-1.2.1-java lib/gooddata/lcm/actions/segments_filter.rb
gooddata-1.2.1 lib/gooddata/lcm/actions/segments_filter.rb
gooddata-1.2.0-java lib/gooddata/lcm/actions/segments_filter.rb
gooddata-1.2.0 lib/gooddata/lcm/actions/segments_filter.rb
gooddata-1.1.0-java lib/gooddata/lcm/actions/segments_filter.rb
gooddata-1.1.0 lib/gooddata/lcm/actions/segments_filter.rb
gooddata-1.0.2-java lib/gooddata/lcm/actions/segments_filter.rb
gooddata-1.0.2 lib/gooddata/lcm/actions/segments_filter.rb
gooddata-1.0.1 lib/gooddata/lcm/actions/segments_filter.rb
gooddata-1.0.1-java lib/gooddata/lcm/actions/segments_filter.rb
gooddata-1.0.0-java lib/gooddata/lcm/actions/segments_filter.rb
gooddata-1.0.0 lib/gooddata/lcm/actions/segments_filter.rb
gooddata-0.6.54 lib/gooddata/lcm/actions/segments_filter.rb