dynamic_attribute.rb 652 B

123456789101112131415161718192021222324252627282930313233
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module Sequencer::Unit::Common::Mixin::DynamicAttribute
  3. def self.included(base)
  4. class << base
  5. def inherited(base)
  6. super
  7. base.extend(Forwardable)
  8. base.instance_delegate [:attribute] => base
  9. end
  10. def attribute
  11. @attribute ||= begin
  12. if uses.size != 1
  13. raise "DynamicAttribute classes can use exactly one attribute. Found #{uses.size}."
  14. end
  15. uses.first
  16. end
  17. end
  18. end
  19. end
  20. private
  21. def attribute_value
  22. @attribute_value ||= state.use(attribute)
  23. end
  24. end