Sha256: 576829e05a130d2077ad78eee11074fc5641f608289b42e9f1f797cb7cedba41

Contents?: true

Size: 1016 Bytes

Versions: 27

Compression:

Stored size: 1016 Bytes

Contents

module Eco
  module API
    class MicroCases
      # Helper to preserve the original filter tags.
      # @note
      #   1. It only works if the original value of `filter_tags` was **not** empty
      # @param person [Ecoportal::API::V1::Person] the person we want to update, carrying the changes to be done.
      # @param options [Hash] the options.
      # @param keep_new [Boolean] tells if it should keep the new tags or get rid of them.
      # @return [Array<String>] the final value of `filter_tags`.
      def preserve_filter_tags(person, _options, keep_new: false)
        person.filter_tags.tap do
          next unless person.as_update.key?('filter_tags')
          next unless (original = person.original_doc['filter_tags'])
          next if original.empty?

          if keep_new
            person.filter_tags += original
          else
            person.filter_tags  = original
          end

          return person.filter_tags
        end
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
eco-helpers-3.0.1 lib/eco/api/microcases/preserve_filter_tags.rb
eco-helpers-3.0.0 lib/eco/api/microcases/preserve_filter_tags.rb
eco-helpers-2.7.25 lib/eco/api/microcases/preserve_filter_tags.rb
eco-helpers-2.7.24 lib/eco/api/microcases/preserve_filter_tags.rb
eco-helpers-2.7.23 lib/eco/api/microcases/preserve_filter_tags.rb
eco-helpers-2.7.22 lib/eco/api/microcases/preserve_filter_tags.rb
eco-helpers-2.7.21 lib/eco/api/microcases/preserve_filter_tags.rb