Class: YARD::Handlers::Ruby::ActiveRecord::Fields::FieldHandler

Inherits:
MethodHandler
  • Object
show all
Defined in:
lib/yard-activerecord/fields/field_handler.rb

Instance Method Summary collapse

Instance Method Details

#description(method_name) ⇒ Object



43
44
45
# File 'lib/yard-activerecord/fields/field_handler.rb', line 43

def description(method_name)
  '' # "Database field value of #{method_name}. Defined in {file:db/schema.rb}"
end

#get_tag(tag, text, return_classes) ⇒ Object



47
48
49
# File 'lib/yard-activerecord/fields/field_handler.rb', line 47

def get_tag(tag, text, return_classes)
  YARD::Tags::Tag.new(:return, text, [return_classes].flatten)
end

#processObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/yard-activerecord/fields/field_handler.rb', line 15

def process
  return unless statement.namespace.jump(:ident).source == 't'
  method_name = call_params.first

  return if method_name['_id'] # Skip all id fields, associations will handle that

  ensure_loaded! P(globals.klass)
  namespace = P(globals.klass)
  return if namespace.nil?

  method_definition = namespace.instance_attributes[method_name.to_sym] || {}

  { read: method_name, write: "#{method_name}=" }.each do |(rw, name)|
    method = method_definition[rw]
    if method
      method.docstring.add_tag( get_tag(:return, '', class_name) ) unless method.has_tag?( :return )
      next
    end
    rw_object = register YARD::CodeObjects::MethodObject.new(namespace, name)
    rw_object.docstring = description(name)
    rw_object.docstring.add_tag get_tag(:return, '', class_name)
    rw_object.dynamic = true
    method_definition[rw] = rw_object
  end

  namespace.instance_attributes[method_name.to_sym] = method_definition
end