Class: Puppet::Indirector::Terminus

Inherits:
Object
  • Object
show all
Extended by:
Util::Docs, Util::InstanceLoader
Defined in:
lib/vendor/puppet/indirector/terminus.rb

Overview

A simple class that can function as the base class for indirected types.

Constant Summary

Constants included from Util

Util::AbsolutePathPosix, Util::AbsolutePathWindows

Constants included from Util::Docs

Util::Docs::HEADER_LEVELS

Class Attribute Summary collapse

Attributes included from Util::Docs

#doc, #nodoc

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util::InstanceLoader

instance_docs, instance_hash, instance_load, instance_loader, instance_loading?, loaded_instance, loaded_instances

Methods included from Util

absolute_path?, activerecord_version, benchmark, binread, chuser, classproxy, #execfail, #execpipe, execute, execute_posix, execute_windows, logmethods, memory, path_to_uri, proxy, replace_file, safe_posix_fork, symbolize, symbolizehash, symbolizehash!, synchronize_on, thinmark, #threadlock, uri_to_path, wait_for_output, which, withumask

Methods included from Util::POSIX

#get_posix_field, #gid, #idfield, #methodbyid, #methodbyname, #search_posix_field, #uid

Methods included from Util::Docs

desc, dochook, doctable, markdown_definitionlist, markdown_header, nodoc?, pad, scrub

Constructor Details

#initializeTerminus

Returns a new instance of Terminus.

Raises:



130
131
132
# File 'lib/vendor/puppet/indirector/terminus.rb', line 130

def initialize
  raise Puppet::DevError, "Cannot create instances of abstract terminus types" if self.class.abstract_terminus?
end

Class Attribute Details

.abstract_terminusObject (readonly)

Returns the value of attribute abstract_terminus.



14
15
16
# File 'lib/vendor/puppet/indirector/terminus.rb', line 14

def abstract_terminus
  @abstract_terminus
end

.indirectionObject

Returns the value of attribute indirection.



14
15
16
# File 'lib/vendor/puppet/indirector/terminus.rb', line 14

def indirection
  @indirection
end

.nameObject

Returns the value of attribute name.



13
14
15
# File 'lib/vendor/puppet/indirector/terminus.rb', line 13

def name
  @name
end

.terminus_typeObject

Returns the value of attribute terminus_type.



13
14
15
# File 'lib/vendor/puppet/indirector/terminus.rb', line 13

def terminus_type
  @terminus_type
end

Class Method Details

.abstract_terminus?Boolean

Are we an abstract terminus type, rather than an instance with an associated indirection?

Returns:

  • (Boolean)


18
19
20
# File 'lib/vendor/puppet/indirector/terminus.rb', line 18

def abstract_terminus?
  abstract_terminus
end

.const2name(const) ⇒ Object

Convert a constant to a short name.



23
24
25
# File 'lib/vendor/puppet/indirector/terminus.rb', line 23

def const2name(const)
  const.sub(/^[A-Z]/) { |i| i.downcase }.gsub(/[A-Z]/) { |i| "_#{i.downcase}" }.intern
end

.indirection_nameObject



38
39
40
# File 'lib/vendor/puppet/indirector/terminus.rb', line 38

def indirection_name
  @indirection.name
end

.inherited(subclass) ⇒ Object

Register our subclass with the appropriate indirection. This follows the convention that our terminus is named after the indirection.



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/vendor/puppet/indirector/terminus.rb', line 45

def inherited(subclass)
  longname = subclass.to_s
  if longname =~ /#<Class/
    raise Puppet::DevError, "Terminus subclasses must have associated constants"
  end
  names = longname.split("::")

  # Convert everything to a lower-case symbol, converting camelcase to underscore word separation.
  name = names.pop.sub(/^[A-Z]/) { |i| i.downcase }.gsub(/[A-Z]/) { |i| "_#{i.downcase}" }.intern

  subclass.name = name

  # Short-circuit the abstract types, which are those that directly subclass
  # the Terminus class.
  if self == Puppet::Indirector::Terminus
    subclass.mark_as_abstract_terminus
    return
  end

  # Set the terminus type to be the name of the abstract terminus type.
  # Yay, class/instance confusion.
  subclass.terminus_type = self.name

  # Our subclass is specifically associated with an indirection.
  raise("Invalid name #{longname}") unless names.length > 0
  indirection_name = names.pop.sub(/^[A-Z]/) { |i| i.downcase }.gsub(/[A-Z]/) { |i| "_#{i.downcase}" }.intern

  if indirection_name == "" or indirection_name.nil?
    raise Puppet::DevError, "Could not discern indirection model from class constant"
  end

  # This will throw an exception if the indirection instance cannot be found.
  # Do this last, because it also registers the terminus type with the indirection,
  # which needs the above information.
  subclass.indirection = indirection_name

  # And add this instance to the instance hash.
  Puppet::Indirector::Terminus.register_terminus_class(subclass)
end

.mark_as_abstract_terminusObject

Mark that this instance is abstract.



86
87
88
# File 'lib/vendor/puppet/indirector/terminus.rb', line 86

def mark_as_abstract_terminus
  @abstract_terminus = true
end

.modelObject



90
91
92
# File 'lib/vendor/puppet/indirector/terminus.rb', line 90

def model
  indirection.model
end

.name2const(name) ⇒ Object

Convert a short name to a constant.



95
96
97
# File 'lib/vendor/puppet/indirector/terminus.rb', line 95

def name2const(name)
  name.to_s.capitalize.sub(/_(.)/) { |i| $1.upcase }
end

.register_terminus_class(klass) ⇒ Object

Register a class, probably autoloaded.



100
101
102
103
# File 'lib/vendor/puppet/indirector/terminus.rb', line 100

def register_terminus_class(klass)
  setup_instance_loading klass.indirection_name
  instance_hash(klass.indirection_name)[klass.name] = klass
end

.terminus_class(indirection_name, terminus_type) ⇒ Object

Return a terminus by name, using the autoloader.



106
107
108
109
# File 'lib/vendor/puppet/indirector/terminus.rb', line 106

def terminus_class(indirection_name, terminus_type)
  setup_instance_loading indirection_name
  loaded_instance(indirection_name, terminus_type)
end

.terminus_classes(indirection_name) ⇒ Object

Return all terminus classes for a given indirection.



112
113
114
115
116
117
# File 'lib/vendor/puppet/indirector/terminus.rb', line 112

def terminus_classes(indirection_name)
  setup_instance_loading indirection_name
  instance_loader(indirection_name).files_to_load.map do |file|
    File.basename(file).chomp(".rb").intern
  end
end

Instance Method Details

#indirectionObject



126
127
128
# File 'lib/vendor/puppet/indirector/terminus.rb', line 126

def indirection
  self.class.indirection
end

#modelObject



134
135
136
# File 'lib/vendor/puppet/indirector/terminus.rb', line 134

def model
  self.class.model
end

#nameObject



138
139
140
# File 'lib/vendor/puppet/indirector/terminus.rb', line 138

def name
  self.class.name
end

#terminus_typeObject



142
143
144
# File 'lib/vendor/puppet/indirector/terminus.rb', line 142

def terminus_type
  self.class.terminus_type
end