Class: Solargraph::Pin::FactoryParameter

Inherits:
Base
  • Object
show all
Defined in:
lib/solargraph/pin/factory_parameter.rb

Overview

A method parameter with a literal value used in a factory method.

Examples:

RSpec.shared_examples 'some examples'

FactoryParameter.new(
  method_name: 'shared_examples',
  method_namespace: 'RSpec',
  method_scope: :class,
  param_name: 'name',
  value: 'some examples',
  decl: :arg,
  return_type: 'void'
)

Constant Summary

Constants included from Logging

Logging::DEFAULT_LOG_LEVEL, Logging::LOG_LEVELS

Instance Attribute Summary collapse

Attributes inherited from Base

#code_object, #combine_priority, #directives, #docstring, #path, #return_type, #source, #type_location

Attributes included from Common

#context

Instance Method Summary collapse

Methods inherited from Base

#==, #all_location_text, #all_rooted?, #assert_location_provided, #assert_same, #assert_same_array_content, #assert_same_count, #assert_same_macros, #assert_source_provided, #best_location, #choose, #choose_longer, #choose_node, #choose_pin_attr, #choose_pin_attr_with_same_name, #choose_priority, #closure, #combine_closure, #combine_directives, #combine_name, #combine_return_type, #combine_with, #comments, #completion_item_kind, #deprecated?, #desc, #dodgy_return_type_source?, #erase_generics, #filename, #gates, #identity, #infer, #inspect, #macro_names, #macro_names?, #macros, #macros_names?, #maybe_directives?, #maybe_macros?, #nearly?, #needs_consistent_name?, #prefer_rbs_location, #presence_certain?, #probe, #probed?, #proxied?, #proxy, #rbs_location?, #realize, #reset_generated!, #resolve_generics, #resolve_generics_from_context, #symbol_kind, #to_rbs, #to_s, #transform_types, #type_desc, #typify, #variable?

Methods included from Logging

log_level, logger

Methods included from Documenting

#documentation, normalize_indentation, strip_html_comments

Methods included from Conversions

#completion_item, #completion_item_kind, #deprecated?, #detail, #link_documentation, #probed?, #proxied?, #reset_conversions, #resolve_completion_item, #signature_help

Methods included from Common

#binder, #closure, #closure=, #comments, #each_closure, #namespace, #path, #reset_generated!, #return_type, #source

Constructor Details

#initialize(method_name:, method_namespace:, method_scope:, param_name:, value:, return_type:, decl: :arg, location: nil) ⇒ FactoryParameter

Returns a new instance of FactoryParameter.

Parameters:

  • method_name (String) —

    The name of the method that this parameter belongs to

  • method_namespace (String) —

    The class of the method that this parameter belongs to

  • method_scope (Symbol) —

    The scope of the method, either :class or :instance

  • param_name (String, nil) —

    The name of the parameter

  • value (String, Symbol) —

    The value of the parameter

  • decl (::Symbol) (defaults to: :arg) —

    :arg, :kwarg

  • location (Location, nil) (defaults to: nil) —

    The location of the parameter in the source code

  • return_type (String, nil) —

    The return type of the method that this parameter belongs to



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/solargraph/pin/factory_parameter.rb', line 43

def initialize method_name:,
               method_namespace:,
               method_scope:,
               param_name:,
               value:,
               return_type:,
               decl: :arg,
               location: nil
  super(location: location)
  @method_name = method_name
  @method_namespace = method_namespace
  @method_scope = method_scope
  @param_name = param_name
  @value = value
  @decl = decl
  @return_type = return_type
end

Instance Attribute Details

#decl ⇒ ::Symbol (readonly)

Returns :arg, :optarg, :kwarg, :kwoptarg, :restarg, :kwrestarg, :block, :blockarg.

Returns:

  • (::Symbol) —

    :arg, :optarg, :kwarg, :kwoptarg, :restarg, :kwrestarg, :block, :blockarg



31
32
33
# File 'lib/solargraph/pin/factory_parameter.rb', line 31

def decl
  @decl
end

#location ⇒ Location? (readonly)

Returns:



33
34
35
# File 'lib/solargraph/pin/factory_parameter.rb', line 33

def location
  @location
end

#method_name ⇒ String (readonly)

Returns:

  • (String)


21
22
23
# File 'lib/solargraph/pin/factory_parameter.rb', line 21

def method_name
  @method_name
end

#method_namespace ⇒ String (readonly)

Returns:

  • (String)


23
24
25
# File 'lib/solargraph/pin/factory_parameter.rb', line 23

def method_namespace
  @method_namespace
end

#method_scope ⇒ Symbol (readonly)

Returns :class or :instance.

Returns:

  • (Symbol) —

    :class or :instance



25
26
27
# File 'lib/solargraph/pin/factory_parameter.rb', line 25

def method_scope
  @method_scope
end

#param_name ⇒ String? (readonly)

Returns:

  • (String, nil)


27
28
29
# File 'lib/solargraph/pin/factory_parameter.rb', line 27

def param_name
  @param_name
end

#value ⇒ ::String, ::Symbol (readonly)

Returns The literal value.

Returns:

  • (::String, ::Symbol) —

    The literal value



29
30
31
# File 'lib/solargraph/pin/factory_parameter.rb', line 29

def value
  @value
end

Instance Method Details

#method_path ⇒ String

Returns:

  • (String)


70
71
72
73
74
# File 'lib/solargraph/pin/factory_parameter.rb', line 70

def method_path
  # @sg-ignore false failure on method_scope "Wrong argument type for Solargraph::Pin::Base#==: other expected
  # Solargraph::Pin::Base, received :instance"
  @method_path ||= "#{method_namespace}#{method_scope == :instance ? '#' : '.'}#{method_name}"
end

#name ⇒ Object



61
62
63
# File 'lib/solargraph/pin/factory_parameter.rb', line 61

def name
  param_name
end

#text_documentation ⇒ Object



65
66
67
# File 'lib/solargraph/pin/factory_parameter.rb', line 65

def text_documentation
  "#{method_path}(#{param_name}) = #{value.inspect}"
end