Class: YARD::Handlers::Ruby::ActiveRecord2::Fields::FieldHandler

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

Instance Method Summary collapse

Instance Method Details

#description(method_name) ⇒ Object



42
43
44
# File 'lib/yard-activerecord2/fields/field_handler.rb', line 42

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

#get_tag(tag, text, return_classes) ⇒ Object



46
47
48
# File 'lib/yard-activerecord2/fields/field_handler.rb', line 46

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

#processObject



10
11
12
13
14
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
# File 'lib/yard-activerecord2/fields/field_handler.rb', line 10

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

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

  if class_name == "Datetime"
    class_name = "DateTime"
  end
  ensure_loaded! P(globals.klass)
  namespace = P(globals.klass)
  return if namespace.nil?

  r_object = YARD::CodeObjects::MethodObject.new(namespace, method_name)
  r_object.docstring = description(method_name)
  r_object.docstring.add_tag get_tag(:return, '', class_name)
  r_object.dynamic = true
  register r_object

  w_object = YARD::CodeObjects::MethodObject.new(namespace, "#{method_name}=")
  w_object.docstring = description(method_name)
  w_object.docstring.add_tag get_tag(:return, '', class_name)
  w_object.dynamic = true
  register w_object

  namespace.instance_attributes[method_name.to_sym] = {
    read: r_object,
    write: w_object
  }
end