Class: Puppet::Confine::Variable
- Inherits:
-
Puppet::Confine
- Object
- Puppet::Confine
- Puppet::Confine::Variable
- Defined in:
- lib/puppet/confine/variable.rb
Overview
Require a specific value for a variable, either a Puppet setting or a Facter value. This class is a bit weird because the name is set explicitly by the ConfineCollection class β from this class, itβs not obvious how the name would ever get set.
Constant Summary
Constants included from Util
Util::AbsolutePathPosix, Util::AbsolutePathWindows, Util::DEFAULT_POSIX_MODE, Util::DEFAULT_WINDOWS_MODE, Util::RFC_3986_URI_REGEX
Constants included from Util::POSIX
Util::POSIX::LOCALE_ENV_VARS, Util::POSIX::USER_ENV_VARS
Constants included from Util::SymbolicFileMode
Util::SymbolicFileMode::SetGIDBit, Util::SymbolicFileMode::SetUIDBit, Util::SymbolicFileMode::StickyBit, Util::SymbolicFileMode::SymbolicMode, Util::SymbolicFileMode::SymbolicSpecialToBit
Instance Attribute Summary collapse
-
#name ⇒ Object
This is set by ConfineCollection.
Attributes inherited from Puppet::Confine
Class Method Summary collapse
-
.summarize(confines) ⇒ Object
Provide a hash summary of failing confines β the key of the hash is the name of the confine, and the value is the missing yet required values.
Instance Method Summary collapse
-
#facter_value ⇒ Object
Retrieve the value from facter.
-
#initialize(values) ⇒ Variable
constructor
A new instance of Variable.
- #message(value) ⇒ Object
-
#pass?(value) ⇒ Boolean
Compare the passed-in value to the retrieved value.
- #reset ⇒ Object
- #valid? ⇒ Boolean
Methods inherited from Puppet::Confine
#for_binary?, inherited, #result, test
Methods included from Util
absolute_path?, benchmark, chuser, clear_environment, default_env, deterministic_rand, deterministic_rand_int, exit_on_fail, get_env, get_environment, logmethods, merge_environment, path_to_uri, pretty_backtrace, replace_file, safe_posix_fork, set_env, symbolizehash, thinmark, uri_encode, uri_query_encode, uri_to_path, which, withenv, withumask
Methods included from Util::POSIX
#get_posix_field, #gid, groups_of, #idfield, #methodbyid, #methodbyname, #search_posix_field, #uid
Methods included from Util::SymbolicFileMode
#normalize_symbolic_mode, #symbolic_mode_to_int, #valid_symbolic_mode?
Constructor Details
#initialize(values) ⇒ Variable
Returns a new instance of Variable.
24 25 26 27 |
# File 'lib/puppet/confine/variable.rb', line 24 def initialize(values) super @values = @values.collect { |v| v.to_s.downcase } end |
Instance Attribute Details
#name ⇒ Object
This is set by ConfineCollection.
17 18 19 |
# File 'lib/puppet/confine/variable.rb', line 17 def name @name end |
Class Method Details
.summarize(confines) ⇒ Object
Provide a hash summary of failing confines β the key of the hash is the name of the confine, and the value is the missing yet required values. Only returns failed values, not all required values.
11 12 13 14 |
# File 'lib/puppet/confine/variable.rb', line 11 def self.summarize(confines) result = Hash.new { |hash, key| hash[key] = [] } confines.inject(result) { |total, confine| total[confine.name] += confine.values unless confine.valid?; total } end |
Instance Method Details
#facter_value ⇒ Object
Retrieve the value from facter
20 21 22 |
# File 'lib/puppet/confine/variable.rb', line 20 def facter_value @facter_value ||= ::Facter.value(name).to_s.downcase end |
#message(value) ⇒ Object
29 30 31 |
# File 'lib/puppet/confine/variable.rb', line 29 def (value) "facter value '#{test_value}' for '#{self.name}' not in required list '#{values.join(",")}'" end |
#pass?(value) ⇒ Boolean
Compare the passed-in value to the retrieved value.
34 35 36 |
# File 'lib/puppet/confine/variable.rb', line 34 def pass?(value) test_value.downcase.to_s == value.to_s.downcase end |
#reset ⇒ Object
38 39 40 41 42 |
# File 'lib/puppet/confine/variable.rb', line 38 def reset # Reset the cache. We want to cache it during a given # run, but not across runs. @facter_value = nil end |
#valid? ⇒ Boolean
44 45 46 47 48 |
# File 'lib/puppet/confine/variable.rb', line 44 def valid? @values.include?(test_value.to_s.downcase) ensure reset end |