Class: Scide::Project
- Inherits:
-
Object
- Object
- Scide::Project
- Defined in:
- lib/scide/project.rb
Overview
Scide configuration for one project.
Instance Attribute Summary collapse
-
#default_window ⇒ Object
readonly
The name or index of the window that should be displayed by default for this project (defaults to the last window).
-
#key ⇒ Object
readonly
The project key in the projects configuration hash.
-
#options ⇒ Object
readonly
Project-specific options.
-
#path ⇒ Object
readonly
The path where the project is located.
-
#windows ⇒ Object
readonly
The GNU Screen windows of this project.
Instance Method Summary collapse
-
#initialize(global, key, contents) ⇒ Project
constructor
Returns a project configuration.
-
#to_screen ⇒ Object
Returns a representation of this project as a GNU Screen configuration fragment.
Constructor Details
#initialize(global, key, contents) ⇒ Project
Returns a project configuration.
If not given in the project hash, #path is built by joining the global path and key
.
Arguments
-
global
- The global configuration. -
key
- The key identifying the project. This is the key in the projects hash. -
contents
- The project hash.
Project Options
#options is built by merging the options given in the project hash with the global options.
The following default options are added if not given:
-
name
- Defaults to the project key. -
path
- The path where the project is located.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/scide/project.rb', line 41 def initialize global, key, contents raise ArgumentError, "project '#{key}' must be a hash" unless contents.kind_of? Hash raise ArgumentError, "windows of project '#{key}' must be an array" unless contents[:windows].kind_of?(Array) raise ArgumentError, "options of project '#{key}' must be a hash" unless contents[:options].nil? or contents[:options].kind_of?(Hash) @key = key # path defaults to project key @path = contents[:path].try(:to_s) || key.to_s unless path.match /^\// # if not absolute if global.path # expand from global directory @path = File.join global.path, @path else # or from home directory @path = File.join File.('~'), @path end end @options = global..dup @options[:name] = key @options[:path] = @path @options.merge!(contents[:options] || {}) @windows = contents[:windows].collect{ |w| Scide::Window.new self, w } # find default window if specified @default_window = if contents[:default_window].kind_of? Fixnum @windows[contents[:default_window]] elsif contents[:default_window].kind_of?(String) or contents[:default_window].kind_of?(Symbol) @windows.find{ |w| w.name == contents[:default_window].to_s } elsif !contents[:default_window].nil? raise ArgumentError, "default window of project '#{key}' should be an integer, string or symbol" end raise ArgumentError, "default window of project '#{key}' must be the name or index of one of its windows" if !contents[:default_window].nil? and @default_window.nil? end |
Instance Attribute Details
#default_window ⇒ Object (readonly)
The name or index of the window that should be displayed by default for this project (defaults to the last window).
20 21 22 |
# File 'lib/scide/project.rb', line 20 def default_window @default_window end |
#key ⇒ Object (readonly)
The project key in the projects configuration hash.
7 8 9 |
# File 'lib/scide/project.rb', line 7 def key @key end |
#options ⇒ Object (readonly)
Project-specific options. Can be used by commands. See #initialize.
13 14 15 |
# File 'lib/scide/project.rb', line 13 def @options end |
#path ⇒ Object (readonly)
The path where the project is located. See #initialize.
10 11 12 |
# File 'lib/scide/project.rb', line 10 def path @path end |
#windows ⇒ Object (readonly)
The GNU Screen windows of this project.
16 17 18 |
# File 'lib/scide/project.rb', line 16 def windows @windows end |
Instance Method Details
#to_screen ⇒ Object
Returns a representation of this project as a GNU Screen configuration fragment. Returns nil if this project has no configured windows.
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/scide/project.rb', line 82 def to_screen return nil if @windows.blank? String.new.tap do |s| @windows.each_with_index do |w,i| s << w.to_screen(i) s << "\n" if i != (@windows.length - 1) end s << "\nselect #{@default_window.name}" if @default_window end end |