Module: SuperModule::V1::ModuleBodyMethodCallRecorder

Defined in:
lib/super_module/v1/module_body_method_call_recorder.rb

Instance Method Summary collapse

Instance Method Details

#__all_module_body_method_calls_in_definition_orderObject



25
26
27
28
29
# File 'lib/super_module/v1/module_body_method_call_recorder.rb', line 25

def __all_module_body_method_calls_in_definition_order
  ancestor_module_body_method_calls = included_super_modules.map(&:__module_body_method_calls).flatten(1)
  all_module_body_method_calls = __module_body_method_calls + ancestor_module_body_method_calls
  all_module_body_method_calls.reverse
end

#__method_signature(method_name, args) ⇒ Object



15
16
17
# File 'lib/super_module/v1/module_body_method_call_recorder.rb', line 15

def __method_signature(method_name, args)
  "#{method_name}(#{args.to_a.map(&:to_s).join(",")})"
end

#__module_body_method_callsObject



11
12
13
# File 'lib/super_module/v1/module_body_method_call_recorder.rb', line 11

def __module_body_method_calls
  @__module_body_method_calls ||= []
end

#__record_method_call(method_name, *args, &block) ⇒ Object

TODO handle case of a method call being passed a block (e.g. validates do custom validator end )



20
21
22
23
# File 'lib/super_module/v1/module_body_method_call_recorder.rb', line 20

def __record_method_call(method_name, *args, &block)
  return if self.is_a?(Class)
  __module_body_method_calls << [method_name, args, block]
end

#__singleton_method_call_recorder(method_name, method_args) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/super_module/v1/module_body_method_call_recorder.rb', line 31

def __singleton_method_call_recorder(method_name, method_args)
  unless __super_module_singleton_methods_excluded_from_call_recording.include?(method_name)
    method_call_recorder_args = "'#{method_name}'"
    method_call_recorder_args << ", #{method_args}" unless method_args.to_s.strip == '' 
    "self.__record_method_call(#{method_call_recorder_args})" 
  end
end

#__super_module_singleton_methods_excluded_from_call_recordingObject



4
5
6
7
8
9
# File 'lib/super_module/v1/module_body_method_call_recorder.rb', line 4

def __super_module_singleton_methods_excluded_from_call_recording
  @__super_module_singleton_methods_excluded_from_call_recording ||= [
    :__record_method_call,
    :__method_signature
  ]
end