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.21 lib/eco/api/microcases/preserve_filter_tags.rb
eco-helpers-3.0.20 lib/eco/api/microcases/preserve_filter_tags.rb
eco-helpers-3.0.19 lib/eco/api/microcases/preserve_filter_tags.rb
eco-helpers-3.0.18 lib/eco/api/microcases/preserve_filter_tags.rb
eco-helpers-3.0.17 lib/eco/api/microcases/preserve_filter_tags.rb
eco-helpers-3.0.16 lib/eco/api/microcases/preserve_filter_tags.rb
eco-helpers-3.0.15 lib/eco/api/microcases/preserve_filter_tags.rb
eco-helpers-3.0.14 lib/eco/api/microcases/preserve_filter_tags.rb
eco-helpers-3.0.13 lib/eco/api/microcases/preserve_filter_tags.rb
eco-helpers-3.0.12 lib/eco/api/microcases/preserve_filter_tags.rb
eco-helpers-3.0.11 lib/eco/api/microcases/preserve_filter_tags.rb
eco-helpers-3.0.10 lib/eco/api/microcases/preserve_filter_tags.rb
eco-helpers-3.0.9 lib/eco/api/microcases/preserve_filter_tags.rb
eco-helpers-3.0.8 lib/eco/api/microcases/preserve_filter_tags.rb
eco-helpers-3.0.7 lib/eco/api/microcases/preserve_filter_tags.rb
eco-helpers-3.0.6 lib/eco/api/microcases/preserve_filter_tags.rb
eco-helpers-3.0.5 lib/eco/api/microcases/preserve_filter_tags.rb
eco-helpers-3.0.4 lib/eco/api/microcases/preserve_filter_tags.rb
eco-helpers-3.0.3 lib/eco/api/microcases/preserve_filter_tags.rb
eco-helpers-3.0.2 lib/eco/api/microcases/preserve_filter_tags.rb