Class: Truffle::Toolbox

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/truffle/toolbox.rb

Overview

An ordered collection of tools the agent can reach for, keyed by name.

Instance Method Summary collapse

Constructor Details

#initialize(tools = []) ⇒ Toolbox

Returns a new instance of Toolbox.



8
9
10
11
# File 'lib/truffle/toolbox.rb', line 8

def initialize(tools = [])
  @tools = {}
  Array(tools).each { |t| add(t) }
end

Instance Method Details

#[](name) ⇒ Object



19
20
21
# File 'lib/truffle/toolbox.rb', line 19

def [](name)
  @tools[name.to_s]
end

#add(tool) ⇒ Object Also known as: <<



13
14
15
16
# File 'lib/truffle/toolbox.rb', line 13

def add(tool)
  @tools[tool.name] = tool
  self
end

#each(&block) ⇒ Object



23
24
25
# File 'lib/truffle/toolbox.rb', line 23

def each(&block)
  @tools.values.each(&block)
end

#empty?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/truffle/toolbox.rb', line 27

def empty?
  @tools.empty?
end

#namesObject



31
32
33
# File 'lib/truffle/toolbox.rb', line 31

def names
  @tools.keys
end

#to_schemaObject

Provider-neutral schemas for every tool, in declared order.



36
37
38
# File 'lib/truffle/toolbox.rb', line 36

def to_schema
  @tools.values.map(&:to_schema)
end