Class: Detroit::Toolchain::Script
- Defined in:
- lib/detroit/toolchain/script.rb
Overview
Assembly::Script models an *Assembly file* with it’s collection of tool configurations.
Defined Under Namespace
Classes: BlockContext, CustomContext, ERBContext
Instance Attribute Summary collapse
-
#project ⇒ Object
readonly
Access to project metadata.
-
#tools ⇒ Object
readonly
Hash table of tool configuration.
Class Method Summary collapse
-
.load(input, project = nil) ⇒ Object
Load Assembly file.
Instance Method Summary collapse
-
#custom(name, &block) ⇒ Object
Define a custom tool.
-
#tool(name, settings = {}, &block) ⇒ Object
Configure a tool.
-
#track(name, &block) ⇒ Object
Ecapsulate a set of tools within a specific track.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object (private)
Capitalized tool names called as methods can also define a tool.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# 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 |
Instance Attribute Details
#project ⇒ Object (readonly)
Access to project metadata.
FIXME: Use factory method
16 17 18 |
# File 'lib/detroit/toolchain/script.rb', line 16 def project @project end |
#tools ⇒ Object (readonly)
Hash table of tool configuration.
19 20 21 |
# File 'lib/detroit/toolchain/script.rb', line 19 def tools @tools end |
Class Method Details
.load(input, project = nil) ⇒ Object
Load Assembly file.
11 12 13 |
# File 'lib/detroit/toolchain/script.rb', line 11 def self.load(input, project=nil) new(:file=>input,:project=>project) end |
Instance Method Details
#custom(name, &block) ⇒ Object
Define a custom tool. A custom tool has no tool class. Instead, the configuration itself defines the procedure.
82 83 84 85 86 |
# 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) ⇒ Object
Configure a tool.
70 71 72 73 74 75 76 77 |
# 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) ⇒ Object
Ecapsulate a set of tools within a specific track.
62 63 64 65 66 |
# File 'lib/detroit/toolchain/script.rb', line 62 def track(name, &block) @_track = name instance_eval(&block) @_track = nil end |