Module: Inlay

Defined in:
lib/inlay.rb,
lib/inlay/irb.rb,
lib/inlay/pry.rb,
lib/inlay/iruby.rb,
lib/inlay/sizer.rb,
lib/inlay/config.rb,
lib/inlay/summary.rb,
lib/inlay/version.rb,
lib/inlay/adapters.rb,
lib/inlay/normalizer.rb,
lib/inlay/terminal_output.rb,
sig/inlay.rbs,
sig/inlay.rbs

Defined Under Namespace

Modules: Adapters, IRBIntegration, IRubyIntegration, Normalizer, PryIntegration, Sizer, Summary, TerminalOutput Classes: Config, Error, Normalized

Constant Summary collapse

VERSION =
"0.2.2"

Class Method Summary collapse

Class Method Details

.config ⇒ Config

Returns:



18
19
20
# File 'lib/inlay.rb', line 18

def config
  @config ||= Config.new
end

.displayable?(object) ⇒ Boolean

Parameters:

  • object (Object)

Returns:

  • (Boolean)


32
33
34
35
36
37
# File 'lib/inlay.rb', line 32

def displayable?(object)
  normalized = normalize(object)
  !!(normalized.image || normalized.svg || normalized.png || normalized.frames)
rescue StandardError
  false
end

.html ⇒ String?

Parameters:

  • object (Object)

Returns:

  • (String, nil)


31
# File 'sig/inlay.rbs', line 31

def self.html: (untyped object) -> String?

.install ⇒ Boolean

Returns:

  • (Boolean)


30
# File 'sig/inlay.rbs', line 30

def self.install: () -> bool

.irb_install! ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
46
# File 'lib/inlay.rb', line 43

def irb_install!
  require_relative "inlay/irb"
  IRBIntegration.install
end

.irb_uninstall! ⇒ bool?

Returns:

  • (bool, nil)


48
49
50
# File 'lib/inlay.rb', line 48

def irb_uninstall!
  IRBIntegration.uninstall if defined?(IRBIntegration)
end

.mimebundle ⇒ [Hash[String, String], Hash[untyped, untyped]]

Parameters:

  • object (Object)
  • include: (Array[String])

Returns:

  • ([Hash[String, String], Hash[untyped, untyped]])


34
# File 'sig/inlay.rbs', line 34

def self.mimebundle: (untyped object, ?include: Array[String]) -> [Hash[String, String], Hash[untyped, untyped]]

.normalize(object, allow_path: false) ⇒ Normalized

Parameters:

  • object (Object)
  • allow_path: (Boolean) (defaults to: false)

Returns:



28
29
30
# File 'lib/inlay.rb', line 28

def normalize(object, allow_path: false)
  Normalizer.call(object, allow_path: allow_path)
end

.png ⇒ String?

Parameters:

  • object (Object)

Returns:

  • (String, nil)


33
# File 'sig/inlay.rbs', line 33

def self.png: (untyped object) -> String?

.protocol ⇒ Symbol

Returns:

  • (Symbol)


39
40
41
# File 'lib/inlay.rb', line 39

def protocol
  TerminalOutput.protocol
end

.register(klass) {|object| ... } ⇒ Object

Parameters:

  • klass (Module)

Yields:

Yield Parameters:

  • object (Object)

Yield Returns:

  • (Object)

Returns:

  • (Object)

Raises:

  • (ArgumentError)


22
23
24
25
26
# File 'lib/inlay.rb', line 22

def register(klass, &adapter)
  raise ArgumentError, "an adapter block is required" unless adapter

  Adapters.register(klass, adapter)
end

.show(object, width: nil, height: nil, scale: :auto, protocol: nil) ⇒ String

Parameters:

  • object (Object)
  • width: (Integer, nil) (defaults to: nil)
  • height: (Integer, nil) (defaults to: nil)
  • scale: (Symbol) (defaults to: :auto)
  • protocol: (Symbol, nil) (defaults to: nil)

Returns:

  • (String)


52
53
54
55
56
57
58
59
60
# File 'lib/inlay.rb', line 52

def show(object, width: nil, height: nil, scale: :auto, protocol: nil)
  normalized = normalize(object, allow_path: true)
  image = Normalizer.terminal_image(normalized)
  normalized.image ||= image
  summary = Summary.call(object, normalized)
  return summary unless image && TerminalOutput.write(image, width: width, height: height, scale: scale, protocol: protocol)

  summary
end

.svg ⇒ String?

Parameters:

  • object (Object)

Returns:

  • (String, nil)


32
# File 'sig/inlay.rbs', line 32

def self.svg: (untyped object) -> String?