Class: RDoc::ArAssociation

Inherits:
Context
  • Object
show all
Includes:
TokenStream
Defined in:
lib/rdoc_rails/rdoc/ar_association.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(init = {}) ⇒ ArAssociation

Returns a new instance of ArAssociation.



21
22
23
24
# File 'lib/rdoc_rails/rdoc/ar_association.rb', line 21

def initialize(init={})
  super()
  init.each{ |k,v| send("#{k}=", v) }
end

Instance Attribute Details

#atypeObject

Returns the value of attribute atype.



17
18
19
# File 'lib/rdoc_rails/rdoc/ar_association.rb', line 17

def atype
  @atype
end

#nameObject

Returns the value of attribute name.



18
19
20
# File 'lib/rdoc_rails/rdoc/ar_association.rb', line 18

def name
  @name
end

#optsObject



26
27
28
# File 'lib/rdoc_rails/rdoc/ar_association.rb', line 26

def opts
  @opts || {}
end

Instance Method Details

#add_line_numbers(src) ⇒ Object

Pulled from RDoc::Generator::Markup Would be nice if this were moved into a module so it could be includable without copy/paste.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/rdoc_rails/rdoc/ar_association.rb', line 44

def add_line_numbers(src)
  if src =~ /\A.*, line (\d+)/ then
    first = $1.to_i - 1
    last  = first + src.count("\n")
    size = last.to_s.length
    
    line = first
    src.gsub!(/^/) do
      res = if line == first
              " " * (size + 2)
            else
              "%#{size}d: " % line
            end
      
      line += 1
      res
    end
  end
end

#class_nameObject



30
31
32
33
34
35
# File 'lib/rdoc_rails/rdoc/ar_association.rb', line 30

def class_name
  class_name   = opts[:class_name]
  class_name ||= ActiveSupport::Inflector.classify(name) if ['has_many', 'has_and_belongs_to_many'].include?(atype.to_s)
  class_name ||= name.camelize
  class_name
end

#markup_codeObject

Pulled from RDoc::Generator::Markup Would be nice if this were moved into a module so it could be includable without copy/paste.



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/rdoc_rails/rdoc/ar_association.rb', line 67

def markup_code
  return '' unless @token_stream
  
  src = ""
  
  @token_stream.each do |t|
    next unless t
    #        style = STYLE_MAP[t.class]
    style = case t
              when RDoc::RubyToken::TkCONSTANT then "ruby-constant"
              when RDoc::RubyToken::TkKW       then "ruby-keyword kw"
              when RDoc::RubyToken::TkIVAR     then "ruby-ivar"
              when RDoc::RubyToken::TkOp       then "ruby-operator"
              when RDoc::RubyToken::TkId       then "ruby-identifier"
              when RDoc::RubyToken::TkNode     then "ruby-node"
              when RDoc::RubyToken::TkCOMMENT  then "ruby-comment cmt"
              when RDoc::RubyToken::TkREGEXP   then "ruby-regexp re"
              when RDoc::RubyToken::TkSTRING   then "ruby-value str"
              when RDoc::RubyToken::TkVal      then "ruby-value"
              else nil
            end
    
    text = CGI.escapeHTML(t.text)
    
    if style
      src << "<span class=\"#{style}\">#{text}</span>"
    else
      src << text
    end
  end
  
#    add_line_numbers src if RDoc::RDoc.current.options.include_line_numbers
# change for rdoc > 2.4.3
  
  src
end

#pathObject



37
38
39
# File 'lib/rdoc_rails/rdoc/ar_association.rb', line 37

def path
  parent.path
end