Class: Inspec::Resources::ZfsDataset
- Inherits:
-
Object
- Object
- Inspec::Resources::ZfsDataset
- Defined in:
- lib/inspec/resources/zfs_dataset.rb
Instance Method Summary collapse
-
#exec ⇒ Object
override method.
-
#exists? ⇒ Boolean
method called by ‘it { should exist }’.
- #gather ⇒ Object
-
#initialize(zfs_dataset) ⇒ ZfsDataset
constructor
A new instance of ZfsDataset.
-
#method_missing(name) ⇒ Object
expose all parameters.
- #mounted? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(zfs_dataset) ⇒ ZfsDataset
Returns a new instance of ZfsDataset.
18 19 20 21 22 23 24 |
# File 'lib/inspec/resources/zfs_dataset.rb', line 18 def initialize(zfs_dataset) return skip_resource "The `zfs_dataset` resource is not supported on your OS yet." unless inspec.os.bsd? @zfs_dataset = zfs_dataset @params = gather end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name) ⇒ Object
expose all parameters
58 59 60 |
# File 'lib/inspec/resources/zfs_dataset.rb', line 58 def method_missing(name) @params[name.to_s] end |
Instance Method Details
#exec ⇒ Object
override method
53 54 55 |
# File 'lib/inspec/resources/zfs_dataset.rb', line 53 def exec @params["exec"] end |
#exists? ⇒ Boolean
method called by ‘it { should exist }’
27 28 29 |
# File 'lib/inspec/resources/zfs_dataset.rb', line 27 def exists? inspec.command("/sbin/zfs get -Hp all #{@zfs_dataset}").exit_status == 0 end |
#gather ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/inspec/resources/zfs_dataset.rb', line 41 def gather cmd = inspec.command("/sbin/zfs get -Hp all #{@zfs_dataset}") return nil if cmd.exit_status.to_i != 0 # parse data cmd.stdout.chomp.split("\n").each_with_object(Hash.new(0)) do |line, h| t = line.split("\t") h[t[1].to_s] = t[2].to_s end end |
#mounted? ⇒ Boolean
31 32 33 34 35 |
# File 'lib/inspec/resources/zfs_dataset.rb', line 31 def mounted? return false unless exists? inspec.mount(@params["mountpoint"]).mounted? end |
#to_s ⇒ Object
37 38 39 |
# File 'lib/inspec/resources/zfs_dataset.rb', line 37 def to_s "ZFS Dataset #{@zfs_dataset}" end |