Class: Woro::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/woro/task.rb

Overview

Task object, helps in the creation and management of gists.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(task_name) ⇒ Task

Returns a new instance of Task.



9
10
11
# File 'lib/woro/task.rb', line 9

def initialize(task_name)
  @task_name = Woro::Task.sanitize_task_name task_name
end

Instance Attribute Details

#gistObject (readonly)

Returns the value of attribute gist.



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

def gist
  @gist
end

#task_nameObject (readonly)

Returns the value of attribute task_name.



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

def task_name
  @task_name
end

Class Method Details

.create(task_name) ⇒ Task

Create new Task, creates vanilla task file in the woro task directory. throughout the further processing

Parameters:

  • task_name (String)

    sanitized name of the task, used

Returns:

  • (Task)

    the created task



18
19
20
21
22
# File 'lib/woro/task.rb', line 18

def self.create(task_name)
  task = Woro::Task.new(task_name)
  task.create_from_task_template
  task
end

.sanitize_task_name(task_name) ⇒ Object



24
25
26
# File 'lib/woro/task.rb', line 24

def self.sanitize_task_name(task_name)
  task_name.strip.split(' ').first # not nice
end

Instance Method Details

#build_task_templateString

Read template and inject new name

Returns:

  • (String)

    source code for new task



48
49
50
51
# File 'lib/woro/task.rb', line 48

def build_task_template
  b = binding
  ERB.new(Woro::TaskHelper.read_template_file).result(b)
end

#create_from_task_templateObject

Creates a new rake task file at the file path (see #file_path).



54
55
56
57
58
# File 'lib/woro/task.rb', line 54

def create_from_task_template
  File.open(file_path, 'w') do |f|
    f.puts build_task_template
  end
end

#exists?boolean

Returns true, if a task of this name exists locally

Returns:

  • (boolean)

    task file exists locally



42
43
44
# File 'lib/woro/task.rb', line 42

def exists?
  File.exist? file_path
end

#file_nameString

File name based on the task’s name.

Returns:

  • (String)

    taskname with extension



30
31
32
# File 'lib/woro/task.rb', line 30

def file_name
  "#{task_name}.rake"
end

#file_pathString

File name based on the task’s filename (see #file_name).

Returns:

  • (String)

    taskname with extension and relative path



36
37
38
# File 'lib/woro/task.rb', line 36

def file_path
  File.join 'lib', 'woro_tasks', file_name
end

#read_task_fileString

Read the content of the local rake task file on #file_path.

Returns:

  • (String)

    file content



62
63
64
# File 'lib/woro/task.rb', line 62

def read_task_file
  File.read(file_path)
end