Class: Woro::Task
- Inherits:
-
Object
- Object
- Woro::Task
- Defined in:
- lib/woro/task.rb
Overview
Task object, helps in the creation and management of gists.
Instance Attribute Summary collapse
-
#gist ⇒ Object
readonly
Returns the value of attribute gist.
-
#task_name ⇒ Object
readonly
Returns the value of attribute task_name.
Class Method Summary collapse
-
.create(task_name) ⇒ Task
Create new Task, creates vanilla task file in the woro task directory.
- .sanitize_task_name(task_name) ⇒ Object
Instance Method Summary collapse
-
#build_task_template ⇒ String
Read template and inject new name.
-
#create_from_task_template ⇒ Object
Creates a new rake task file at the file path (see #file_path).
-
#exists? ⇒ boolean
Returns true, if a task of this name exists locally.
-
#file_name ⇒ String
File name based on the task’s name.
-
#file_path ⇒ String
File name based on the task’s filename (see #file_name).
-
#initialize(task_name) ⇒ Task
constructor
A new instance of Task.
-
#read_task_file ⇒ String
Read the content of the local rake task file on #file_path.
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
#gist ⇒ Object (readonly)
Returns the value of attribute gist.
7 8 9 |
# File 'lib/woro/task.rb', line 7 def gist @gist end |
#task_name ⇒ Object (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
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_template ⇒ String
Read template and inject new name
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_template ⇒ Object
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
42 43 44 |
# File 'lib/woro/task.rb', line 42 def exists? File.exist? file_path end |
#file_name ⇒ String
File name based on the task’s name.
30 31 32 |
# File 'lib/woro/task.rb', line 30 def file_name "#{task_name}.rake" end |
#file_path ⇒ String
File name based on the task’s filename (see #file_name).
36 37 38 |
# File 'lib/woro/task.rb', line 36 def file_path File.join 'lib', 'woro_tasks', file_name end |
#read_task_file ⇒ String
Read the content of the local rake task file on #file_path.
62 63 64 |
# File 'lib/woro/task.rb', line 62 def read_task_file File.read(file_path) end |