diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-07-04 22:25:23 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-07-04 22:25:23 +0000 |
| commit | c762c1960cc278f974c098ede994bb82f63fd893 (patch) | |
| tree | 568e3ce09d32176206e32e7da08af5fde87953ff /lib/puppet | |
| parent | 0ff7827d4d7f42fe59c10af35266f197e83b2b17 (diff) | |
| download | puppet-c762c1960cc278f974c098ede994bb82f63fd893.tar.gz puppet-c762c1960cc278f974c098ede994bb82f63fd893.tar.xz puppet-c762c1960cc278f974c098ede994bb82f63fd893.zip | |
Removing the long-obsolete Element base class. The Parameter and Type classes no longer have the same base class.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2647 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet')
| -rw-r--r-- | lib/puppet/element.rb | 52 | ||||
| -rw-r--r-- | lib/puppet/metatype/attributes.rb | 9 | ||||
| -rw-r--r-- | lib/puppet/metatype/evaluation.rb | 9 | ||||
| -rw-r--r-- | lib/puppet/metatype/instances.rb | 8 | ||||
| -rw-r--r-- | lib/puppet/metatype/metaparams.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/metatype/providers.rb | 3 | ||||
| -rw-r--r-- | lib/puppet/parameter.rb | 13 | ||||
| -rw-r--r-- | lib/puppet/property.rb (renamed from lib/puppet/type/property.rb) | 3 | ||||
| -rw-r--r-- | lib/puppet/propertychange.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/provider/package/appdmg.rb | 1 | ||||
| -rw-r--r-- | lib/puppet/type.rb | 17 | ||||
| -rw-r--r-- | lib/puppet/type/component.rb | 4 | ||||
| -rwxr-xr-x | lib/puppet/type/cron.rb | 1 | ||||
| -rwxr-xr-x | lib/puppet/type/exec.rb | 1 | ||||
| -rwxr-xr-x | lib/puppet/type/group.rb | 1 | ||||
| -rw-r--r-- | lib/puppet/type/package.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/type/pfile.rb | 1 | ||||
| -rwxr-xr-x | lib/puppet/type/tidy.rb | 1 | ||||
| -rwxr-xr-x | lib/puppet/type/user.rb | 1 | ||||
| -rw-r--r-- | lib/puppet/util/log.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/util/log_paths.rb | 16 |
21 files changed, 67 insertions, 82 deletions
diff --git a/lib/puppet/element.rb b/lib/puppet/element.rb deleted file mode 100644 index 1cda5e83b..000000000 --- a/lib/puppet/element.rb +++ /dev/null @@ -1,52 +0,0 @@ -# included so we can test object types -require 'puppet' - -# the base class for both types and parameters. -# very little functionality; basically just defines the interface -# and provides a few simple across-the-board functions like 'noop' -class Puppet::Element - include Puppet - include Puppet::Util - include Puppet::Util::Errors - attr_writer :noop - - class << self - attr_accessor :doc, :nodoc - include Puppet::Util - end - - # all of our subclasses must respond to each of these methods... - @@interface_methods = [ - :retrieve, :insync?, :sync, :evaluate - ] - - # so raise an error if a method that isn't overridden gets called - @@interface_methods.each { |method| - self.send(:define_method,method) { - raise Puppet::DevError, "%s(%s) has not overridden %s" % - [self.class, self.class.name,method] - } - } - - Puppet::Util.logmethods(self, true) - - # for testing whether we should actually do anything - def noop - unless defined? @noop - @noop = false - end - return @noop || Puppet[:noop] || false - end - - # return the full path to us, for logging and rollback - # some classes (e.g., FileTypeRecords) will have to override this - def path - unless defined? @path - @path = pathbuilder - end - - return "/" + @path.join("/") - end -end - -# $Id$ diff --git a/lib/puppet/metatype/attributes.rb b/lib/puppet/metatype/attributes.rb index 3e58963ea..4ba3588a1 100644 --- a/lib/puppet/metatype/attributes.rb +++ b/lib/puppet/metatype/attributes.rb @@ -236,7 +236,6 @@ class Puppet::Type # @parameters array, and does some basic checking on it. def self.newparam(name, options = {}, &block) options[:attributes] ||= {} - options[:attributes][:element] = self param = genclass(name, :parent => options[:parent] || Puppet::Parameter, :attributes => options[:attributes], @@ -485,7 +484,7 @@ class Puppet::Type if obj = @parameters[name] # We throw a failure here, because this method is too # ambiguous when used with properties. - if obj.is_a?(Puppet::Type::Property) + if obj.is_a?(Puppet::Property) fail "[] called on a property" else return obj.value @@ -544,7 +543,7 @@ class Puppet::Type # retrieve the 'should' value for a specified property def should(name) name = attr_alias(name) - if prop = @parameters[name] and prop.is_a?(Puppet::Type::Property) + if prop = @parameters[name] and prop.is_a?(Puppet::Property) return prop.should else return nil @@ -608,7 +607,7 @@ class Puppet::Type # return an actual type by name; to return the value, use 'inst[name]' # FIXME this method should go away def property(name) - if obj = @parameters[symbolize(name)] and obj.is_a?(Puppet::Type::Property) + if obj = @parameters[symbolize(name)] and obj.is_a?(Puppet::Property) return obj else return nil @@ -683,7 +682,7 @@ class Puppet::Type }.find_all { |p| ! p.nil? }.each do |prop| - unless prop.is_a?(Puppet::Type::Property) + unless prop.is_a?(Puppet::Property) raise Puppet::DevError, "got a non-property %s(%s)" % [prop.class, prop.class.name] end diff --git a/lib/puppet/metatype/evaluation.rb b/lib/puppet/metatype/evaluation.rb index ba4d84689..a7c9b6361 100644 --- a/lib/puppet/metatype/evaluation.rb +++ b/lib/puppet/metatype/evaluation.rb @@ -96,6 +96,15 @@ class Puppet::Type prophash } end + + # Are we running in noop mode? + def noop + if self.noop? + return true + else + return Puppet[:noop] + end + end # Retrieve the changes associated with all of the properties. def propertychanges(currentvalues) diff --git a/lib/puppet/metatype/instances.rb b/lib/puppet/metatype/instances.rb index 8a0a1d00c..d1c6d7732 100644 --- a/lib/puppet/metatype/instances.rb +++ b/lib/puppet/metatype/instances.rb @@ -1,3 +1,5 @@ +require 'puppet/transportable' + class Puppet::Type # Make 'new' private, so people have to use create instead. class << self @@ -89,7 +91,7 @@ class Puppet::Type # If we're the base class, then pass the info on appropriately if self == Puppet::Type type = nil - if hash.is_a? TransObject + if hash.is_a? Puppet::TransObject type = hash.type else # If we're using the type to determine object type, then delete it @@ -116,7 +118,7 @@ class Puppet::Type end name = nil - unless hash.is_a? TransObject + unless hash.is_a? Puppet::TransObject hash = self.hash2trans(hash) end @@ -236,7 +238,7 @@ class Puppet::Type end # okay, now make a transobject out of hash begin - trans = TransObject.new(title, self.name.to_s) + trans = Puppet::TransObject.new(title, self.name.to_s) hash.each { |param, value| trans[param] = value } diff --git a/lib/puppet/metatype/metaparams.rb b/lib/puppet/metatype/metaparams.rb index 7f0a1ef01..168ddb9ee 100644 --- a/lib/puppet/metatype/metaparams.rb +++ b/lib/puppet/metatype/metaparams.rb @@ -9,7 +9,7 @@ class Puppet::Type # non-functional." #end - newmetaparam(:noop) do + newmetaparam(:noop, :boolean => true) do desc "Boolean flag indicating whether work should actually be done." diff --git a/lib/puppet/metatype/providers.rb b/lib/puppet/metatype/providers.rb index e33657a4c..652c3c683 100644 --- a/lib/puppet/metatype/providers.rb +++ b/lib/puppet/metatype/providers.rb @@ -1,3 +1,4 @@ +require 'puppet/provider' require 'puppet/util/provider_features' class Puppet::Type # Add the feature handling module. @@ -127,7 +128,7 @@ class Puppet::Type end end else - Puppet::Type::Provider + Puppet::Provider end options[:resource_type] ||= self diff --git a/lib/puppet/parameter.rb b/lib/puppet/parameter.rb index b427c1058..8f4baa33e 100644 --- a/lib/puppet/parameter.rb +++ b/lib/puppet/parameter.rb @@ -1,10 +1,17 @@ require 'puppet/util/methodhelper' - -class Puppet::Parameter < Puppet::Element +require 'puppet/util/log_paths' +require 'puppet/util/logging' + +class Puppet::Parameter + include Puppet::Util + include Puppet::Util::Errors + include Puppet::Util::LogPaths + include Puppet::Util::Logging include Puppet::Util::MethodHelper class << self + include Puppet::Util attr_reader :validater, :munger, :name, :default, :required_features - attr_accessor :metaparam, :element + attr_accessor :metaparam # Define the default value for a given parameter or parameter. This # means that 'nil' is an invalid default value. This defines diff --git a/lib/puppet/type/property.rb b/lib/puppet/property.rb index 7fbf33df0..a7e79c9c5 100644 --- a/lib/puppet/type/property.rb +++ b/lib/puppet/property.rb @@ -2,7 +2,6 @@ # blocks for actually doing work on the system. require 'puppet' -require 'puppet/element' require 'puppet/propertychange' require 'puppet/parameter' @@ -14,6 +13,8 @@ class Property < Puppet::Parameter # they can be retrieved and compared later when merging. attr_reader :shouldorig + attr_writer :noop + class << self attr_accessor :unmanaged attr_reader :name diff --git a/lib/puppet/propertychange.rb b/lib/puppet/propertychange.rb index ff221cd52..c6901edfb 100644 --- a/lib/puppet/propertychange.rb +++ b/lib/puppet/propertychange.rb @@ -53,7 +53,7 @@ module Puppet end def initialize(property, currentvalue) - unless property.is_a?(Puppet::Type::Property) + unless property.is_a?(Puppet::Property) raise Puppet::DevError, "Got a %s instead of a property" % property.class end diff --git a/lib/puppet/provider/package/appdmg.rb b/lib/puppet/provider/package/appdmg.rb index c63c26a1f..1041e55d4 100644 --- a/lib/puppet/provider/package/appdmg.rb +++ b/lib/puppet/provider/package/appdmg.rb @@ -19,7 +19,6 @@ require 'puppet/provider/package' Puppet::Type.type(:package).provide(:appdmg, :parent => Puppet::Provider::Package) do desc "Package management which copies application bundles to a target." - defaultfor :operatingsystem => :darwin confine :exists => "/Library/Receipts" commands :hdiutil => "/usr/bin/hdiutil" commands :curl => "/usr/bin/curl" diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb index fe0fc2810..e3eaf4901 100644 --- a/lib/puppet/type.rb +++ b/lib/puppet/type.rb @@ -1,18 +1,25 @@ require 'puppet' require 'puppet/util/log' -require 'puppet/element' require 'puppet/event' require 'puppet/util/metric' -require 'puppet/type/property' +require 'puppet/property' require 'puppet/parameter' require 'puppet/util' require 'puppet/util/autoload' require 'puppet/metatype/manager' +require 'puppet/util/errors' +require 'puppet/util/log_paths' +require 'puppet/util/logging' # see the bottom of the file for the rest of the inclusions module Puppet -class Type < Puppet::Element +class Type + include Puppet::Util + include Puppet::Util::Errors + include Puppet::Util::LogPaths + include Puppet::Util::Logging + # Nearly all of the code in this class is stored in files in the # metatype/ directory. This is a temporary measure until I get a chance # to refactor this class entirely. There's still more simplification to @@ -40,6 +47,7 @@ class Type < Puppet::Element attr_reader :parent attr_writer :title + attr_writer :noop include Enumerable @@ -53,6 +61,9 @@ class Type < Puppet::Element attr_accessor :self_refresh include Enumerable, Puppet::Util::ClassGen include Puppet::MetaType::Manager + + include Puppet::Util + include Puppet::Util::Logging end # all of the variables that must be initialized for each subclass diff --git a/lib/puppet/type/component.rb b/lib/puppet/type/component.rb index 82ee8c056..41b284b4a 100644 --- a/lib/puppet/type/component.rb +++ b/lib/puppet/type/component.rb @@ -131,10 +131,10 @@ Puppet::Type.newtype(:component) do if parentof?(child) devfail "Already the parent of %s[%s]" % [child.class.name, child.title] end - unless child.is_a?(Puppet::Element) + unless child.is_a?(Puppet::Type) self.debug "Got object of type %s" % child.class self.devfail( - "Containers can only contain Puppet::Elements, not %s" % + "Containers can only contain Puppet resources, not %s" % child.class ) end diff --git a/lib/puppet/type/cron.rb b/lib/puppet/type/cron.rb index debf8c85f..f0188e8e7 100755 --- a/lib/puppet/type/cron.rb +++ b/lib/puppet/type/cron.rb @@ -1,6 +1,5 @@ require 'etc' require 'facter' -require 'puppet/type/property' require 'puppet/util/filetype' Puppet::Type.newtype(:cron) do diff --git a/lib/puppet/type/exec.rb b/lib/puppet/type/exec.rb index dabd98830..13d76577a 100755 --- a/lib/puppet/type/exec.rb +++ b/lib/puppet/type/exec.rb @@ -51,7 +51,6 @@ module Puppet you to get a native element type for the work you are doing." require 'open3' - require 'puppet/type/property' # Create a new check mechanism. It's basically just a parameter that # provides one extra 'check' method. diff --git a/lib/puppet/type/group.rb b/lib/puppet/type/group.rb index 8ca687904..e8e2047e5 100755 --- a/lib/puppet/type/group.rb +++ b/lib/puppet/type/group.rb @@ -8,7 +8,6 @@ require 'etc' require 'facter' -require 'puppet/type/property' module Puppet newtype(:group) do diff --git a/lib/puppet/type/package.rb b/lib/puppet/type/package.rb index 8072361a9..d6e05c526 100644 --- a/lib/puppet/type/package.rb +++ b/lib/puppet/type/package.rb @@ -3,8 +3,6 @@ # This allows packages to exist on the same machine using different packaging # systems. -require 'puppet/type/property' - module Puppet class PackageError < Puppet::Error; end newtype(:package) do diff --git a/lib/puppet/type/pfile.rb b/lib/puppet/type/pfile.rb index 148cf4b52..402ca00e8 100644 --- a/lib/puppet/type/pfile.rb +++ b/lib/puppet/type/pfile.rb @@ -3,7 +3,6 @@ require 'cgi' require 'etc' require 'uri' require 'fileutils' -require 'puppet/type/property' require 'puppet/network/handler' module Puppet diff --git a/lib/puppet/type/tidy.rb b/lib/puppet/type/tidy.rb index 75a68170d..8b3ea6a76 100755 --- a/lib/puppet/type/tidy.rb +++ b/lib/puppet/type/tidy.rb @@ -1,6 +1,5 @@ require 'etc' -require 'puppet/type/property' require 'puppet/type/pfile' module Puppet diff --git a/lib/puppet/type/user.rb b/lib/puppet/type/user.rb index ea28fd72a..04fe4ec48 100755 --- a/lib/puppet/type/user.rb +++ b/lib/puppet/type/user.rb @@ -1,6 +1,5 @@ require 'etc' require 'facter' -require 'puppet/type/property' module Puppet newtype(:user) do diff --git a/lib/puppet/util/log.rb b/lib/puppet/util/log.rb index 8c085c38e..e7e000e30 100644 --- a/lib/puppet/util/log.rb +++ b/lib/puppet/util/log.rb @@ -518,7 +518,7 @@ class Puppet::Util::Log # We can't store the actual source, we just store the path. # We can't just check for whether it responds to :path, because # plenty of providers respond to that in their normal function. - if source.is_a?(Puppet::Element) and source.respond_to?(:path) + if (source.is_a?(Puppet::Type) or source.is_a?(Puppet::Parameter)) and source.respond_to?(:path) @objectsource = true @source = source.path else diff --git a/lib/puppet/util/log_paths.rb b/lib/puppet/util/log_paths.rb new file mode 100644 index 000000000..5cfec34cb --- /dev/null +++ b/lib/puppet/util/log_paths.rb @@ -0,0 +1,16 @@ +# Created by Luke Kanies on 2007-07-04. +# Copyright (c) 2007. All rights reserved. + +module Puppet::Util::LogPaths + # return the full path to us, for logging and rollback + # some classes (e.g., FileTypeRecords) will have to override this + def path + unless defined? @path + @path = pathbuilder + end + + return "/" + @path.join("/") + end +end + +# $Id$ |
