Class: Orthoses::Descendants

Inherits:
Object
  • Object
show all
Defined in:
lib/orthoses/descendants.rb

Overview

use Orthoses::Descendants, of: ‘ApplicationJob’

Instance Method Summary collapse

Constructor Details

#initialize(loader, of:) ⇒ Descendants

Returns a new instance of Descendants.



6
7
8
9
# File 'lib/orthoses/descendants.rb', line 6

def initialize(loader, of:)
  @loader = loader
  @of = of
end

Instance Method Details

#callObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/orthoses/descendants.rb', line 11

def call
  @loader.call.tap do |store|
    super_class =
      case @of
      when String
        Object.const_get(@of)
      else
        @of
      end

    unless super_class.kind_of?(Class)
      raise "`of` option should be String or Class"
    end

    descendants_of(super_class).each do |descendant|
      base_name = Orthoses::Utils.module_name(descendant) or next
      store[base_name]
    end
  end
end