Class: Marshalsea::Scanner::Candidate

Inherits:
Object
  • Object
show all
Defined in:
lib/marshalsea/scanner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(class_name:, method_name:, gate:, source_location:, arity:, singleton:, touches_state:, formats:) ⇒ Candidate

Returns a new instance of Candidate.



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/marshalsea/scanner.rb', line 78

def initialize(class_name:, method_name:, gate:, source_location:, arity:, singleton:,
               touches_state:, formats:)
  @class_name = class_name
  @method_name = method_name
  @gate = gate
  @source_location = source_location
  @arity = arity
  @singleton = singleton
  @touches_state = touches_state
  @formats = formats
end

Instance Attribute Details

#arityObject (readonly)

Returns the value of attribute arity.



76
77
78
# File 'lib/marshalsea/scanner.rb', line 76

def arity
  @arity
end

#class_nameObject (readonly)

Returns the value of attribute class_name.



76
77
78
# File 'lib/marshalsea/scanner.rb', line 76

def class_name
  @class_name
end

#formatsObject (readonly)

Returns the value of attribute formats.



76
77
78
# File 'lib/marshalsea/scanner.rb', line 76

def formats
  @formats
end

#gateObject (readonly)

Returns the value of attribute gate.



76
77
78
# File 'lib/marshalsea/scanner.rb', line 76

def gate
  @gate
end

#method_nameObject (readonly)

Returns the value of attribute method_name.



76
77
78
# File 'lib/marshalsea/scanner.rb', line 76

def method_name
  @method_name
end

#source_locationObject (readonly)

Returns the value of attribute source_location.



76
77
78
# File 'lib/marshalsea/scanner.rb', line 76

def source_location
  @source_location
end

Instance Method Details

#accepts_dispatch?Boolean

Returns:

  • (Boolean)


114
115
116
117
118
119
120
# File 'lib/marshalsea/scanner.rb', line 114

def accepts_dispatch?
  required = dispatch_arity
  return true if required == VARIADIC
  return arity == required unless arity.negative?

  required >= (arity.abs - 1)
end

#dispatch_arityObject



110
111
112
# File 'lib/marshalsea/scanner.rb', line 110

def dispatch_arity
  ENTRY_POINTS.fetch(method_name).fetch(:arity)
end

#entry_point?Boolean

Returns:

  • (Boolean)


106
107
108
# File 'lib/marshalsea/scanner.rb', line 106

def entry_point?
  !link?
end

#gated?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/marshalsea/scanner.rb', line 94

def gated?
  gate == GATE_GATED
end

#link?Boolean

Returns:

  • (Boolean)


102
103
104
# File 'lib/marshalsea/scanner.rb', line 102

def link?
  gate == GATE_LINK
end

#reachable?Boolean

Returns:

  • (Boolean)


142
143
144
145
146
147
148
# File 'lib/marshalsea/scanner.rb', line 142

def reachable?
  return false unless entry_point?
  return false unless accepts_dispatch?
  return true if gated? || soft_gated?

  touches_state? || unreadable_source?
end

#singleton?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/marshalsea/scanner.rb', line 90

def singleton?
  @singleton
end

#soft_gated?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/marshalsea/scanner.rb', line 98

def soft_gated?
  gate == GATE_SOFT
end

#state_known?Boolean

Returns:

  • (Boolean)


130
131
132
# File 'lib/marshalsea/scanner.rb', line 130

def state_known?
  STATE_VERDICTS.include?(@touches_state)
end

#to_sObject



150
151
152
# File 'lib/marshalsea/scanner.rb', line 150

def to_s
  "#{class_name}#{singleton? ? '.' : '#'}#{method_name}"
end

#touches_state?Boolean

Returns:

  • (Boolean)


126
127
128
# File 'lib/marshalsea/scanner.rb', line 126

def touches_state?
  @touches_state == true
end

#unanalysable?Boolean

Returns:

  • (Boolean)


134
135
136
# File 'lib/marshalsea/scanner.rb', line 134

def unanalysable?
  @touches_state == STATE_UNANALYSABLE
end

#unreadable_source?Boolean

Returns:

  • (Boolean)


138
139
140
# File 'lib/marshalsea/scanner.rb', line 138

def unreadable_source?
  @touches_state == STATE_UNREADABLE
end

#zero_arity?Boolean

Returns:

  • (Boolean)


122
123
124
# File 'lib/marshalsea/scanner.rb', line 122

def zero_arity?
  arity.zero?
end