Class: DotMe::Incubator

Inherits:
Object
  • Object
show all
Defined in:
lib/dotme/incubator.rb

Direct Known Subclasses

File, Folder

Constant Summary collapse

@@incubators =
[]
@@cells =
[]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Incubator

Returns a new instance of Incubator.



9
10
11
12
13
14
15
16
# File 'lib/dotme/incubator.rb', line 9

def initialize(path)
  @path     = path
  @relative = @path.gsub( Etc.getpwuid.dir, '~' )
  @basename = ::File.basename @path
  unless @basename[0] != '.'
    @basename = @basename[1..-1]
  end
end

Class Method Details

.cellsObject



39
40
41
# File 'lib/dotme/incubator.rb', line 39

def self.cells
  @@cells
end

.incubate(path, to) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/dotme/incubator.rb', line 23

def self.incubate(path,to)
  path = ::File.join( Etc.getpwuid.dir, path ) unless ::File.exists? path

  Dir.mkdir to, 0700 unless ::File.directory? to

  puts "Incubating #{::File.basename path} to #{to}"
  incubator = nil
  # get the last valid incubator
  @@incubators.each { |c| if c.incubates? path then incubator = c end }
  unless incubator 
    raise NoIncubator 
  end 

  @@cells << incubator.new(path).incubate(to)
end

.register!(c) ⇒ Object

Raises:

  • (TypeError)


18
19
20
21
# File 'lib/dotme/incubator.rb', line 18

def self.register!(c)
  raise TypeError, 'Not an Incubator derived class.' unless c.respond_to? :incubates?
  @@incubators << c
end