Class: P4Util::Tasks

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/p4util/tasks.rb

Overview

Creates a few tasks to allow launching init and kill commands via rake tasks, which should make it easy to script with test tasks, for example.

Example:

require 'p4util/tasks'

P4Util::Tasks.new do |p4util|
  p4util.version = 'r14.2' # Indicate p4d version to download
end

Tasks:

  • p4init

  • p4kill

  • p4reset

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(basename = :p4) {|_self| ... } ⇒ Tasks

Returns a new instance of Tasks.

Yields:

  • (_self)

Yield Parameters:

  • _self (P4Util::Tasks)

    the object that the method was called on



35
36
37
38
39
40
41
42
43
# File 'lib/p4util/tasks.rb', line 35

def initialize basename = :p4
  @basename = basename
  @version = 'r14.2'
  @p4_init_dir = 'p4init'

  yield self if block_given?

  define_tasks
end

Instance Attribute Details

#basenameObject

The task base name, defaults to ‘:p4’



27
28
29
# File 'lib/p4util/tasks.rb', line 27

def basename
  @basename
end

#p4_init_dirObject

The directory containing p4 init scripts, defaults to ‘p4init’



33
34
35
# File 'lib/p4util/tasks.rb', line 33

def p4_init_dir
  @p4_init_dir
end

#versionObject

P4 Version to use, defaults to ‘r14.2’



30
31
32
# File 'lib/p4util/tasks.rb', line 30

def version
  @version
end

Instance Method Details

#define_tasksObject

Create the tasks defined by this task library



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/p4util/tasks.rb', line 46

def define_tasks
  desc init_task_description
  task init_task_name do
    options = OpenStruct.new
    options.params = [p4_init_dir, '--version', version]
    Commands.init(options)
  end

  desc kill_task_description
  task kill_task_name do
    options = OpenStruct.new
    options.params = ['--version', version]
    Commands.kill(options)
  end

  desc reset_task_description
  task reset_task_name => kill_task_name do
    FileUtils.rmtree(Conventions.p4droot_dir)
  end

  self
end

#init_task_descriptionObject



69
70
71
# File 'lib/p4util/tasks.rb', line 69

def init_task_description
  "Initializes a p4d instance, and ensures it's downloaded and running"
end

#init_task_nameObject



73
74
75
# File 'lib/p4util/tasks.rb', line 73

def init_task_name
  "#{basename}init"
end

#kill_task_descriptionObject



77
78
79
# File 'lib/p4util/tasks.rb', line 77

def kill_task_description
  'Halt any locally running p4d instance'
end

#kill_task_nameObject



81
82
83
# File 'lib/p4util/tasks.rb', line 81

def kill_task_name
  "#{basename}kill"
end

#reset_task_descriptionObject



85
86
87
# File 'lib/p4util/tasks.rb', line 85

def reset_task_description
  'Cleans out the current p4droot working directory (after killing p4d)'
end

#reset_task_nameObject



89
90
91
# File 'lib/p4util/tasks.rb', line 89

def reset_task_name
  "#{basename}reset"
end