Class: Kefka::Method

Inherits:
Object
  • Object
show all
Defined in:
lib/kefka.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Method

Returns a new instance of Method.

Raises:

  • (ArgumentError)


49
50
51
52
53
54
55
56
# File 'lib/kefka.rb', line 49

def initialize(options={})
  raise ArgumentError, "missing file + line" unless options[:file] && options[:line]
  @classname  = options[:classname]
  @id         = options[:id]
  @file       = options[:file]
  @start_line = options[:line]
  @format     = options[:format] || :plain
end

Instance Attribute Details

#classnameObject (readonly)

Returns the value of attribute classname.



46
47
48
# File 'lib/kefka.rb', line 46

def classname
  @classname
end

#depthObject

Returns the value of attribute depth.



47
48
49
# File 'lib/kefka.rb', line 47

def depth
  @depth
end

#fileObject (readonly)

Returns the value of attribute file.



46
47
48
# File 'lib/kefka.rb', line 46

def file
  @file
end

#formatObject

Returns the value of attribute format.



47
48
49
# File 'lib/kefka.rb', line 47

def format
  @format
end

#idObject (readonly)

Returns the value of attribute id.



46
47
48
# File 'lib/kefka.rb', line 46

def id
  @id
end

#lineObject (readonly)

Returns the value of attribute line.



46
47
48
# File 'lib/kefka.rb', line 46

def line
  @line
end

#sourceObject

Returns the value of attribute source.



47
48
49
# File 'lib/kefka.rb', line 47

def source
  @source
end

Instance Method Details

#contains?(file, line) ⇒ Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/kefka.rb', line 70

def contains?(file, line)
  @file == file && @start_line <= line && end_line > line
end

#end_lineObject



62
63
64
# File 'lib/kefka.rb', line 62

def end_line
  @start_line + source.lines.count - 1
end

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


102
103
104
# File 'lib/kefka.rb', line 102

def eql?(other)
  self.key == other.key
end

#formatted_sourceObject



83
84
85
86
87
88
89
90
# File 'lib/kefka.rb', line 83

def formatted_source
  if @format == :html
    CodeRay.scan(source, :ruby)
           .div(:line_numbers => :table, :line_number_start => @start_line)
  else
    source
  end
end

#hashObject



108
109
110
# File 'lib/kefka.rb', line 108

def hash
  [@file,@start_line].hash
end

#keyObject



66
67
68
# File 'lib/kefka.rb', line 66

def key
  source_location ? [id,source_location].flatten.join(":") : nil
end

#source_at_line(line) ⇒ Object



92
93
94
95
96
# File 'lib/kefka.rb', line 92

def source_at_line(line)
  # what if source is not known, ie. eval
  index = line - @start_line
  source.lines.take(index + 1)[index]
end

#source_locationObject



58
59
60
# File 'lib/kefka.rb', line 58

def source_location
  [@file,@start_line]
end

#to_json(*a) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
# File 'lib/kefka.rb', line 112

def to_json(*a)
  {
    :classname => @classname,
    :id => @id.to_s,
    :file => @file,
    :line => @start_line,
    :end_line => end_line,
    :depth => depth,
    :source => formatted_source
  }.to_json(*a)
end

#to_sObject



98
99
100
# File 'lib/kefka.rb', line 98

def to_s
  "#{classname} #{id}"
end