Class: Woro::TaskHelper

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

Class Method Summary collapse

Class Method Details

.extract_description(task_content) ⇒ Object

Extract description from gist’s data content string.

String

description string

Parameters:

  • data (Hash)

    gist data hash



26
27
28
29
30
# File 'lib/woro/task_helper.rb', line 26

def extract_description(task_content)
  # regex from http://stackoverflow.com/questions/171480/regex-grabbing-values-between-quotation-marks
  match = task_content.match(/desc (["'])((?:(?!\1)[^\\]|(?:\\\\)*\\[^\\])*)\1/)
  match && match[2] || 'No description'
end


4
5
6
7
8
9
# File 'lib/woro/task_helper.rb', line 4

def print_task_list(tasks)
  width ||= tasks.map { |t| t.name_with_args.length }.max || 10
  tasks.each do |t|
    puts "  %-#{width}s   # %s" % [ t.name_with_args, t.comment ]
  end
end

.read_template_fileString

Read the rake task template

Returns:

  • (String)


34
35
36
# File 'lib/woro/task_helper.rb', line 34

def read_template_file
  File.read(File.join(File.dirname(__FILE__), 'templates','task.rake.erb') )
end

.woro_task_files(directory) ⇒ Object

Perform an action over all files within the woro task directory



12
13
14
15
16
17
18
19
20
21
# File 'lib/woro/task_helper.rb', line 12

def woro_task_files(directory)
  tasks = []
  Dir.foreach(directory) do |file_name|
    if file_name.include? '.rake'
      data = File.read(File.join(directory, file_name))
      tasks << yield(file_name, data)
    end
  end
  tasks
end