Class: OsCtl::ExportFS::Config::Exports

Inherits:
Object
  • Object
show all
Defined in:
lib/osctl/exportfs/config/exports.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cfg) ⇒ Exports

Returns a new instance of Exports.

Parameters:

  • cfg (Array)


4
5
6
# File 'lib/osctl/exportfs/config/exports.rb', line 4

def initialize(cfg)
  @db = cfg.map { |v| Export.load(v) }
end

Instance Attribute Details

#dbObject (readonly, protected)

Returns the value of attribute db.



64
65
66
# File 'lib/osctl/exportfs/config/exports.rb', line 64

def db
  @db
end

Instance Method Details

#<<(export) ⇒ Object

Parameters:



9
10
11
# File 'lib/osctl/exportfs/config/exports.rb', line 9

def <<(export)
  db << export
end

#dumpObject



58
59
60
# File 'lib/osctl/exportfs/config/exports.rb', line 58

def dump
  db.map(&:dump)
end

#eachObject



25
26
27
# File 'lib/osctl/exportfs/config/exports.rb', line 25

def each(&)
  db.each(&)
end

#find_by_as(as) ⇒ Object

Parameters:

  • as (String)


30
31
32
33
# File 'lib/osctl/exportfs/config/exports.rb', line 30

def find_by_as(as)
  as_abs = File.absolute_path(as)
  db.detect { |ex| File.absolute_path(ex.as) == as_abs }
end

#group_by_asArray(String, String, Array<::Export>)

Returns:

  • (Array(String, String, Array<::Export>))


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/osctl/exportfs/config/exports.rb', line 36

def group_by_as
  ret = {}

  db.each do |ex|
    ret[ex.as] ||= []
    ret[ex.as] << ex
  end

  ret.map do |as, exports|
    first_ex = exports.first

    exports.each do |ex|
      if ex.dir != first_ex.dir
        raise "target export path #{as} has two source paths: #{ex.dir} " \
              "and #{first_ex.dir}"
      end
    end

    [first_ex.dir, as, exports]
  end
end

#lookup(as, host) ⇒ Export?

Parameters:

  • as (String)
  • host (String)

Returns:



16
17
18
# File 'lib/osctl/exportfs/config/exports.rb', line 16

def lookup(as, host)
  db.detect { |ex| return ex if ex.as == as && ex.host == host }
end

#remove(export) ⇒ Object

Parameters:



21
22
23
# File 'lib/osctl/exportfs/config/exports.rb', line 21

def remove(export)
  db.delete(export)
end