Class: YARD::Virtus::Declarations::Type

Inherits:
Object
  • Object
show all
Defined in:
lib/yard/virtus/declarations/type.rb

Overview

Type declaration wraps AST which represents type of Virtus attribute

Examples:

ast = s(:call, s(:var_ref, s(:const, "Virtus")), :".", s(:ident, "model"))
d   = VirtusModel.new(ast)
d.module_proxies_in_ns(ns) # => P("Virtus.model")

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ast) ⇒ Type

Returns a new instance of Type.



16
17
18
# File 'lib/yard/virtus/declarations/type.rb', line 16

def initialize(ast)
  @ast = ast
end

Instance Attribute Details

#astObject (readonly)

Returns the value of attribute ast.



13
14
15
# File 'lib/yard/virtus/declarations/type.rb', line 13

def ast
  @ast
end

Instance Method Details

#yard_type_stringObject



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/yard/virtus/declarations/type.rb', line 20

def yard_type_string
  if association?(ast)
    yard_type_from_association(ast)
  elsif collection?(ast)
    yard_type_from_collection(ast)
  elsif ast.ref?
    yard_type_from_reference(ast)
  elsif !ast[0].nil?
    Type.new(ast[0]).yard_type_string
  else
    nil
  end
end