Module: Promiscuous::Subscriber::Lint::Polymorphic

Extended by:
ActiveSupport::Concern
Defined in:
lib/promiscuous/subscriber/lint/polymorphic.rb

Instance Method Summary collapse

Instance Method Details

#lintObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/promiscuous/subscriber/lint/polymorphic.rb', line 14

def lint
  super
  return if skip_polymorphic

  sub_descendants = subscriber.descendants
  pub_descendants = publishers.select { |pub| pub < publisher }

  if check_publisher
    subscriber_types = sub_descendants.map &:from_type
    publisher_types = pub_descendants.map &:class_name
    missing_types = publisher_types - subscriber_types
    if missing_types.present?
      raise "#{subscriber} does not cover #{missing_types.join(", ")}"
    end
  end

  sub_descendants.each do |pub|
    self.class.new(options.merge(:klass => nil, :subscriber => pub,
                                 :skip_polymorphic => true)).lint
  end
end

#publisherObject



4
5
6
7
8
9
10
11
12
# File 'lib/promiscuous/subscriber/lint/polymorphic.rb', line 4

def publisher
  parent_publisher = super
  return nil if parent_publisher.nil?

  publishers.
    select { |pub| pub <= parent_publisher }.
    select { |pub| pub.class_name == subscriber.from_type }.
    first
end