Class: Gem::Tasks::Task

Inherits:
Rake::TaskLib
  • Object
show all
Includes:
Printing
Defined in:
lib/rubygems/tasks/task.rb

Constant Summary

Constants included from Printing

Printing::ANSI_BRIGHT, Printing::ANSI_CLEAR, Printing::ANSI_GREEN, Printing::ANSI_RED, Printing::ANSI_YELLOW, Printing::DEBUG_PREFIX, Printing::ERROR_PREFIX, Printing::STATUS_PREFIX

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Printing

#debug, #error, #status

Constructor Details

#initializeTask

Initializes the task.


22
23
24
# File 'lib/rubygems/tasks/task.rb', line 22

def initialize
  @project = Project.directories[Dir.pwd]
end

Instance Attribute Details

#projectProject (readonly)

Project metadata.

Returns:


17
18
19
# File 'lib/rubygems/tasks/task.rb', line 17

def project
  @project
end

Instance Method Details

#bundle(command, *arguments) ⇒ Boolean (protected)

Runs a bundle command.

Parameters:

  • command (String)

    The bundle command to run.

  • arguments (Array<String>)

    Additional arguments for the command.

Returns:

  • (Boolean)

    Specifies whether the command was successful.


87
88
89
# File 'lib/rubygems/tasks/task.rb', line 87

def bundle(command,*arguments)
  run 'bundler', command, *arguments
end

#gem(command, *arguments) ⇒ Boolean (protected)

Runs a gem command.

Parameters:

  • command (String)

    The gem command to run.

  • arguments (Array<String>)

    Additional arguments for the command.

Returns:

  • (Boolean)

    Specifies whether the command was successful.


69
70
71
# File 'lib/rubygems/tasks/task.rb', line 69

def gem(command,*arguments)
  run 'gem', command, *arguments
end

#gemspec_tasks(prefix) ⇒ Object (protected)

Defines a task that will execute tasks for each gemspec.

Parameters:

  • prefix (Symbol, String)

    The name for the task.


147
148
149
# File 'lib/rubygems/tasks/task.rb', line 147

def gemspec_tasks(prefix)
  namespaced_tasks prefix, @project.gemspecs.keys
end

#invoke(name) ⇒ Object (protected)

Explicitly invokes a task.

Parameters:

  • name (Symbol, String)

    The name of the task.

Since:

  • 0.2.2


116
117
118
# File 'lib/rubygems/tasks/task.rb', line 116

def invoke(name)
  Rake.application[name].invoke
end

#namespaced_tasks(prefix, subtasks) ⇒ Object (protected)

Defines a task that will invoke one or all of the specifies tasks within the namespace.

Examples:

namespaced_tasks 'pkg:tar', @project.gemspecs.keys

Parameters:

  • prefix (String)

    The namespace of the sub-tasks to call.

  • subtasks (Array<Symbol>)

    The names of the sub-tasks.


135
136
137
# File 'lib/rubygems/tasks/task.rb', line 135

def namespaced_tasks(prefix,subtasks)
  task prefix => subtasks.map { |subtask| "#{prefix}:#{subtask}" }
end

#run(command, *arguments) ⇒ Boolean (protected)

Runs a command.

Parameters:

  • command (String)

    The command to run.

  • arguments (Array<String>)

    Additional arguments for the command.

Returns:

  • (Boolean)

    Specifies whether the command was successful.


42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/rubygems/tasks/task.rb', line 42

def run(command,*arguments)
  show_command = [command, *arguments].join(' ')

  debug show_command

  unless system(command,*arguments)
    error "Command failed: #{show_command}"
    abort
  end

  return true
end

#task?(name) ⇒ Boolean (protected)

Determines if a task was defined.

Parameters:

  • name (Symbol, String)

    The task name to search for.

Returns:

  • (Boolean)

    Specifies whether the task was defined.


102
103
104
# File 'lib/rubygems/tasks/task.rb', line 102

def task?(name)
  Rake::Task.task_defined?(name)
end