Class: CallerWithContext::Caller
- Inherits:
-
Object
- Object
- CallerWithContext::Caller
- Defined in:
- lib/caller_with_context/caller.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #format_single_location(location) ⇒ Object
-
#initialize(options = {}) ⇒ Caller
constructor
A new instance of Caller.
- #locations ⇒ Object
- #output(string, color) ⇒ Object
- #show ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Caller
Returns a new instance of Caller.
8 9 10 11 12 13 14 |
# File 'lib/caller_with_context/caller.rb', line 8 def initialize(={}) @options = { colorize: true, only_cwd: false, lines_of_context: 1 }.merge() end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/caller_with_context/caller.rb', line 6 def @options end |
Instance Method Details
#format_single_location(location) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/caller_with_context/caller.rb', line 39 def format_single_location(location) output(location.to_s, :light_blue) if [:lines_of_context] > 0 location.context_lines.each do |line| puts line end puts end end |
#locations ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/caller_with_context/caller.rb', line 16 def locations return @locations if @locations locations = caller_locations if @options[:only_cwd] locations.select! { |l| l.to_s.include?(Dir.pwd) } end @locations ||= locations.map { |location| Location.new(location, [:lines_of_context]) } end |
#output(string, color) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/caller_with_context/caller.rb', line 31 def output(string, color) if [:colorize] puts string.send(color) else puts string end end |
#show ⇒ Object
25 26 27 28 29 |
# File 'lib/caller_with_context/caller.rb', line 25 def show locations.each do |location| format_single_location location end end |