Class: OsCtld::Assets::Base
- Inherits:
-
Object
- Object
- OsCtld::Assets::Base
- Defined in:
- lib/osctld/assets/base.rb
Direct Known Subclasses
Class Attribute Summary collapse
-
.type ⇒ Object
readonly
Returns the value of attribute type.
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #add_error(error) ⇒ Object
-
#initialize(path, opts, &block) ⇒ Base
constructor
A new instance of Base.
-
#prefetch_zfs ⇒ Array< Array<String>, Array<String> >
Return a list of datasets and a list properties needed for validation.
- #run_validation(run) ⇒ Object protected
- #state ⇒ :valid, ...
- #type ⇒ Object
- #valid? ⇒ Boolean
-
#validate(run) ⇒ Object
protected
Implement in subclasses to validate the asset.
- #validate? ⇒ Boolean
- #validate_block(&block) ⇒ Object
Constructor Details
#initialize(path, opts, &block) ⇒ Base
Returns a new instance of Base.
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/osctld/assets/base.rb', line 18 def initialize(path, opts, &block) @path = path @opts = opts @block_validators = [] @errors = [] @valid = nil @state = nil block.call(self) if block end |
Class Attribute Details
.type ⇒ Object (readonly)
Returns the value of attribute type.
9 10 11 |
# File 'lib/osctld/assets/base.rb', line 9 def type @type end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
12 13 14 |
# File 'lib/osctld/assets/base.rb', line 12 def errors @errors end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
12 13 14 |
# File 'lib/osctld/assets/base.rb', line 12 def opts @opts end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
12 13 14 |
# File 'lib/osctld/assets/base.rb', line 12 def path @path end |
Class Method Details
Instance Method Details
#add_error(error) ⇒ Object
72 73 74 |
# File 'lib/osctld/assets/base.rb', line 72 def add_error(error) @errors << error end |
#prefetch_zfs ⇒ Array< Array<String>, Array<String> >
Return a list of datasets and a list properties needed for validation
35 36 37 |
# File 'lib/osctld/assets/base.rb', line 35 def prefetch_zfs [[], []] end |
#run_validation(run) ⇒ Object (protected)
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/osctld/assets/base.rb', line 79 def run_validation(run) @valid = nil @state = nil @errors = [] unless validate? @state = :unknown return end validate(run) @block_validators.each do |block_validator| block_validator.call(self, run) end @valid = errors.empty? @state = @valid ? :valid : :invalid end |
#state ⇒ :valid, ...
66 67 68 69 70 |
# File 'lib/osctld/assets/base.rb', line 66 def state raise 'asset not validated' if @state.nil? @state end |
#type ⇒ Object
29 30 31 |
# File 'lib/osctld/assets/base.rb', line 29 def type self.class.type end |
#valid? ⇒ Boolean
55 56 57 58 59 60 61 62 63 |
# File 'lib/osctld/assets/base.rb', line 55 def valid? if @valid.nil? raise 'asset not validated' elsif !validate? raise 'asset cannot be validated' end @valid end |
#validate(run) ⇒ Object (protected)
Implement in subclasses to validate the asset
101 |
# File 'lib/osctld/assets/base.rb', line 101 def validate(run); end |
#validate? ⇒ Boolean
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/osctld/assets/base.rb', line 39 def validate? if @opts.has_key?(:validate_if) if @opts[:validate_if].is_a?(Proc) @opts[:validate_if].call else @opts[:validate_if] end else true end end |
#validate_block(&block) ⇒ Object
51 52 53 |
# File 'lib/osctld/assets/base.rb', line 51 def validate_block(&block) @block_validators << block end |