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

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

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

Methods included from Serializable

#derive, 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 (TagList, nil)
  • visibility (Symbol) (defaults to: :public)
  • overloads (Array<Overload>) (defaults to: [])
  • parameters (Array<(String, String)>, nil) (defaults to: [])


45
46
47
48
49
50
51
# File 'lib/yoda/store/objects/method_object.rb', line 45

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:



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

def overloads
  @overloads
end

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

Returns:

  • (Array<(String, String)>)


6
7
8
# File 'lib/yoda/store/objects/method_object.rb', line 6

def parameters
  @parameters
end

#visibilitySymbol (readonly)

Returns:

  • (Symbol)


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

def visibility
  @visibility
end

Class Method Details

.attr_namesArray<Symbol>

Returns:

  • (Array<Symbol>)


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

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

.name_of_path(path) ⇒ String

Parameters:

  • path (String)

Returns:

  • (String)


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

def name_of_path(path)
  path.slice((path.rindex(/[#.]/) || -1) + 1, path.length)
end

.namespace_of_path(path) ⇒ String

Parameters:

  • path (String)

Returns:

  • (String)


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

def namespace_of_path(path)
  path.slice(0, (path.rindex(/[#.]/) || 0))
end

.sep_of_path(path) ⇒ String

Parameters:

  • path (String)

Returns:

  • (String)


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

def sep_of_path(path)
  path.slice(path.rindex(/[#.]/))
end

Instance Method Details

#kindObject



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

def kind
  :method
end

#nameString

Returns:

  • (String)


54
55
56
# File 'lib/yoda/store/objects/method_object.rb', line 54

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

#namespace_pathString

Returns:

  • (String)


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

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

#sepString

Returns:

  • (String)


59
60
61
# File 'lib/yoda/store/objects/method_object.rb', line 59

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

#to_hObject



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

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