Sha256: 905981583a57d0fd1de0f08564321270f468c76c3a102bd06c348162300c5205

Contents?: true

Size: 970 Bytes

Versions: 6

Compression:

Stored size: 970 Bytes

Contents

# frozen_string_literal: true

require_relative 'loader'
require_relative 'lookup'
require_relative 'coactants'
require_relative 'coactions'

module Coactive
  module Coactor
    extend ActiveSupport::Concern
    include Coactants
    include Coactions

    def coactors
      self.class._coactants.map do |coactant|
        if coactant.is_a?(Symbol) && respond_to?(coactant, true)
          send(coactant)
        elsif coactant.is_a?(Proc)
          instance_exec(&coactant)
        else
          coactant
        end
      end.flatten.compact.map do |coactant|
        if coactant.is_a?(Class) && coactant < self.class.coactive_config.base_class
          coactant
        else
          self.class.coactors(coactant)
        end
      end.flatten.compact
    end

    class_methods do
      def coactors(*coactants)
        coactants = _coactants unless coactants
        coactants.map { |coactant| Lookup.call(self, coactant) }.flatten
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
coactive-0.6.0 lib/coactive/coactor.rb
coactive-0.5.2 lib/coactive/coactor.rb
coactive-0.5.1 lib/coactive/coactor.rb
coactive-0.5.0 lib/coactive/coactor.rb
coactive-0.4.1 lib/coactive/coactor.rb
coactive-0.4.0 lib/coactive/coactor.rb