Class: Filament::Workspace

Inherits:
Object
  • Object
show all
Defined in:
lib/filament/workspace.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Workspace

Returns a new instance of Workspace.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/filament/workspace.rb', line 20

def initialize(path)
  @realpath = Pathname.new(path).realpath
  # stores Pathname#realpath for all packages in this workspace
  @realpath_package_cache = {}
  
  @package_resolver = PackageResolver.new
  
  # create root_package for this workspace
  @root_package = Package.new(
    :realpath => @realpath, 
    :parent => nil,
    :workspace => self,
    :package_resolver => @package_resolver)
end

Instance Attribute Details

#package_resolverObject (readonly)

Returns the value of attribute package_resolver.



18
19
20
# File 'lib/filament/workspace.rb', line 18

def package_resolver
  @package_resolver
end

#realpathObject (readonly)

Returns the value of attribute realpath.



18
19
20
# File 'lib/filament/workspace.rb', line 18

def realpath
  @realpath
end

Class Method Details

.create(path) ⇒ Object



10
11
12
13
14
15
# File 'lib/filament/workspace.rb', line 10

def create(path)
  FileUtils.mkdir_p(path)
  FileUtils.cd path do 
    FileUtils.touch('.workspace')
  end
end

Instance Method Details

#create_package_for_path(path) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/filament/workspace.rb', line 52

def create_package_for_path(path)
  return nil if path.nil?

  FileUtils.mkdir_p(path)
  realpath_p = Pathname.new(path).realpath

  puts realpath_p
  package = package_for_realpath(realpath_p)

  package.create
  
  return package
end

#load_tasks(package = nil) ⇒ Object



70
71
72
73
74
75
76
77
78
79
# File 'lib/filament/workspace.rb', line 70

def load_tasks(package=nil)
  package ||= @root_package
  
  pn = package.pathname + 'tasks.rb'
  load pn.realpath if pn.exist?

  package.subpackages.each do |subpkg|
    load_tasks(subpkg)
  end
end

#package_for_realpath(realpath) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/filament/workspace.rb', line 35

def package_for_realpath(realpath)
  return nil if realpath.nil?
  realpath_p = Pathname.new(realpath)
  
  raise "realpath must be absolute." unless realpath_p.absolute?
  
  if @realpath_package_cache.key?(realpath_p)
    return realpath_package_cache[realpath_p]
  end
  
  relative_path_p = realpath_p.relative_path_from(@realpath)
  package = @root_package + relative_path_p
  @realpath_package_cache[realpath_p] = package
  
  return package
end

#resolve_package(uri) ⇒ Object



66
67
68
# File 'lib/filament/workspace.rb', line 66

def resolve_package(uri)
  @package_resolver.resolve_package(uri)
end