Class: Ruber::Project

Inherits:
AbstractProject show all
Includes:
Activable
Defined in:
lib/ruber/project.rb

Overview

Class representing a global project (one which should be managed by ProjectList).

It uses ProjectBackend as backend and includes the Activable module.

Signals

activated()

Signal emitted when the project is activated

deactivated()

Signal emitted when the project is deactivated

Slots

  • activate()

  • deactivate()

Defined Under Namespace

Classes: InvalidProjectFileName

Instance Attribute Summary

Attributes inherited from AbstractProject

#project_file, #project_name

Instance Method Summary collapse

Methods included from Activable

#activate, #active=, #active?, #deactivate

Methods inherited from AbstractProject

#[]=, #add_extension, #each_extension, #extension, #extensions, #finalize, #has_extension?, #match_rule?, #method_missing, #project_directory, #query_close, #remove_extension, #save, #write

Methods included from SettingsContainer

#[], #[]=, #add_setting, #add_widget, #default, #dialog, #has_setting?, #relative_path?, #remove_setting, #remove_widget, #write

Constructor Details

#initialize(file, name = nil) ⇒ Project

Creates a new Project. file is the name of the project file, while name is the project name. You must specify both arguments if the file file doesn’t exist, while you must not pass the name parameter if the file file already exists (in this case, the project name is written in the project file and there’s no need to specify it). Note that this method takes care of creating the backend, so you don’t need to do that yourself (unlike with AbstractProject).

If file is a relative path, it’s considered relative to the current directory.

If the project file file already exists but it’s not a valid project file, AbstractProject::InvalidProjectFile will be raised.

Parameters:

  • file (String)

    the path of the project file (it doesn’t need to exist)

  • name (String, nil) (defaults to: nil)

    the name of the project. If the project file already exists, then this should be nil. If the project file doesn’t exist, this should not be nil



390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
# File 'lib/ruber/project.rb', line 390

def initialize file, name = nil
  file = File.join(Dir.pwd, file) unless file.start_with? '/'
  back = begin ProjectBackend.new file
  rescue YamlSettingsBackend::InvalidSettingsFile => e
    raise Ruber::AbstractProject::InvalidProjectFile, e.message
  end
  super Ruber[:world], back, name
  finalize
  @dir_scanner = ProjectDirScanner.new self
  @dir_scanner.connect(SIGNAL('file_added(QString)')) do |f|
    @files << f if @files
  end
  @dir_scanner.connect(SIGNAL('file_removed(QString)')) do |f|
    @files.delete f if @files
  end
  @dir_scanner.connect(SIGNAL(:rules_changed)){@files = nil}
  @files = nil
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Ruber::AbstractProject

Instance Method Details

#add_option(opt) ⇒ Object

Override of SettingsContainer#add_option which sets the type of opt to :global if opt.type returns nil.

This is necessary because AbstractProject.new adds the :project_name option without specifying its type.



434
435
436
437
# File 'lib/ruber/project.rb', line 434

def add_option opt
  opt.type ||= :global
  super
end

#close(save = true) ⇒ Object

Override of AbstractProject#close which deactivates the project before closing it and disposes of it after closing. Aside from this, it works as the base class version.



413
414
415
416
417
418
# File 'lib/ruber/project.rb', line 413

def close save = true
  deactivate
  res = super
  dispose
  res
end

#file_in_project?(file) ⇒ Boolean

Returns:

  • (Boolean)


451
452
453
# File 'lib/ruber/project.rb', line 451

def file_in_project? file
  @dir_scanner.file_in_project? file
end

#filesObject Also known as: project_files

Override of AbstractProject#files which actually returns the list of files belonging to the project.

Note: this method uses the project_files extension



445
446
447
448
# File 'lib/ruber/project.rb', line 445

def files
  @files ||= @dir_scanner.project_files
  ProjectFiles.new project_directory, @files
end

#scopeObject

Reimplementation of AbstractProject#scope which returns :global



423
424
425
# File 'lib/ruber/project.rb', line 423

def scope
  :global
end