Module: Ruby::Rego::CallName
- Defined in:
- lib/ruby/rego/call_name.rb
Overview
Shared call name resolution helpers. NOTE: Internal helper module, not a stable public API.
Class Method Summary collapse
-
.call_name(node) ⇒ Object
-
.dot_ref_segment_value(segment) ⇒ Object
-
.reference_base_name(reference) ⇒ Object
-
.reference_call_name(reference) ⇒ Object
-
.reference_call_segments(path) ⇒ Object
Class Method Details
.call_name(node) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/ruby/rego/call_name.rb', line 12 def call_name(node) return node.name if node.is_a?(AST::Variable) return node.to_s if node.is_a?(String) || node.is_a?(Symbol) return reference_call_name(node) if node.is_a?(AST::Reference) nil end |
.dot_ref_segment_value(segment) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ruby/rego/call_name.rb', line 42 def dot_ref_segment_value(segment) value = segment.value case segment when AST::DotRefArg return value.to_s if value.is_a?(String) || value.is_a?(Symbol) when AST::BracketRefArg return value.value.to_s if value.is_a?(AST::StringLiteral) end nil end |
.reference_base_name(reference) ⇒ Object
30 31 32 33 |
# File 'lib/ruby/rego/call_name.rb', line 30 def reference_base_name(reference) base = reference.base base.is_a?(AST::Variable) ? base.name : nil end |
.reference_call_name(reference) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/ruby/rego/call_name.rb', line 20 def reference_call_name(reference) base_name = reference_base_name(reference) return nil unless base_name segments = reference_call_segments(reference.path) return nil unless segments ([base_name] + segments).join(".") end |
.reference_call_segments(path) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/ruby/rego/call_name.rb', line 35 def reference_call_segments(path) segments = path.map { |segment| dot_ref_segment_value(segment) } return nil if segments.any?(&:nil?) segments.compact end |