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



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

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 {}



84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/rake-commander/rake_task.rb', line 84

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.



43
44
45
46
47
# File 'lib/rake-commander/rake_task.rb', line 43

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



66
67
68
69
70
71
72
73
74
# File 'lib/rake-commander/rake_task.rb', line 66

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)


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

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 = :not_used) ⇒ Symbol

Give a name to the task

Returns:

  • (Symbol)

    the task name



35
36
37
38
39
# File 'lib/rake-commander/rake_task.rb', line 35

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)


51
52
53
# File 'lib/rake-commander/rake_task.rb', line 51

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