Class: Regent::Toolchain
- Inherits:
-
Object
- Object
- Regent::Toolchain
- Defined in:
- lib/regent/toolchain.rb
Instance Attribute Summary collapse
-
#tools ⇒ Object
readonly
Returns the value of attribute tools.
Instance Method Summary collapse
- #add(tool, context) ⇒ Object
- #find(name) ⇒ Object
-
#initialize(tools) ⇒ Toolchain
constructor
A new instance of Toolchain.
- #to_s ⇒ Object
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
#tools ⇒ Object (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_s ⇒ Object
24 25 26 |
# File 'lib/regent/toolchain.rb', line 24 def to_s tools.map(&:to_s).join("\n") end |