Class: KXI::Application::Workspace
- Inherits:
-
Object
- Object
- KXI::Application::Workspace
- Defined in:
- lib/kxi/application/workspace.rb
Overview
Represents a workspace (directory)
Instance Method Summary collapse
-
#dirs(ptt = nil, rec = true) ⇒ Array<String>
Preforms lookup of directories (glob).
-
#files(ptt = nil, rec = true) ⇒ Array<String>
Preforms lookup of files (glob).
-
#initialize(path, mk = false) ⇒ Workspace
constructor
Instantiates the Workspace class.
-
#inner(*path) ⇒ KXI::Application::Workspace
Gets a child workspace.
-
#made? ⇒ Bool
Checks if workspace physically exists in the file system.
-
#make ⇒ Object
Creates the workspace, if it doesn’t exist.
-
#open(mode, *path) ⇒ Object
Opens a file withing the workspace.
-
#parent ⇒ KXI::Application::Workspace?
Obtains the parent of this workspace, if it exists.
-
#path(*path) ⇒ String
Gets path relative to this workspace.
Constructor Details
#initialize(path, mk = false) ⇒ Workspace
Instantiates the KXI::Application::Workspace class
10 11 12 13 14 |
# File 'lib/kxi/application/workspace.rb', line 10 def initialize(path, mk = false) @path = File.(path) validate make if mk end |
Instance Method Details
#dirs(ptt = nil, rec = true) ⇒ Array<String>
Preforms lookup of directories (glob)
90 91 92 93 94 |
# File 'lib/kxi/application/workspace.rb', line 90 def dirs(ptt = nil, rec = true) ptt = '*' if ptt == nil ptt = File.join('**', ptt) if rec return Dir.glob(path(ptt), File::FNM_DOTMATCH).select { |i| File.exists?(i) and File.directory?(i) }.collect { |i| File.(i) } end |
#files(ptt = nil, rec = true) ⇒ Array<String>
Preforms lookup of files (glob)
80 81 82 83 84 |
# File 'lib/kxi/application/workspace.rb', line 80 def files(ptt = nil, rec = true) ptt = '*' if ptt == nil ptt = File.join('**', ptt) if rec return Dir.glob(path(ptt), File::FNM_DOTMATCH).select { |i| File.exists?(i) and not File.directory?(i) }.collect { |i| File.(i) } end |
#inner(*path) ⇒ KXI::Application::Workspace
Gets a child workspace
51 52 53 |
# File 'lib/kxi/application/workspace.rb', line 51 def inner(*path) return KXI::Application::Workspace.new(path(*path)) end |
#made? ⇒ Bool
Checks if workspace physically exists in the file system
34 35 36 37 |
# File 'lib/kxi/application/workspace.rb', line 34 def made? validate return Dir.exists?(@path) end |
#make ⇒ Object
Creates the workspace, if it doesn’t exist
40 41 42 43 44 45 46 |
# File 'lib/kxi/application/workspace.rb', line 40 def make validate return if made? p = parent p.make unless parent == nil Dir.mkdir(@path) end |
#open(mode, *path) ⇒ IO #open(mode, *path) {|handle| ... } ⇒ Object
Opens a file withing the workspace
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/kxi/application/workspace.rb', line 65 def open(mode, *path) h = File.open(path(*path), mode) return h unless block_given? begin yield(h) ensure h.flush h.close end end |
#parent ⇒ KXI::Application::Workspace?
Obtains the parent of this workspace, if it exists
26 27 28 29 30 |
# File 'lib/kxi/application/workspace.rb', line 26 def parent dir = File.dirname(@path) return nil if KXI::Platform.this.path_case_sensitive? ? dir == @path : dir.downcase == @path.downcase return KXI::Application::Workspace.new(dir) end |
#path(*path) ⇒ String
Gets path relative to this workspace
19 20 21 22 |
# File 'lib/kxi/application/workspace.rb', line 19 def path(*path) return @path if path.length == 0 return File.(File.join(@path, *path)) end |