Class: VolumeVisualizer::ZFS::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/volume_visualizer/zfs/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, data) ⇒ Base

Returns a new instance of Base.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/volume_visualizer/zfs/base.rb', line 6

def initialize(name, data)
  @name = name || "unknown volume"
  @filesystems = {}

  data.each do |line|
    line.chomp!
    fs = ZFS::Filesystem.new(line)
    next if fs.snapshot? && fs.zero?
    if filesystems.empty?
      @root = fs
    else
      parent = filesystems[ fs.parent_name ]
      fs.parent = parent
      parent.children << fs
    end
    filesystems[fs.name] = fs
  end
end

Instance Attribute Details

#filesystemsObject (readonly)

Returns the value of attribute filesystems.



4
5
6
# File 'lib/volume_visualizer/zfs/base.rb', line 4

def filesystems
  @filesystems
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/volume_visualizer/zfs/base.rb', line 4

def name
  @name
end

#rootObject (readonly)

Returns the value of attribute root.



4
5
6
# File 'lib/volume_visualizer/zfs/base.rb', line 4

def root
  @root
end

Instance Method Details

#to_hObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/volume_visualizer/zfs/base.rb', line 32

def to_h
  {
    :name => name,
    :type => :root,
    :children => [
      {
        :name => "free space",
        :size => root.available.bytes,
        :size_human => root.available,
        :type => "free"
      },
      root.to_h
    ]
  }
end

#to_jsonObject



48
49
50
# File 'lib/volume_visualizer/zfs/base.rb', line 48

def to_json
  to_h.to_json(:max_nesting => 50)
end

#walk(nodes = [ root ], &block) ⇒ Object



25
26
27
28
29
30
# File 'lib/volume_visualizer/zfs/base.rb', line 25

def walk(nodes = [ root ], &block)
  nodes.each do |node|
    yield node
    walk node.children, &block
  end
end