Class: Rubyzen::Declarations::CallSiteDeclaration
- Inherits:
-
Object
- Object
- Rubyzen::Declarations::CallSiteDeclaration
- Includes:
- Providers::ClassNameProvider, Providers::FilePathProvider, Providers::LineNumberProvider, Providers::SourceCodeProvider
- Defined in:
- lib/rubyzen/declarations/call_site_declaration.rb
Overview
Represents a method call site (a send node in the AST).
Instance Attribute Summary collapse
- #node ⇒ RuboCop::AST::Node readonly
- #parent ⇒ MethodDeclaration, ... readonly
Instance Method Summary collapse
-
#initialize(node, parent) ⇒ CallSiteDeclaration
constructor
A new instance of CallSiteDeclaration.
-
#keyword_arg_value_pairs ⇒ Hash{Symbol => Object}
Returns a hash mapping keyword argument keys to their literal values.
-
#keyword_args ⇒ Array<Symbol>
Returns the keyword argument keys passed in the call.
-
#method_name ⇒ String
Returns the called method name.
-
#name ⇒ String
Returns the called method name.
-
#receiver ⇒ String?
Returns the constant name of the receiver, if any.
-
#strings ⇒ Array<String>
Returns positional string arguments.
-
#symbols ⇒ Array<Symbol>
Returns positional symbol arguments.
Methods included from Providers::SourceCodeProvider
Methods included from Providers::ClassNameProvider
Methods included from Providers::LineNumberProvider
Methods included from Providers::FilePathProvider
Constructor Details
#initialize(node, parent) ⇒ CallSiteDeclaration
Returns a new instance of CallSiteDeclaration.
25 26 27 28 |
# File 'lib/rubyzen/declarations/call_site_declaration.rb', line 25 def initialize(node, parent) @node = node @parent = parent end |
Instance Attribute Details
#node ⇒ RuboCop::AST::Node (readonly)
18 19 20 |
# File 'lib/rubyzen/declarations/call_site_declaration.rb', line 18 def node @node end |
#parent ⇒ MethodDeclaration, ... (readonly)
21 22 23 |
# File 'lib/rubyzen/declarations/call_site_declaration.rb', line 21 def parent @parent end |
Instance Method Details
#keyword_arg_value_pairs ⇒ Hash{Symbol => Object}
Returns a hash mapping keyword argument keys to their literal values.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/rubyzen/declarations/call_site_declaration.rb', line 67 def keyword_arg_value_pairs result = {} node.arguments.each do |arg| next unless arg.hash_type? arg.pairs.each do |pair| next unless pair.key.type == :sym value_node = pair.value result[pair.key.value] = value_node.respond_to?(:value) ? value_node.value : nil end end result end |
#keyword_args ⇒ Array<Symbol>
Returns the keyword argument keys passed in the call.
54 55 56 57 58 59 60 61 62 |
# File 'lib/rubyzen/declarations/call_site_declaration.rb', line 54 def keyword_args node.arguments.flat_map do |arg| next [] unless arg.hash_type? arg.pairs.filter_map do |pair| pair.key.value if pair.key.type == :sym end end.uniq end |
#method_name ⇒ String
Returns the called method name.
47 48 49 |
# File 'lib/rubyzen/declarations/call_site_declaration.rb', line 47 def method_name node.method_name.to_s end |
#name ⇒ String
Returns the called method name. Alias for #method_name.
33 34 35 |
# File 'lib/rubyzen/declarations/call_site_declaration.rb', line 33 def name method_name end |
#receiver ⇒ String?
Returns the constant name of the receiver, if any.
40 41 42 |
# File 'lib/rubyzen/declarations/call_site_declaration.rb', line 40 def receiver node.receiver&.type == :const ? node.receiver.const_name : nil end |
#strings ⇒ Array<String>
Returns positional string arguments.
92 93 94 |
# File 'lib/rubyzen/declarations/call_site_declaration.rb', line 92 def strings node.arguments.select { |arg| arg.type == :str }.map(&:value) end |
#symbols ⇒ Array<Symbol>
Returns positional symbol arguments.
85 86 87 |
# File 'lib/rubyzen/declarations/call_site_declaration.rb', line 85 def symbols node.arguments.select { |arg| arg.type == :sym }.map(&:value) end |