Class: Declare::CallerEntry

Inherits:
Struct
  • Object
show all
Defined in:
lib/declare/callerentry.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#block_levelObject

Returns the value of attribute block_level

Returns:

  • (Object)

    the current value of block_level



5
6
7
# File 'lib/declare/callerentry.rb', line 5

def block_level
  @block_level
end

#file_nameObject

Returns the value of attribute file_name

Returns:

  • (Object)

    the current value of file_name



5
6
7
# File 'lib/declare/callerentry.rb', line 5

def file_name
  @file_name
end

#line_numberObject

Returns the value of attribute line_number

Returns:

  • (Object)

    the current value of line_number



5
6
7
# File 'lib/declare/callerentry.rb', line 5

def line_number
  @line_number
end

#method_nameObject

Returns the value of attribute method_name

Returns:

  • (Object)

    the current value of method_name



5
6
7
# File 'lib/declare/callerentry.rb', line 5

def method_name
  @method_name
end

Class Method Details

.parse(caller_entry) ⇒ CallerEntry

Parameters:

  • caller_entry (String)

Returns:



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/declare/callerentry.rb', line 9

def parse(caller_entry)
  matched = /\A(?<file_name>.+?):(?<line_number>\d+)(?::in `(?<method_name>.*)')?/.match(caller_entry)
  if matched
    block_level = case matched[:method_name]
                  when /block \((\d+) levels\)/
                    Regexp.last_match(1).to_i
                  when /block/
                    1
                  else
                    0
                  end

    new(file_name: matched[:file_name], line_number: Integer(matched[:line_number]), method_name: matched[:method_name], block_level:)
  else
    raise TypeError, caller_entry
  end
end

Instance Method Details

#to_sString

Returns:

  • (String)


29
30
31
# File 'lib/declare/callerentry.rb', line 29

def to_s
  "#{file_name}:#{line_number}"
end