Module: Linux::Lxc

Defined in:
lib/linux/lxc.rb,
lib/linux/lxc/file.rb,
lib/linux/lxc/line.rb,
lib/linux/lxc/index.rb,
lib/linux/lxc/lines.rb,
lib/linux/lxc/version.rb,
lib/linux/lxc/directory.rb

Defined Under Namespace

Classes: Directory, File, Index, Line, Lines

Constant Summary collapse

VERSION =
'0.1.8'

Class Method Summary collapse

Class Method Details

.directory(fname, index = Index.new) ⇒ Object



44
45
46
# File 'lib/linux/lxc.rb', line 44

def self.directory(fname, index = Index.new)
  index.get_directory(fname)
end

.file(fname, index = Index.new) ⇒ Object



39
40
41
42
# File 'lib/linux/lxc.rb', line 39

def self.file(fname, index = Index.new)
  dir = index.get_directory(::File.dirname(fname))
  dir.add_file(fname)
end

.numeric_prefix_order(data) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/linux/lxc.rb', line 10

def self.numeric_prefix_order(data)
  data.sort do |a,b|
    a_m = a.match(/^(\d+)(.*)$/)
    b_m = b.match(/^(\d+)(.*)$/)
    if a_m && b_m
      ret = a_m[1].to_i <=> b_m[1].to_i
      if ret == 0
        ret = a_m[2] <=> b_m[2]
      end
      ret
    else
      a <=> b
    end
  end
end

.parse(file, index = Index.new) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/linux/lxc.rb', line 26

def self.parse(file, index = Index.new)
  if ::File.directory?(file)
    fname = file
    entries = ::Dir.glob(::File.join(file, '*.conf')).select { |f| ::File.file?(f) }
    dir = index.get_directory(fname)
    numeric_prefix_order(entries).each do |entry|
      dir.add_file(entry).parse
    end
    return dir
  end
  return Lxc.file(file, index).parse
end