provide_mapped.rb 985 B

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