Class: Logue::Frame

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

Constant Summary collapse

FRAME_RE =
Regexp.new '(.*):(\d+)(?::in \`(.*)\')?'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entry: nil, path: nil, line: nil, method: nil) ⇒ Frame

Returns a new instance of Frame.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/logue/frame.rb', line 14

def initialize entry: nil, path: nil, line: nil, method: nil
  # entry if called from "caller(x)" elements, path/line/method if called from
  # "caller_location(x)" elements.
  if entry
    md = FRAME_RE.match entry
    @path   = md[1]
    @line   = md[2].to_i
    @method = md[3] || ""
  else
    @path   = path
    @line   = line
    @method = method
  end
end

Instance Attribute Details

#lineObject (readonly)

Returns the value of attribute line.



11
12
13
# File 'lib/logue/frame.rb', line 11

def line
  @line
end

#methodObject (readonly)

Returns the value of attribute method.



12
13
14
# File 'lib/logue/frame.rb', line 12

def method
  @method
end

#pathObject (readonly)

Returns the value of attribute path.



10
11
12
# File 'lib/logue/frame.rb', line 10

def path
  @path
end

Instance Method Details

#formatted(format, cname) ⇒ Object



33
34
35
# File 'lib/logue/frame.rb', line 33

def formatted format, cname
  format.format @path, @line, cname, @method
end

#to_sObject



29
30
31
# File 'lib/logue/frame.rb', line 29

def to_s
  [ :path, :line, :method ].collect { |field| "#{field}: " + send(field).to_s }.join ", "
end