Module: Transpec::Syntax::Mixin::Send::ClassMethods

Defined in:
lib/transpec/syntax/mixin/send.rb

Instance Method Summary collapse

Instance Method Details

#check_target_node_dynamically(node, runtime_data) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/transpec/syntax/mixin/send.rb', line 44

def check_target_node_dynamically(node, runtime_data)
  return true unless runtime_data

  receiver_node, method_name, *_ = *node
  target_node = receiver_node ? receiver_node : node

  return true unless (node_data = runtime_data[target_node])
  return true unless (eval_data = node_data[source_location_key(method_name)])
  return true unless (source_location = eval_data.result)

  file_path = source_location.first
  !file_path.match(%r{/gems/rspec\-[^/]+/lib/rspec/}).nil?
end

#check_target_node_statically(node) ⇒ Object



38
39
40
41
42
# File 'lib/transpec/syntax/mixin/send.rb', line 38

def check_target_node_statically(node)
  return false unless node && node.type == :send
  receiver_node, method_name, *_ = *node
  target_method?(receiver_node, method_name)
end

#register_request_for_dynamic_analysis(node, rewriter) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/transpec/syntax/mixin/send.rb', line 12

def register_request_for_dynamic_analysis(node, rewriter)
  return unless target_node?(node)

  receiver_node, method_name, *_ = *node

  if receiver_node
    target_node = receiver_node
    target_object_type = :object
  else
    target_node = node
    target_object_type = :context
  end

  key = source_location_key(method_name)
  code = "method(#{method_name.inspect}).source_location"
  rewriter.register_request(target_node, key, code, target_object_type)
end

#source_location_key(method_name) ⇒ Object



58
59
60
# File 'lib/transpec/syntax/mixin/send.rb', line 58

def source_location_key(method_name)
  "#{method_name}_source_location".to_sym
end

#target_method?(receiver_node, method_name) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/transpec/syntax/mixin/send.rb', line 34

def target_method?(receiver_node, method_name)
  false
end

#target_node?(node, runtime_data = nil) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/transpec/syntax/mixin/send.rb', line 30

def target_node?(node, runtime_data = nil)
  check_target_node_statically(node) && check_target_node_dynamically(node, runtime_data)
end