lib/coactive/coactions.rb in coactive-0.4.0 vs lib/coactive/coactions.rb in coactive-0.4.1

- old
+ new

@@ -4,19 +4,29 @@ module Coactive module Coactions extend ActiveSupport::Concern - included do - class_attribute :coactions_map - self.coactions_map = {} + class << self + class_attribute :registry + self.registry = {} + + def [](base, name) + registry.dig(base, name) + end + + def []=(base, name, array) + registry[base] ||= {} + registry[base][name] = array + end end class_methods do def coaction(*names, **options) + base = coactive_config.base_class names.each do |name| - coactions = coactions_map[name].to_a + [Coaction.new(self, name, options)] - coactions_map[name] = coactions.sort_by.with_index { |coaction, i| [coaction.priority, i] } + coactions = Coactions[base, name].to_a + [Coaction.new(self, name, options)] + Coactions[base, name] = coactions.sort_by.with_index { |coaction, i| [coaction.priority, i] } end end end end end