Class: OsCtld::Assets::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/osctld/assets/validator.rb

Defined Under Namespace

Classes: Run

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(assets = []) ⇒ Validator

Returns a new instance of Validator.

Parameters:

  • assets (Array<Asset::Base>) (defaults to: [])


11
12
13
# File 'lib/osctld/assets/validator.rb', line 11

def initialize(assets = [])
  @assets = assets.clone
end

Instance Attribute Details

#assetsArray<Asset::Base> (readonly)

Returns:

  • (Array<Asset::Base>)


8
9
10
# File 'lib/osctld/assets/validator.rb', line 8

def assets
  @assets
end

Instance Method Details

#add_asset(asset) ⇒ Object

Parameters:

  • asset (Asset::Base)


16
17
18
# File 'lib/osctld/assets/validator.rb', line 16

def add_asset(asset)
  assets << asset
end

#add_assets(new_assets) ⇒ Object

Parameters:

  • new_assets (Array<Asset::Base>)


21
22
23
# File 'lib/osctld/assets/validator.rb', line 21

def add_assets(new_assets)
  assets.concat(new_assets)
end

#validateArray<Asset::Base>

Validate and return assets

Returns:

  • (Array<Asset::Base>)


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/osctld/assets/validator.rb', line 27

def validate
  dataset_hash = {}
  property_hash = {}

  assets.each do |asset|
    datasets, properties = asset.prefetch_zfs

    datasets.each do |ds|
      dataset_hash[ds] = true
    end

    properties.each do |p|
      property_hash[p] = true
    end
  end

  propreader = OsCtl::Lib::Zfs::PropertyReader.new
  tree = propreader.read(
    dataset_hash.keys,
    property_hash.keys,
    recursive: false,
    ignore_error: true
  )

  run = Run.new(tree)

  assets.each do |asset|
    asset.send(:run_validation, run)
  end

  assets
end