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.



93
94
95
# File 'lib/rubygems/tasks/task.rb', line 93

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
72
73
74
75
76
77
# File 'lib/rubygems/tasks/task.rb', line 69

def gem(command,*arguments)
  if defined?(Bundler)
    Bundler.with_original_env do
      run 'gem', command, *arguments
    end
  else
    run 'gem', command, *arguments
  end
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.



153
154
155
# File 'lib/rubygems/tasks/task.rb', line 153

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



122
123
124
# File 'lib/rubygems/tasks/task.rb', line 122

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.



141
142
143
# File 'lib/rubygems/tasks/task.rb', line 141

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.



108
109
110
# File 'lib/rubygems/tasks/task.rb', line 108

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