Class: Caracara::Group

Inherits:
Object
  • Object
show all
Defined in:
lib/caracara/group.rb

Overview

Group

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tasks = [], options = {}) ⇒ Group

Initialize



9
10
11
12
# File 'lib/caracara/group.rb', line 9

def initialize(tasks = [], options = {})
  @tasks = tasks
  @options = options
end

Class Attribute Details

.tasksObject (readonly)

Tasks



65
66
67
# File 'lib/caracara/group.rb', line 65

def tasks
  @tasks
end

Instance Attribute Details

#tasksObject (readonly)

Tasks



6
7
8
# File 'lib/caracara/group.rb', line 6

def tasks
  @tasks
end

Class Method Details

.init(options = {}) ⇒ Object

Init



86
87
88
# File 'lib/caracara/group.rb', line 86

def init(options = {})
  new @tasks, options
end

.task(name, command) ⇒ Object

Set a new task to the group

Parameters:

  • name (Symbol)

    The task name

  • task (Caracara::Task/String)

    The task itself



70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/caracara/group.rb', line 70

def task(name, command)
  # Check the type of the command
  if command.is_a? String
    task = Task.new [command]
  else
    task = command.init
  end

  # Init the tasks
  @tasks = {} if @tasks.nil?

  # Set the task
  @tasks[name] = task
end

Instance Method Details

#command(name, options = {}, ssh_command = true, escape = true) ⇒ Object

Generate the SSH command



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/caracara/group.rb', line 36

def command(name, options = {}, ssh_command = true, escape = true)
  # Set options
  options = Utils.merge @options, options

  # Generate task command
  task = @tasks[name].command options, false

  # Do not return the SSH command
  return task unless ssh_command

  # Generate the full command
  SSH.command task, escape
end

#command_all(options = {}, escape = true) ⇒ Object

Generate all tasks commands



51
52
53
54
55
56
57
58
59
60
# File 'lib/caracara/group.rb', line 51

def command_all(options = {}, escape = true)
  # Each tasks
  tasks = @tasks.keys.map do |name|
    # Compile the task
    command name, options, false
  end

  # Generate the full command
  SSH.command tasks, escape
end

#compile(name, options = {}) ⇒ Object

Compile the tasks



15
16
17
18
19
20
21
22
23
24
# File 'lib/caracara/group.rb', line 15

def compile(name, options = {})
  # Set options
  options = Utils.merge @options, options

  # Get the tasks
  task = @tasks[name]

  # Compile the task
  task.compile options
end

#compile_all(options = {}) ⇒ Object

Compile all the tasks



27
28
29
30
31
32
33
# File 'lib/caracara/group.rb', line 27

def compile_all(options = {})
  # Each tasks
  @tasks.keys.map do |name|
    # Compile the task
    compile name, options
  end
end