Sha256: 208828530ed250d7b0b47256e472d2655aa7d7c9e8cec629e8d2965878243de1

Contents?: true

Size: 755 Bytes

Versions: 1

Compression:

Stored size: 755 Bytes

Contents

# frozen_string_literal: true

require_relative 'coaction'

module Coactive
  module Coactions
    extend ActiveSupport::Concern

    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[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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
coactive-0.4.1 lib/coactive/coactions.rb