Class: Puppet::Confine

Inherits:
Object show all
Includes:
Util
Defined in:
lib/puppet/confine/boolean.rb,
lib/puppet/confine.rb

Overview

Common module for the Boolean confines. It currently contains just enough code to implement PUP-9336.

Direct Known Subclasses

Any, Exists, False, Feature, True, Variable

Defined Under Namespace

Modules: Boolean Classes: Any, Exists, False, Feature, True, Variable

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

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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) ⇒ Confine

Returns a new instance of Confine.



54
55
56
57
# File 'lib/puppet/confine.rb', line 54

def initialize(values)
  values = [values] unless values.is_a?(Array)
  @values = values
end

Class Attribute Details

.nameObject

Returns the value of attribute name.



13
14
15
# File 'lib/puppet/confine.rb', line 13

def name
  @name
end

Instance Attribute Details

#for_binaryObject

Mark that this confine is used for testing binary existence.



45
46
47
# File 'lib/puppet/confine.rb', line 45

def for_binary
  @for_binary
end

#labelObject

Used for logging.



52
53
54
# File 'lib/puppet/confine.rb', line 52

def label
  @label
end

#valuesObject (readonly)

Returns the value of attribute values.



42
43
44
# File 'lib/puppet/confine.rb', line 42

def values
  @values
end

Class Method Details

.inherited(klass) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/puppet/confine.rb', line 16

def self.inherited(klass)
  name = klass.to_s.split("::").pop.downcase.to_sym
  raise "Test #{name} is already defined" if @tests.include?(name)

  klass.name = name

  @tests[name] = klass
end

.test(name) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/puppet/confine.rb', line 25

def self.test(name)
  unless @tests.include?(name)
    begin
      require "puppet/confine/#{name}"
    rescue LoadError => detail
      unless detail.to_s =~ /No such file|cannot load such file/i
        Puppet.warning("Could not load confine test '#{name}': #{detail}")
      end
      # Could not find file
      unless Puppet[:always_retry_plugins]
        @tests[name] = nil
      end
    end
  end
  @tests[name]
end

Instance Method Details

#for_binary?Boolean

Returns:



47
48
49
# File 'lib/puppet/confine.rb', line 47

def for_binary?
  for_binary
end

#message(value) ⇒ Object

Provide a hook for the message when there’s a failure.



60
61
62
# File 'lib/puppet/confine.rb', line 60

def message(value)
  ""
end

#resetObject

Provide a hook for subclasses.



84
85
# File 'lib/puppet/confine.rb', line 84

def reset
end

#resultObject

Collect the results of all of them.



65
66
67
# File 'lib/puppet/confine.rb', line 65

def result
  values.collect { |value| pass?(value) }
end

#valid?Boolean

Test whether our confine matches.

Returns:



70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/puppet/confine.rb', line 70

def valid?
  values.each do |value|
    unless pass?(value)
      Puppet.debug { label + ": " + message(value) }
      return false
    end
  end

  true
ensure
  reset
end