provide_mapped.rb 639 B

12345678910111213141516171819202122232425
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module Sequencer::Unit::Import::Common::Mapping::Mixin::ProvideMapped
  3. def self.included(base)
  4. base.optional :mapped
  5. base.provides :mapped
  6. end
  7. private
  8. def existing_mapped
  9. @existing_mapped ||= begin
  10. # we need to use `state.optional` instead of just `mapped` here
  11. # to prevent naming conflicts with other Unit methods named `mapped`
  12. state.optional(:mapped) || ActiveSupport::HashWithIndifferentAccess.new
  13. end
  14. end
  15. def provide_mapped
  16. state.provide(:mapped) do
  17. existing_mapped.merge(yield)
  18. end
  19. end
  20. end