Class: Puppet::Confine

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

Direct Known Subclasses

Any, Exists, False, Feature, True, Variable

Defined Under Namespace

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

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, #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.



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

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.



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

def for_binary
  @for_binary
end

#labelObject

Used for logging.



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

def label
  @label
end

#valuesObject (readonly)

Returns the value of attribute values.



37
38
39
# File 'lib/puppet/confine.rb', line 37

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
# File 'lib/puppet/confine.rb', line 23

def self.test(name)
  unless @tests[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
    end
  end
  @tests[name]
end

Instance Method Details

#for_binary?Boolean

Returns:

  • (Boolean)


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

def for_binary?
  for_binary
end

#message(value) ⇒ Object

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



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

def message(value)
  ""
end

#resetObject

Provide a hook for subclasses.



78
79
# File 'lib/puppet/confine.rb', line 78

def reset
end

#resultObject

Collect the results of all of them.



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

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

#valid?Boolean

Test whether our confine matches.

Returns:

  • (Boolean)


64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/puppet/confine.rb', line 64

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

  return true
ensure
  reset
end