Module: RakeCommander::RakeTask::ClassMethods

Defined in:
lib/rake-commander/rake_task.rb

Instance Method Summary collapse

Instance Method Details

#desc(str = :not_used) ⇒ String

Give a description to the task

Returns:

  • (String)

    the description of the task



26
27
28
29
# File 'lib/rake-commander/rake_task.rb', line 26

def desc(str = :not_used)
  return @desc if str == :not_used
  @desc = str.to_s
end

#install_task(&task_method) ⇒ @see Rake::Task

Note:

although it will exist, the task won't be listed with rake -T unless it has a description (desc).

Note:

this method is extended by some modules

  1. RakeCommander::Options::Result: Ensure options are parsed before calling task
  2. RakeCommander::Options::Arguments: exit(0) when Rake interprets the full ARGV rather than stopping at the delimiter (--)

Does the final rake task definition

Returns:

  • (@see Rake::Task)

    same results as if you used task :name {} or namespace :space {}



79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/rake-commander/rake_task.rb', line 79

def install_task(&task_method)
  raise "Expected task_block." unless task_method

  if namespaced?
    namespaced do
      rake.desc desc
      rake.task task, &task_method
    end
  else
    rake.desc desc
    rake.task task, &task_method
  end
end

#namespace(name = :not_used) ⇒ String

It can be hierarchical by using NAMESPACE_DELIMITER

Returns:

  • (String)

    the namespace defined for this RakeCommander class.



40
41
42
43
# File 'lib/rake-commander/rake_task.rb', line 40

def namespace(name = :not_used)
  return @namespace if name == :not_used
  @namespace = namespace_str(name)
end

#namespaced(name = namespace, &block) ⇒ Object

It builds the nested namespace rake blocks



62
63
64
65
66
67
68
69
# File 'lib/rake-commander/rake_task.rb', line 62

def namespaced(name = namespace, &block)
  spaces = namespace_split(name)
  top    = spaces.shift
  block  = spaces.reverse.reduce(block) do |blk, nm|
    namespace_block(nm, &blk)
  end
  rake.namespace top, &block
end

#namespaced?Boolean

Note:

Rake allows to namespace tasks (i.e. task :"run:this") Although supported by this integration, namespace detection is left to the core rake gem. This method will return false.

Is this rake context namespaced?

Returns:

  • (Boolean)


57
58
59
# File 'lib/rake-commander/rake_task.rb', line 57

def namespaced?
  !!namespace
end

#rakeObject

The rake context wrapper (to invoke rake commands)



20
21
22
# File 'lib/rake-commander/rake_task.rb', line 20

def rake
  @rake ||= RakeCommander::RakeContext::Wrapper.new
end

#task(name = :not_used) ⇒ Symbol

Give a name to the task

Returns:

  • (Symbol)

    the task name



33
34
35
36
# File 'lib/rake-commander/rake_task.rb', line 33

def task(name = :not_used)
  return @task if name == :not_used
  @task = name.to_sym
end

#task_fullnameString Also known as: name

It gives the task full name (including namespacing)

Returns:

  • (String)


47
48
49
# File 'lib/rake-commander/rake_task.rb', line 47

def task_fullname
  "#{namespace}:#{task}"
end