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::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

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

Returns a new instance of Confine.



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

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

Class Attribute Details

.nameObject

Returns the value of attribute name.



11
12
13
# File 'lib/puppet/confine.rb', line 11

def name
  @name
end

Instance Attribute Details

#for_binaryObject

Mark that this confine is used for testing binary existence.



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

def for_binary
  @for_binary
end

#labelObject

Used for logging.



49
50
51
# File 'lib/puppet/confine.rb', line 49

def label
  @label
end

#valuesObject (readonly)

Returns the value of attribute values.



40
41
42
# File 'lib/puppet/confine.rb', line 40

def values
  @values
end

Class Method Details

.inherited(klass) ⇒ Object



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

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



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

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
        warn "Could not load confine test '#{name}': #{detail}"
      end
      # Could not find file
      if !Puppet[:always_retry_plugins]
        @tests[name] = nil
      end
    end
  end
  @tests[name]
end

Instance Method Details

#for_binary?Boolean

Returns:



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

def for_binary?
  for_binary
end

#message(value) ⇒ Object

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



57
58
59
# File 'lib/puppet/confine.rb', line 57

def message(value)
  ""
end

#resetObject

Provide a hook for subclasses.



81
82
# File 'lib/puppet/confine.rb', line 81

def reset
end

#resultObject

Collect the results of all of them.



62
63
64
# File 'lib/puppet/confine.rb', line 62

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

#valid?Boolean

Test whether our confine matches.

Returns:



67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/puppet/confine.rb', line 67

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

  return true
ensure
  reset
end