Class: Cult::Task

Inherits:
Object
  • Object
show all
Includes:
SingletonInstances, Transferable
Defined in:
lib/cult/task.rb

Direct Known Subclasses

BuildTask, EventTask

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SingletonInstances

included

Methods included from Transferable

#binary?, #collection_name, #contents, included, #remote_path, #role_relative_path

Constructor Details

#initialize(role, path) ⇒ Task

Returns a new instance of Task.



10
11
12
13
14
# File 'lib/cult/task.rb', line 10

def initialize(role, path)
  @role = role
  @path = path
  @name = File.basename(path)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/cult/task.rb', line 8

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



7
8
9
# File 'lib/cult/task.rb', line 7

def path
  @path
end

#roleObject (readonly)

Returns the value of attribute role.



6
7
8
# File 'lib/cult/task.rb', line 6

def role
  @role
end

Class Method Details

.all_for_role(project, role) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/cult/task.rb', line 44

def self.all_for_role(project, role)
  fail ArgumentError if block_given?

  Dir.glob(File.join(role.path, "tasks", "*")).sort.map do |path|
    spawn(role, path)
  end.compact.to_named_array
end

.collection_nameObject



17
18
19
# File 'lib/cult/task.rb', line 17

def self.collection_name
  "tasks"
end

.spawn(role, path) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/cult/task.rb', line 34

def self.spawn(role, path)
  [BuildTask, EventTask].each do |task_cls|
    if task_cls.valid_name?(File.basename(path))
      return task_cls.new(role, path)
    end
  end
  nil
end

Instance Method Details

#file_modeObject

Task files are executable by anyone: this makes re-exec’ing tasks as another user trivial.



29
30
31
# File 'lib/cult/task.rb', line 29

def file_mode
  super | 0111
end

#relative_pathObject



22
23
24
# File 'lib/cult/task.rb', line 22

def relative_path
  File.basename(path)
end