Class: OsCtl::ExportFS::Config::Exports
- Inherits:
-
Object
- Object
- OsCtl::ExportFS::Config::Exports
- Defined in:
- lib/osctl/exportfs/config/exports.rb
Instance Attribute Summary collapse
-
#db ⇒ Object
readonly
protected
Returns the value of attribute db.
Instance Method Summary collapse
- #<<(export) ⇒ Object
- #dump ⇒ Object
- #each ⇒ Object
- #find_by_as(as) ⇒ Object
- #group_by_as ⇒ Array(String, String, Array<::Export>)
-
#initialize(cfg) ⇒ Exports
constructor
A new instance of Exports.
- #lookup(as, host) ⇒ Export?
- #remove(export) ⇒ Object
Constructor Details
Instance Attribute Details
#db ⇒ Object (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
9 10 11 |
# File 'lib/osctl/exportfs/config/exports.rb', line 9 def <<(export) db << export end |
#dump ⇒ Object
58 59 60 |
# File 'lib/osctl/exportfs/config/exports.rb', line 58 def dump db.map(&:dump) end |
#each ⇒ Object
25 26 27 |
# File 'lib/osctl/exportfs/config/exports.rb', line 25 def each(&) db.each(&) end |
#find_by_as(as) ⇒ Object
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_as ⇒ 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?
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
21 22 23 |
# File 'lib/osctl/exportfs/config/exports.rb', line 21 def remove(export) db.delete(export) end |