Class: R::TargetGenerator
- Inherits:
-
TargetSmart
- Object
- Target
- TargetSmart
- R::TargetGenerator
- Defined in:
- lib/rub/r/targetgenerator.rb
Overview
A target that executes a command.
This is a target that executes a command. It can be used directly but it is easier and prettier to use C.generator
Direct Known Subclasses
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
Attributes inherited from TargetSmart
Instance Method Summary collapse
-
#add_cmd(cmd) ⇒ Array<String>
Add a command to be executed.
-
#add_cmds(cmds) ⇒ Array<Array<String>>
Add multiple commands.
- #build_self ⇒ Object
- #hash_input ⇒ Object
-
#initialize ⇒ TargetGenerator
constructor
A new instance of TargetGenerator.
Methods inherited from TargetSmart
Methods inherited from Target
#build, #clean?, #description, #hash_output, #hash_outputs, #hash_self, #input, #output, #register
Constructor Details
#initialize ⇒ TargetGenerator
Returns a new instance of TargetGenerator.
33 34 35 36 37 38 39 |
# File 'lib/rub/r/targetgenerator.rb', line 33 def initialize super @action = 'Building' @cmd = [] end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
31 32 33 |
# File 'lib/rub/r/targetgenerator.rb', line 31 def action @action end |
Instance Method Details
#add_cmd(cmd) ⇒ Array<String>
Add a command to be executed.
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rub/r/targetgenerator.rb', line 45 def add_cmd(cmd) cmd = cmd.map{|a| a.to_s} exe = C.find_command(cmd[0]) if not exe raise "Can't find #{cmd[0]}." exit 1 end cmd[0] = exe @input << cmd[0] @cmd << cmd cmd end |
#add_cmds(cmds) ⇒ Array<Array<String>>
Add multiple commands.
65 66 67 |
# File 'lib/rub/r/targetgenerator.rb', line 65 def add_cmds(cmds) cmds.map{|c| add_cmd c} end |
#build_self ⇒ Object
75 76 77 78 |
# File 'lib/rub/r/targetgenerator.rb', line 75 def build_self R::run(['mkdir', '-pv', *@output.map{|o| o.dirname}], "Preparing output directories", importance: :low) @cmd.all?{|c| R::run(c, "#@action #{@output.to_a.join", "}")} or exit 1 end |
#hash_input ⇒ Object
69 70 71 72 73 |
# File 'lib/rub/r/targetgenerator.rb', line 69 def hash_input super + Digest::SHA1.digest( @cmd.join("\0") ) end |