Class: Object

Inherits:
BasicObject
Defined in:
lib/hyper-operation/call_by_class_name.rb

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/hyper-operation/call_by_class_name.rb', line 47

def method_missing(name, *args, &block)
  if name =~ /^[A-Z]/
    first = self.is_a?(Module) || self.is_a?(Class) ? self.name : self.class.name
    scopes = first.to_s.split('::').inject([Module]) do |nesting, next_const|
      nesting + [nesting.last.const_get(next_const)]
    end.reverse
    #cant use const_defined? on server because it wont invoke rails auto loading
    scope = scopes.detect { |s| s.const_get(name) rescue nil }
    const = scope.const_get(name) if scope
  end
  _hyper_operation_original_method_missing(name, *args, &block) unless const.is_a?(Class) && const < Hyperloop::Operation
  const.send(:run, *args)
end

Class Method Details

._hyper_operation_original_method_missingObject



29
# File 'lib/hyper-operation/call_by_class_name.rb', line 29

alias _hyper_operation_original_method_missing method_missing

.method_missing(name, *args, &block) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/hyper-operation/call_by_class_name.rb', line 31

def method_missing(name, *args, &block)
  if name =~ /^[A-Z]/
    scopes = self.name.to_s.split('::').inject([Module]) do |nesting, next_const|
      nesting + [nesting.last.const_get(next_const)]
    end.reverse
    #cant use const_defined? on server because it wont invoke rails auto loading
    scope = scopes.detect { |s| s.const_get(name) rescue nil }
    const = scope.const_get(name) if scope
  end
  _hyper_operation_original_method_missing(name, *args, &block) unless const.is_a?(Class) && const < Hyperloop::Operation
  const.send(:run, *args)
end

Instance Method Details

#_hyper_operation_original_method_missingObject



45
# File 'lib/hyper-operation/call_by_class_name.rb', line 45

alias _hyper_operation_original_method_missing method_missing