Class: RFacter::Util::NonNullable Private
- Inherits:
-
Concurrent::ThreadLocalVar
- Object
- Concurrent::ThreadLocalVar
- RFacter::Util::NonNullable
- Defined in:
- lib/rfacter/util/non_nullable.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Non-nullable thread local variable
A Subclass of Concurrent::ThreadLocalVar that raises a NameError if de-referenced to ‘nil`. This allows the creation of variables that must always be bound to a specific value before use.
Instance Method Summary collapse
- #bind(value, &block) ⇒ Object private
-
#initialize(default = nil, err_message:, &default_block) ⇒ NonNullable
constructor
private
A new instance of NonNullable.
- #value ⇒ Object private
Constructor Details
#initialize(default = nil, err_message:, &default_block) ⇒ NonNullable
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of NonNullable.
16 17 18 19 |
# File 'lib/rfacter/util/non_nullable.rb', line 16 def initialize(default = nil, err_message:, &default_block) @err_message = super(default, &default_block) end |
Instance Method Details
#bind(value, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rfacter/util/non_nullable.rb', line 27 def bind(value, &block) if block_given? old_value = nillable_value begin self.value = value yield ensure self.value = old_value end end end |
#value ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
40 41 42 43 44 45 46 |
# File 'lib/rfacter/util/non_nullable.rb', line 40 def value result = super raise(NameError, @err_message) if result.nil? result end |