Class: Irbs::AttributeWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/irbs/attribute_wrapper.rb

Overview

return value of ‘YARD::CodeObjects::NamespaceObject#attributes`

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scope, name, attr_meths) ⇒ AttributeWrapper

Returns a new instance of AttributeWrapper.



25
26
27
28
29
30
# File 'lib/irbs/attribute_wrapper.rb', line 25

def initialize(scope, name, attr_meths)
  @scope = scope
  @name = name
  @reader = attr_meths[:read]
  @writer = attr_meths[:write]
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



18
19
20
# File 'lib/irbs/attribute_wrapper.rb', line 18

def name
  @name
end

#readerObject (readonly)

Returns the value of attribute reader.



20
21
22
# File 'lib/irbs/attribute_wrapper.rb', line 20

def reader
  @reader
end

#scopeObject (readonly)

Returns the value of attribute scope.



16
17
18
# File 'lib/irbs/attribute_wrapper.rb', line 16

def scope
  @scope
end

#writerObject (readonly)

Returns the value of attribute writer.



22
23
24
# File 'lib/irbs/attribute_wrapper.rb', line 22

def writer
  @writer
end

Class Method Details

.parse(attributes) ⇒ Object



9
10
11
12
13
# File 'lib/irbs/attribute_wrapper.rb', line 9

def self.parse(attributes)
  attributes.map{|scope, attr_data|
    attr_data.map{|name, attr_meths| new(scope, name, attr_meths) }
  }.flatten
end

Instance Method Details

#sigObject



51
52
53
# File 'lib/irbs/attribute_wrapper.rb', line 51

def sig
  (reader || writer)&.tag(:sig)&.text
end

#typeObject



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/irbs/attribute_wrapper.rb', line 33

def type
  if reader && writer
    :accessor
  elsif reader
    :reader
  elsif writer
    :writer
  else
    raise StandardError
  end
end

#visibilityObject



46
47
48
# File 'lib/irbs/attribute_wrapper.rb', line 46

def visibility
  (reader || writer)&.visibility
end