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::ALNUM, Util::ALPHA, Util::AbsolutePathPosix, Util::AbsolutePathWindows, Util::DEFAULT_POSIX_MODE, Util::DEFAULT_WINDOWS_MODE, Util::ESCAPED, Util::HEX, Util::HttpProxy, Util::PUPPET_STACK_INSERTION_FRAME, Util::RESERVED, Util::RFC_3986_URI_REGEX, Util::UNRESERVED, Util::UNSAFE
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, create_erb, default_env, deterministic_rand, deterministic_rand_int, exit_on_fail, format_backtrace_array, format_puppetstack_frame, get_env, get_environment, logmethods, merge_environment, path_to_uri, pretty_backtrace, replace_file, resolve_stackframe, rfc2396_escape, safe_posix_fork, set_env, skip_external_facts, symbolizehash, thinmark, uri_encode, uri_query_encode, uri_to_path, uri_unescape, 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
#display_mode, #normalize_symbolic_mode, #symbolic_mode_to_int, #valid_symbolic_mode?
Constructor Details
#initialize(values) ⇒ Variable
Returns a new instance of Variable.
26 27 28 29 |
# File 'lib/puppet/confine/variable.rb', line 26 def initialize(values) super @values = @values.collect { |v| v.to_s.downcase } end |
Instance Attribute Details
#name ⇒ Object
This is set by ConfineCollection.
19 20 21 |
# File 'lib/puppet/confine/variable.rb', line 19 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.
13 14 15 16 |
# File 'lib/puppet/confine/variable.rb', line 13 def self.summarize(confines) result = Hash.new { |hash, key| hash[key] = [] } confines.each_with_object(result) { |confine, total| total[confine.name] += confine.values unless confine.valid?; } end |
Instance Method Details
#facter_value ⇒ Object
Retrieve the value from facter
22 23 24 |
# File 'lib/puppet/confine/variable.rb', line 22 def facter_value @facter_value ||= Puppet.runtime[:facter].value(name).to_s.downcase end |
#message(value) ⇒ Object
31 32 33 |
# File 'lib/puppet/confine/variable.rb', line 31 def (value) "facter value '#{test_value}' for '#{name}' not in required list '#{values.join(',')}'" end |
#pass?(value) ⇒ Boolean
Compare the passed-in value to the retrieved value.
36 37 38 |
# File 'lib/puppet/confine/variable.rb', line 36 def pass?(value) test_value.downcase.to_s == value.to_s.downcase end |
#reset ⇒ Object
40 41 42 43 44 |
# File 'lib/puppet/confine/variable.rb', line 40 def reset # Reset the cache. We want to cache it during a given # run, but not across runs. @facter_value = nil end |
#valid? ⇒ Boolean
46 47 48 49 50 |
# File 'lib/puppet/confine/variable.rb', line 46 def valid? @values.include?(test_value.to_s.downcase) ensure reset end |