Module: Thaum::Action::ClassMethods

Defined in:
lib/thaum/action.rb

Instance Method Summary collapse

Instance Method Details

#method_added(name) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/thaum/action.rb', line 30

def method_added(name)
  super
  return if name == :initialize
  return unless public_method_defined?(name)
  return if singleton_class.method_defined?(name, false)

  define_singleton_method(name) do |*args, **kwargs|
    pool = Thaum::Action.pool
    unless pool
      raise Thaum::Error,
            "Thaum::Action method called outside a running Thaum app (no thread pool available)"
    end

    pool.post { new.public_send(name, *args, **kwargs) }
  end
end