Class: RFacter::Util::Confine Private
- Inherits:
-
Object
- Object
- RFacter::Util::Confine
- Extended by:
- Forwardable
- Includes:
- Values
- Defined in:
- lib/rfacter/util/confine.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.
A restricting tag for fact resolution mechanisms. The tag must be true for the resolution mechanism to be suitable.
Instance Attribute Summary collapse
- #fact ⇒ Object private
- #values ⇒ Object private
Instance Method Summary collapse
-
#initialize(fact = nil, *values, config: RFacter::Config.config, **options, &block) ⇒ Confine
constructor
private
Add the restriction.
- #to_s ⇒ Object private
-
#true? ⇒ Boolean
private
Evaluate the fact, returning true or false.
Methods included from Values
convert, deep_freeze, deep_merge, flatten_structure
Constructor Details
#initialize(fact = nil, *values, config: RFacter::Config.config, **options, &block) ⇒ Confine
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.
Add the restriction. Requires the fact name, an operator, and the value we’re comparing to.
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rfacter/util/confine.rb', line 31 def initialize(fact = nil, *values, config: RFacter::Config.config, **, &block) raise ArgumentError, "The fact name must be provided" unless fact or block_given? if values.empty? and not block_given? raise ArgumentError, "One or more values or a block must be provided" end @fact = fact @values = values @config = config @block = block end |
Instance Attribute Details
#fact ⇒ 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.
18 19 20 |
# File 'lib/rfacter/util/confine.rb', line 18 def fact @fact end |
#values ⇒ 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.
18 19 20 |
# File 'lib/rfacter/util/confine.rb', line 18 def values @values end |
Instance Method Details
#to_s ⇒ 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.
42 43 44 45 |
# File 'lib/rfacter/util/confine.rb', line 42 def to_s return @block.to_s if @block return "'%s' '%s'" % [@fact, @values.join(",")] end |
#true? ⇒ Boolean
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.
Evaluate the fact, returning true or false. if we have a block paramter then we only evaluate that instead
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/rfacter/util/confine.rb', line 49 def true? if @block and not @fact then begin return !! @block.call rescue StandardError => error logger.debug "Confine raised #{error.class} #{error}" return false end end unless fact = RFacter::DSL::Facter[@fact] logger.debug "No fact for %s" % @fact return false end value = convert(fact.value) return false if value.nil? if @block then begin return !! @block.call(value) rescue StandardError => error logger.debug "Confine raised #{error.class} #{error}" return false end end return @values.any? do |v| convert(v) === value end end |