Class: Caracara::Task
- Inherits:
-
Object
- Object
- Caracara::Task
- Defined in:
- lib/caracara/task.rb
Overview
Task class
Class Attribute Summary collapse
-
.fixed_options ⇒ Object
readonly
Static attributes.
-
.steps ⇒ Object
readonly
Static attributes.
Class Method Summary collapse
-
.dir(name, &blk) ⇒ Object
Run steps inside a dir.
-
.init(args = {}) ⇒ Object
Initialize a task.
-
.step(cmd, fixed_options = {}) ⇒ Object
Add a step.
Instance Method Summary collapse
-
#command(args = {}, escape = true) ⇒ Object
Generate the SSH command.
-
#compile(args = {}) ⇒ Object
Compile the tasks.
-
#initialize(steps, fixed_options = {}, args = {}) ⇒ Task
constructor
Initialize.
-
#steps ⇒ Object
Steps.
Constructor Details
#initialize(steps, fixed_options = {}, args = {}) ⇒ Task
Initialize
12 13 14 15 16 |
# File 'lib/caracara/task.rb', line 12 def initialize(steps, = {}, args = {}) @steps = steps @fixed_options = @options = args end |
Class Attribute Details
.fixed_options ⇒ Object (readonly)
Static attributes
76 77 78 |
# File 'lib/caracara/task.rb', line 76 def @fixed_options end |
.steps ⇒ Object (readonly)
Static attributes
76 77 78 |
# File 'lib/caracara/task.rb', line 76 def steps @steps end |
Class Method Details
.dir(name, &blk) ⇒ Object
Run steps inside a dir
79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/caracara/task.rb', line 79 def dir(name, &blk) # Store the current steps and set a blank steps old, @steps = @steps, nil # Generate the block steps result = yield # Restore the old steps @steps = old # Put dir commands in the steps step "(cd #{name} && (#{result.join('\n')}))" end |
.init(args = {}) ⇒ Object
Initialize a task
127 128 129 130 |
# File 'lib/caracara/task.rb', line 127 def init(args = {}) # Create a new instance new @steps, @fixed_options, args end |
.step(cmd, fixed_options = {}) ⇒ Object
Add a step
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/caracara/task.rb', line 94 def step(cmd, = {}) # Define the step @steps = [] if @steps.nil? # Define the step @fixed_options = {} if @fixed_options.nil? # Add a new step if cmd.is_a?(String) # Push step and get the index index = @steps.push(cmd).length - 1 # Add fixed options @fixed_options[index] = # Default return return @steps end # If it is another task cmd.steps.each do |task_cmd| # Push and get the index index = @steps.push(task_cmd).length - 1 # Add fixed options @fixed_options[index] = end # Default return @steps end |
Instance Method Details
#command(args = {}, escape = true) ⇒ Object
Generate the SSH command
39 40 41 |
# File 'lib/caracara/task.rb', line 39 def command(args = {}, escape = true) SSH.command compile(args), escape end |
#compile(args = {}) ⇒ Object
Compile the tasks
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/caracara/task.rb', line 24 def compile(args = {}) # Merge args with defult options = Utils.merge @options, args # Each the steps @steps.map.with_index do |step, index| # Append with the fixed options = Utils.merge(, @fixed_options[index]) unless @fixed_options[index].nil? # Compile the mustache template Mustache.render step, (, ) end end |
#steps ⇒ Object
Steps
19 20 21 |
# File 'lib/caracara/task.rb', line 19 def steps @steps end |