Class: Yoda::Store::Objects::MethodObject

Inherits:
Base
  • Object
show all
Defined in:
lib/yoda/store/objects/method_object.rb

Defined Under Namespace

Classes: Connected

Constant Summary collapse

METHOD_SEPARATOR_PATTERN =
/[#.]|(::)/

Instance Attribute Summary collapse

Attributes inherited from Base

#document, #path, #primary_source, #sources, #tag_list

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#==, #address, #eql?, #hash, #merge, #meta_class_address, #namespace?, #with_connection

Methods included from Serializable

#==, #derive, #eql?, #hash, included, #to_json

Methods included from Addressable

#address

Constructor Details

#initialize(parameters: [], visibility: :public, overloads: [], **kwargs) ⇒ MethodObject

Returns a new instance of MethodObject.

Parameters:

  • path (String)
  • document (Document, nil)
  • tag_list (Array<Tag>, nil)
  • visibility (Symbol) (defaults to: :public)
  • overloads (Array<Overload>) (defaults to: [])
  • parameters (Array<(String, String)>, nil) (defaults to: [])


64
65
66
67
68
69
70
# File 'lib/yoda/store/objects/method_object.rb', line 64

def initialize(parameters: [], visibility: :public, overloads: [], **kwargs)
  super(**kwargs)
  fail ArgumentError, visibility unless %i(public private protected)
  @visibility = visibility.to_sym
  @parameters = parameters
  @overloads = overloads
end

Instance Attribute Details

#overloadsArray<Overload> (readonly)

Returns:



16
17
18
# File 'lib/yoda/store/objects/method_object.rb', line 16

def overloads
  @overloads
end

#parametersArray<(String, String)> (readonly)

Returns:

  • (Array<(String, String)>)


10
11
12
# File 'lib/yoda/store/objects/method_object.rb', line 10

def parameters
  @parameters
end

#visibilitySymbol (readonly)

Returns:

  • (Symbol)


13
14
15
# File 'lib/yoda/store/objects/method_object.rb', line 13

def visibility
  @visibility
end

Class Method Details

.attr_namesArray<Symbol>

Returns:

  • (Array<Symbol>)


40
41
42
# File 'lib/yoda/store/objects/method_object.rb', line 40

def attr_names
  super + %i(parameters visibility overloads)
end

.name_of_path(path) ⇒ String

Parameters:

  • path (String)

Returns:

  • (String)


29
30
31
# File 'lib/yoda/store/objects/method_object.rb', line 29

def name_of_path(path)
  divide_by_separator(path)&.at(2)
end

.namespace_of_path(path) ⇒ String

Parameters:

  • path (String)

Returns:

  • (String)


23
24
25
# File 'lib/yoda/store/objects/method_object.rb', line 23

def namespace_of_path(path)
  divide_by_separator(path)&.at(0)
end

.sep_of_path(path) ⇒ String?

Parameters:

  • path (String)

Returns:

  • (String, nil)


35
36
37
# File 'lib/yoda/store/objects/method_object.rb', line 35

def sep_of_path(path)
  divide_by_separator(path)&.at(1)
end

Instance Method Details

#kindObject



101
102
103
# File 'lib/yoda/store/objects/method_object.rb', line 101

def kind
  :method
end

#nameString

Returns:

  • (String)


73
74
75
# File 'lib/yoda/store/objects/method_object.rb', line 73

def name
  @name ||= MethodObject.name_of_path(path)
end

#namespace_pathString

Returns:

  • (String)


83
84
85
# File 'lib/yoda/store/objects/method_object.rb', line 83

def namespace_path
  @namespace_path ||= MethodObject.namespace_of_path(path)
end

#parent_addressString

Returns:

  • (String)


88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/yoda/store/objects/method_object.rb', line 88

def parent_address
  @parent_address ||= begin
    case MethodObject.sep_of_path(path)
    when '#'
      namespace_path
    when '.', '::'
      MetaClassObject.address_of(namespace_path)
    else
      fail TypeError
    end
  end
end

#sepString

Returns:

  • (String)


78
79
80
# File 'lib/yoda/store/objects/method_object.rb', line 78

def sep
  @sep ||= MethodObject.sep_of_path(path)
end

#to_hObject



105
106
107
108
109
110
111
# File 'lib/yoda/store/objects/method_object.rb', line 105

def to_h
  super.merge(
    parameters: parameters.to_a,
    visibility: visibility,
    overloads: overloads,
  )
end