Class: OsCtld::Assets::Base
- Inherits:
-
Object
- Object
- OsCtld::Assets::Base
show all
- Defined in:
- lib/osctld/assets/base.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
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
|
Instance Attribute Details
#errors ⇒ Object
Returns the value of attribute errors.
12
13
14
|
# File 'lib/osctld/assets/base.rb', line 12
def errors
@errors
end
|
#opts ⇒ Object
Returns the value of attribute opts.
12
13
14
|
# File 'lib/osctld/assets/base.rb', line 12
def opts
@opts
end
|
#path ⇒ Object
Returns the value of attribute path.
12
13
14
|
# File 'lib/osctld/assets/base.rb', line 12
def path
@path
end
|
Class Method Details
.register(type) ⇒ Object
3
4
5
6
|
# File 'lib/osctld/assets/base.rb', line 3
def self.register(type)
@type = type
Assets.register(type, self)
end
|
.type ⇒ Object
8
9
10
|
# File 'lib/osctld/assets/base.rb', line 8
def self.type
@type
end
|
Instance Method Details
#add_error(error) ⇒ Object
71
72
73
|
# File 'lib/osctld/assets/base.rb', line 71
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/osctld/assets/base.rb', line 77
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
|
# File 'lib/osctld/assets/base.rb', line 66
def state
fail '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?
fail 'asset not validated'
elsif !validate?
fail 'asset cannot be validated'
end
@valid
end
|
#validate(run) ⇒ Object
Implement in subclasses to validate the asset
99
100
101
|
# File 'lib/osctld/assets/base.rb', line 99
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
|