Class: Ruber::Rake::ProjectExtension

Inherits:
Qt::Object
  • Object
show all
Includes:
Extension
Defined in:
plugins/rake/rake_extension.rb

Overview

Extension which takes care of storing and rebuilding the task list contained in the rake/tasks project option when one of the rake/rake, rake/rakefile, rake/options or rake/environment changes.

Instance Attribute Summary

Attributes included from Extension

plugin

Instance Method Summary (collapse)

Methods included from Extension

#query_close, #remove_from_project, #save_settings, #shutdown

Signal Summary

Constructor Details

- (ProjectExtension) initialize(prj)

A new instance of ProjectExtension

Parameters:



39
40
41
42
43
44
45
# File 'plugins/rake/rake_extension.rb', line 39

def initialize prj
  super
  @project = prj
  @project.connect SIGNAL('option_changed(QString, QString)') do |grp, name|
    emit tasks_updated if grp == 'rake' and name == 'tasks'
  end
end

Instance Method Details

- (Hash) gather_parameters (private)

Retrieves the parameters to run rake with from the associated project.

Returns:

  • (Hash)

    a hash contains the following entries :rake: the path of the rake program to use :env: the environment to pass to rake :options: the options to pass to rake :dir: the directory to run rake from :rakefile: the path of the rakefile to use (relative to the @dir+ entry) or nil if it is not specified in prj. If prj is a DocumentProject, this entry will always contain the path of the document



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'plugins/rake/rake_extension.rb', line 132

def gather_parameters
  res = {}
  res[:rake] = @project[:rake, :rake].dup
  res[:env] = @project[:rake, :environment].dup
  res[:options] = @project[:rake, :options].dup
  sync_stdout = @project[:rake, :sync_stdout]
  res[:options] << '-E' << '$stdout.sync = true' if sync_stdout
  rakefile = @project[:rake, :rakefile, :abs] rescue @project.document.path
  rakefile = rakefile.dup if rakefile
  if rakefile
    res[:rakefile] = File.basename rakefile
    res[:dir] = File.dirname rakefile
  else res[:dir] = @project.project_directory.dup
  end
  res
end

- (nil) run_rake(task)

Runs a given task in rake

The output from rake is displayed in the associated output widget, according to the settings for the associated project.

Before running rake, all the open documents belonging to the project are saved using autosave (this means that if the associated project is a DocumentProject, only the corresponding document will be saved).

default task

Parameters:

  • task (String, nil)

    the name of the task to execute or nil to execute the

Returns:

  • (nil)

Raises:

  • RakeError if rake reports an error while executing the rakefile

  • RakefileNotFound if rake can’t find the rakefile

  • Timeout if rake -T doesn’t exit after a suitable time



81
82
83
84
85
86
87
88
89
90
# File 'plugins/rake/rake_extension.rb', line 81

def run_rake task
  params = gather_parameters
  files = @project.files
  docs= Ruber[:world].documents.documents_with_file.select{|d| files.include? d.path}
  return unless Ruber[:autosave].autosave Ruber[:rake], docs, :on_failure => :ask
  ruby, *ruby_opts = Ruber[:rake].ruby_command_for @project, params[:dir]
  params[:ruby_options] = ruby_opts
  params[:task] = task
  Ruber[:rake].run_rake ruby, params[:dir], params
end

- (Hash) tasks

The tasks defined in the rakefile associated with the project

This method uses Ruber::Rake::Plugin#tasks to retrieve the list of tasks.

values

Returns:

  • (Hash)

    a hash having the task names as keys and their descriptions as

See Also:



57
58
59
60
61
62
# File 'plugins/rake/rake_extension.rb', line 57

def tasks
  pars = gather_parameters
  ruby, *ruby_opts = Ruber[:rake].ruby_command_for @project, pars[:dir]
  pars[:ruby_options] = ruby_opts
  Ruber[:rake].tasks ruby, pars[:dir], pars
end

- (nil) update_tasks

Updates the rake/tasks project option so that the tasks match those reported by rake.

by the user

Returns:

  • (nil)

Raises:

  • (Plugin::RakefileNotFound)

    if rake reports that no rakefile has been found

  • (Plugin::Rake::Timeout)

    if rake doesn’t return the list of task in the amount of time set

  • (Plugin::Rake::RakeError)

    if rake aborts with an error



103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'plugins/rake/rake_extension.rb', line 103

def update_tasks
  new_tasks = tasks
  old_tasks = @project[:rake, :tasks]
  new_tasks.each_pair do |k, v| 
    data = [v]
    old_data = old_tasks[k]
    data << old_data[1] if old_data and old_data[1]
    new_tasks[k] = data
  end
  @project[:rake, :tasks] = new_tasks
  @project.save
  emit tasks_updated
  self
end

Signal Details

- tasks_updated