Module: RakeCommander::RakeTask::ClassMethods

Includes:
Base::ClassHelpers
Defined in:
lib/rake-commander/rake_task.rb

Constant Summary

Constants included from Base::ClassHelpers

Base::ClassHelpers::NOT_USED

Instance Method Summary collapse

Methods included from Base::ClassHelpers

#class_resolver, #descendants, #descendants?, #inheritable_attrs, #inheritable_class_vars, #inherited, #instance_variable_name, #new_class, #redef_without_warning, #resolve_class, #to_constant, #used_param?

Instance Method Details

#desc(str = nil) ⇒ String

Give a description to the task

Returns:

  • (String)

    the description of the task



54
55
56
57
# File 'lib/rake-commander/rake_task.rb', line 54

def desc(str = nil)
  return @desc if str.nil?
  @desc = str.to_s
end

#install_task(&task_method) ⇒ Object

Does the final rake task definition



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/rake-commander/rake_task.rb', line 26

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

  # ensure options are parsed before calling task

  # and that ARGV is only parsed after `--`

  # do an `exit(0)` right at the end

  task_method = task_context(&task_method) if options?

  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 = nil) ⇒ String

It can be hierarchical by using NAMESPACE_DELIMITER

Returns:

  • (String)

    the namespace defined for this RakeCommander class.



61
62
63
64
# File 'lib/rake-commander/rake_task.rb', line 61

def namespace(name = nil)
  return @namespace if name.nil?
  @namespace = namespace_str(name)
end

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

It builds the nested namespace rake blocks



76
77
78
79
80
81
82
83
# File 'lib/rake-commander/rake_task.rb', line 76

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)


71
72
73
# File 'lib/rake-commander/rake_task.rb', line 71

def namespaced?
  !!namespace
end

#rakeObject

The rake context wrapper (to invoke rake commands)



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

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

#task(name = nil) ⇒ Symbol

Give a name to the task

Returns:

  • (Symbol)

    the task name



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

def task(name = nil)
  return @task if name.nil?
  @task = name.to_sym
end