class Detroit::Toolchain::Script
Assembly::Script models an *Assembly file* with it’s collection of tool configurations.
Attributes
project[R]
Project
instance.
tools[R]
Hash
table of tool configuration.
Public Class Methods
load(input, project=nil)
click to toggle source
Load Assembly
file.
# File lib/detroit/toolchain/script.rb, line 11 def self.load(input, project=nil) new(:file=>input,:project=>project) end
new(options={}, &block)
click to toggle source
# File lib/detroit/toolchain/script.rb, line 24 def initialize(options={}, &block) @project = options[:project] @tools = {} if options[:file] initialize_file(options[:file]) end if block instance_eval(&block) end end
Public Instance Methods
custom(name, &block)
click to toggle source
Define a custom tool. A custom tool has no tool class. Instead, the configuration itself defines the procedure.
# File lib/detroit/toolchain/script.rb, line 82 def custom(name, &block) context = CustomContext.new(&block) settings = context.settings @tools[name.to_s] = settings.rekey(&:to_s) end
tool(name, settings={}, &block)
click to toggle source
Configure a tool.
# File lib/detroit/toolchain/script.rb, line 70 def tool(name, settings={}, &block) settings[:track] = @_track if @_track if block block_context = BlockContext.new(&block) settings.update(block_context.settings) end @tools[name.to_s] = settings.rekey(&:to_s) end
track(name, &block)
click to toggle source
Ecapsulate a set of tools within a specific track.
# File lib/detroit/toolchain/script.rb, line 62 def track(name, &block) @_track = name instance_eval(&block) @_track = nil end
Private Instance Methods
erb(text)
click to toggle source
Process Routine document via ERB.
# File lib/detroit/toolchain/script.rb, line 121 def erb(text) context = ERBContext.new(project) ERB.new(text).result(context.__binding__) end
initialize_file(file)
click to toggle source
Inititalize from assembly file.
# File lib/detroit/toolchain/script.rb, line 40 def initialize_file(file) @file = (String === file ? File.new(file) : file) case File.extname(@file.path) when '.rb' instance_eval(@file.read, @file.path) when '.yml', '.yaml' @tools = YAML.load(erb(@file.read)) else text = @file.read if /^---/ =~ text @tools = YAML.load(erb(text)) else instance_eval(text, @file.path) end end end
method_missing(sym, *args, &block)
click to toggle source
Capitalized tool names called as methods can also define a tool.
Calls superclass method
# File lib/detroit/toolchain/script.rb, line 99 def method_missing(sym, *args, &block) tool_class = sym.to_s case tool_class when /^[A-Z]/ if Hash === args.last args.last[:tool] = tool_class else args << {:tool=>tool_class} end case args.first when String, Symbol name = args.first else name = tool_class.to_s.downcase end tool(name, *args, &block) else super(sym, *args, &block) end end