Class: Regent::Toolchain

Inherits:
Object
  • Object
show all
Defined in:
lib/regent/toolchain.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tools) ⇒ Toolchain

Returns a new instance of Toolchain.



5
6
7
# File 'lib/regent/toolchain.rb', line 5

def initialize(tools)
  @tools = tools
end

Instance Attribute Details

#toolsObject (readonly)

Returns the value of attribute tools.



9
10
11
# File 'lib/regent/toolchain.rb', line 9

def tools
  @tools
end

Instance Method Details

#add(tool, context) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/regent/toolchain.rb', line 15

def add(tool, context)
  @tools << Regent::Tool.new(name: tool[:name].to_s, description: tool[:description]).instance_eval do
    raise "A tool method '#{tool[:name]}' is missing in the #{context.class.name}" unless context.respond_to?(tool[:name])

    define_singleton_method(:call){ |*args| context.send(tool[:name], *args) }
    self
  end
end

#find(name) ⇒ Object



11
12
13
# File 'lib/regent/toolchain.rb', line 11

def find(name)
  tools.find { |tool| tool.name.downcase == name.downcase }
end

#to_sObject



24
25
26
# File 'lib/regent/toolchain.rb', line 24

def to_s
  tools.map(&:to_s).join("\n")
end