Class: Ro::Root

Inherits:
String
  • Object
show all
Defined in:
lib/ro/root.rb

Instance Method Summary collapse

Constructor Details

#initialize(root) ⇒ Root

Returns a new instance of Root.



3
4
5
6
7
8
# File 'lib/ro/root.rb', line 3

def initialize(root)
  super(Ro.realpath(root.to_s))
ensure
  raise ArgumentError.new("root=#{ root.inspect }") if root.nil?
  raise ArgumentError.new("root=#{ root.inspect }") unless test(?d, self)
end

Instance Method Details

#directories(&block) ⇒ Object



22
23
24
# File 'lib/ro/root.rb', line 22

def directories(&block)
  Dir.glob(File.join(root, '*/'), &block)
end

#dotdirObject



38
39
40
# File 'lib/ro/root.rb', line 38

def dotdir
  File.join(self, '.ro')
end

#gitObject



30
31
32
# File 'lib/ro/root.rb', line 30

def git
  @git ||= Git.new(self)
end

#lock(&block) ⇒ Object



46
47
48
49
50
# File 'lib/ro/root.rb', line 46

def lock(&block)
  FileUtils.mkdir_p(File.dirname(lockpath))
  @lock ||= Lock.new(lockpath)
  block ? @lock.lock(&block) : @lock
end

#lockpathObject



42
43
44
# File 'lib/ro/root.rb', line 42

def lockpath
  File.join(dotdir, 'lock')
end

#node_directories(&block) ⇒ Object



26
27
28
# File 'lib/ro/root.rb', line 26

def node_directories(&block)
  Dir.glob(File.join(root, '*/*/'), &block)
end

#nodesObject



14
15
16
17
18
19
20
# File 'lib/ro/root.rb', line 14

def nodes
  Node::List.new(root) do |list|
    node_directories do |path|
      list.load(path)
    end
  end
end

#patch(*args, &block) ⇒ Object



34
35
36
# File 'lib/ro/root.rb', line 34

def patch(*args, &block)
  git.patch(*args, &block)
end

#rootObject



10
11
12
# File 'lib/ro/root.rb', line 10

def root
  self
end