Module: Inlay::PryIntegration

Defined in:
lib/inlay/pry.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.original ⇒ Object (readonly)

Returns the value of attribute original.



9
10
11
# File 'lib/inlay/pry.rb', line 9

def original
  @original
end

.wrapper ⇒ Object (readonly)

Returns the value of attribute wrapper.



9
10
11
# File 'lib/inlay/pry.rb', line 9

def wrapper
  @wrapper
end

Class Method Details

.install ⇒ Object



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

def install
  return true if Pry.config.print.equal?(@wrapper)

  @original = Pry.config.print
  @wrapper = proc do |output, value, pry_instance|
    begin
      value = Inlay.show(value) if Inlay.displayable?(value)
    rescue StandardError
      # Preserve Pry's configured printer if image rendering fails.
    end
    @original.call(output, value, pry_instance)
  end
  Pry.config.print = @wrapper
  true
end

.uninstall ⇒ Object



27
28
29
30
31
32
33
# File 'lib/inlay/pry.rb', line 27

def uninstall
  return false unless @wrapper && Pry.config.print.equal?(@wrapper)

  Pry.config.print = @original
  @wrapper = @original = nil
  true
end