Sha256: 4d2428545d335fe5fd7f61747b69509fc8cb15f01b66c0144d05a41aa662543c

Contents?: true

Size: 931 Bytes

Versions: 3

Compression:

Stored size: 931 Bytes

Contents

# frozen_string_literal: true

#
# Copyright (c) 2020-present, Blue Marble Payroll, LLC
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#

module Realize
  class Filter
    # This transformer can take an object (will be converted to array) or array and
    # will go through each child object and see if the child record has a value for the
    # specified key.  If it does then it will select that record.
    class ByKeyValuePresence
      include Arrays
      acts_as_hashable

      attr_reader :key

      def initialize(key:)
        raise ArgumentError, 'key is required' if key.to_s.empty?

        @key = key

        freeze
      end

      def transform(resolver, value, _time, _record)
        records = array(value)

        records.reject do |record|
          resolver.get(record, key).to_s.empty?
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
realize-1.6.0 lib/realize/filter/by_key_value_presence.rb
realize-1.5.0 lib/realize/filter/by_key_value_presence.rb
realize-1.4.0 lib/realize/filter/by_key_value_presence.rb