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, #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.



359
360
361
362
363
364
365
366
# File 'lib/ruber/project.rb', line 359

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[:projects], back, name
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.



393
394
395
396
# File 'lib/ruber/project.rb', line 393

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.



372
373
374
375
376
377
# File 'lib/ruber/project.rb', line 372

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

#filesObject

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

Note: this method uses the project_files extension



404
405
406
# File 'lib/ruber/project.rb', line 404

def files
  @project_extensions[:project_files].project_files
end

#scopeObject

Reimplementation of AbstractProject#scope which returns :global



382
383
384
# File 'lib/ruber/project.rb', line 382

def scope
  :global
end