Class: YARD::Virtus::CodeObjects::AttributeWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/yard/virtus/code_objects/attribute_writer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attr, type, is_private = false) ⇒ AttributeWriter

Returns a new instance of AttributeWriter.

Parameters:

  • attr (Symbol)

    name of attribute

  • type (String)

    string representation of type in YARD format

  • is_private (Boolean) (defaults to: false)

    indicates if writer is part of private API



10
11
12
13
14
# File 'lib/yard/virtus/code_objects/attribute_writer.rb', line 10

def initialize(attr, type, is_private=false)
  @attr_name = attr
  @type      = type
  @is_private = is_private
end

Instance Attribute Details

#attr_nameObject (readonly)

Returns the value of attribute attr_name.



5
6
7
# File 'lib/yard/virtus/code_objects/attribute_writer.rb', line 5

def attr_name
  @attr_name
end

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'lib/yard/virtus/code_objects/attribute_writer.rb', line 5

def type
  @type
end

Instance Method Details

#method_nameObject



16
17
18
# File 'lib/yard/virtus/code_objects/attribute_writer.rb', line 16

def method_name
  :"#{attr_name}="
end

#yard_method_object(namespace) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/yard/virtus/code_objects/attribute_writer.rb', line 20

def yard_method_object(namespace)
  YARD::CodeObjects::MethodObject.new(namespace, method_name, :instance).tap do |mo|
    mo.parameters = [["value", default_value]]
    mo.add_tag param_tag("value", type)
    mo.add_tag private_tag if private?
  end
end