Class: YARD::DM::HasHandler

Inherits:
Handlers::Ruby::Base
  • Object
show all
Includes:
Extensions
Defined in:
lib/yard-dm/has_handler.rb

Instance Method Summary collapse

Instance Method Details

#processObject



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
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/yard-dm/has_handler.rb', line 11

def process
  args = statement.parameters
  n = args[0]
  name = args[1].last

  return unless name.type == :symbol

  return unless (
    (n.type == :int && n.source =~ /^[1-9]\d*$/) ||
    (n.type == :var_ref && n.source == 'n') ||
    (n.type == :dot2 && (
      (n[0].type == :int && n[0].source =~ /^[0-9]\d*$/) || (
        (n[1].type == :int && n[1].source =~ /^[1-9]\d*$/) ||
        (n[1].type == :var_ref && n[1].source == 'n')
      )
    ))
  )

  nobj = effected_namespace
  mscope = scope
  name = name.source[1..-1]

  register MethodObject.new(nobj, name, :class) do |o|
    o.visibility = :public
    o.source = statement.source
    o.signature = "def self.#{name}"
    o.parameters = [['repository', 'nil']]
  end

  register MethodObject.new(nobj, name, mscope) do |o|
    o.visibility = :public
    o.source = statement.source
    o.signature = "def #{name}"
  end

  register MethodObject.new(nobj, "#{name}=", mscope) do |o|
    o.visibility = :public
    o.source = statement.source
    o.signature = "def #{name}="
    o.parameters = [["new_#{name}", nil]]
  end
end