summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2005-04-14 04:49:28 +0000
committerLuke Kanies <luke@madstop.com>2005-04-14 04:49:28 +0000
commitc6755f5f30be79ddb42c0afc4d89be42a2df47f9 (patch)
tree0ff0ccc7d1b013680346bba10c7d5216ea693ad7
parente5676ab347399a1f32e77bf4f64eaa73d54a895b (diff)
adding class collection and naming stuff
git-svn-id: https://reductivelabs.com/svn/puppet/library/trunk@149 980ebf18-57e1-0310-9a29-db15c13687c0
-rw-r--r--lib/blink/interface.rb3
-rw-r--r--lib/blink/objects.rb49
-rw-r--r--lib/blink/objects/file.rb3
-rw-r--r--lib/blink/objects/package.rb1
-rw-r--r--lib/blink/objects/process.rb46
-rw-r--r--lib/blink/objects/service.rb3
-rw-r--r--lib/blink/objects/symlink.rb3
7 files changed, 69 insertions, 39 deletions
diff --git a/lib/blink/interface.rb b/lib/blink/interface.rb
index 4a507c3b9..6362fcc39 100644
--- a/lib/blink/interface.rb
+++ b/lib/blink/interface.rb
@@ -34,6 +34,7 @@ module Blink
# we, uh, don't do anything
end
end
+ self.retrieve
end
#---------------------------------------------------------------
@@ -42,7 +43,7 @@ module Blink
[:sync,:retrieve].each { |method|
self.send(:define_method,method) {
self.each { |subobj|
- Blink.debug("sending '%s' to '%s'" % [method,subobj])
+ #Blink.debug("sending '%s' to '%s'" % [method,subobj])
subobj.send(method)
}
}
diff --git a/lib/blink/objects.rb b/lib/blink/objects.rb
index 14ecd92b5..5d03dc1aa 100644
--- a/lib/blink/objects.rb
+++ b/lib/blink/objects.rb
@@ -5,7 +5,11 @@
require 'blink/attribute'
require 'blink/interface'
-puts Blink.class
+#---------------------------------------------------------------
+# This class is the abstract base class for the mechanism for organizing
+# work. No work is actually done by this class or its subclasses; rather,
+# the subclasses include attributes which do the actual work.
+# See attribute.rb for how work is actually done.
module Blink
class Objects < Blink::Interface
@@ -13,7 +17,9 @@ module Blink
@objects = Hash.new
@@allobjects = Array.new # and then an array for all objects
- @@types = Hash.new { |hash,key|
+
+ @@typeary = []
+ @@typehash = Hash.new { |hash,key|
raise "Object type %s not found" % key
}
@@ -24,11 +30,28 @@ module Blink
# all objects total
def Objects.push(object)
@@allobjects.push object
- Blink.debug("adding %s of type %s to master list" % [object.name,object.class])
+ Blink.debug("adding %s of type %s to master list" %
+ [object.name,object.class])
end
#-----------------------------------
#-----------------------------------
+ # this is meant to be run multiple times, e.g., when a new
+ # type is defined at run-time
+ def Objects.buildtypehash
+ @@typeary.each { |otype|
+ if @@typehash.include?(otype.name)
+ if @@typehash[otype.name] != otype
+ Blink.warning("Object type %s is already defined" % otype.name)
+ end
+ else
+ @@typehash[otype.name] = otype
+ end
+ }
+ end
+ #-----------------------------------
+
+ #-----------------------------------
# this should make it so our subclasses don't have to worry about
# defining these class instance variables
def Objects.inherited(sub)
@@ -37,16 +60,23 @@ module Blink
@actions = Hash.new
}
- if @@types.include?(sub.name)
- Blink.notice("Redefining object type %s" % sub.name)
- else
- #Blink.debug("Defining object type %s" % sub.name)
- end
- @@types[sub.name] = sub
+ # add it to the master list
+ # unfortunately we can't yet call sub.name, because the #inherited
+ # method gets called before any commands in the class definition
+ # get executed, which, um, sucks
+ @@typeary.push(sub)
end
#-----------------------------------
#-----------------------------------
+ # this is used for mapping object types (e.g., Blink::Objects::File)
+ # to names (e.g., "file")
+ def Objects.name
+ return @name
+ end
+ #-----------------------------------
+
+ #-----------------------------------
# some simple stuff to make it easier to get a name from everyone
def Objects.namevar
return @namevar
@@ -264,6 +294,7 @@ module Blink
# this is a wrapper, doing all of the work that should be done
# and none that shouldn't
def evaluate
+ raise "don't call evaluate; it's disabled"
end
#-----------------------------------
diff --git a/lib/blink/objects/file.rb b/lib/blink/objects/file.rb
index 3f2a8dcfc..502a5a404 100644
--- a/lib/blink/objects/file.rb
+++ b/lib/blink/objects/file.rb
@@ -205,8 +205,7 @@ module Blink
:path
]
- @objects = Hash.new
- @actions = Hash.new
+ @name = :file
@namevar = :path
end # Blink::Objects::File
end # Blink::Objects
diff --git a/lib/blink/objects/package.rb b/lib/blink/objects/package.rb
index faf8905af..407b5871a 100644
--- a/lib/blink/objects/package.rb
+++ b/lib/blink/objects/package.rb
@@ -16,6 +16,7 @@ module Blink
:version
]
+ @name = :package
@namevar = :name
# this is already being done in objects.rb
diff --git a/lib/blink/objects/process.rb b/lib/blink/objects/process.rb
index 182667d7c..e2e5722fc 100644
--- a/lib/blink/objects/process.rb
+++ b/lib/blink/objects/process.rb
@@ -7,29 +7,6 @@ require 'blink/operation/processes'
# I'm only working on services, not processes, right now
module Blink
- class Objects
- class BProcess < Objects
- attr_reader :stat, :path
- @params = [:start, :stop, :user, :pattern, :binary, :arguments] # class instance variable
-
- @objects = Hash.new
- @namevar = :pattern
-
- Blink::Relation.new(self, Blink::Operation::Start, {
- :user => :user,
- :pattern => :pattern,
- :binary => :binary,
- :arguments => :arguments
- })
-
- Blink::Relation.new(self, Blink::Operation::Stop, {
- :user => :user,
- :pattern => :pattern
- })
-
- end # Blink::Objects::BProcess
- end # Blink::Objects
-
class Attribute
class ProcessRunning < Attribute
def retrieve
@@ -83,4 +60,27 @@ module Blink
end
end
end
+ class Objects
+ class BProcess < Objects
+ attr_reader :stat, :path
+ @params = [:start, :stop, :user, :pattern, :binary, :arguments]
+ @name = :process
+
+ @namevar = :pattern
+
+ Blink::Relation.new(self, Blink::Operation::Start, {
+ :user => :user,
+ :pattern => :pattern,
+ :binary => :binary,
+ :arguments => :arguments
+ })
+
+ Blink::Relation.new(self, Blink::Operation::Stop, {
+ :user => :user,
+ :pattern => :pattern
+ })
+
+ end # Blink::Objects::BProcess
+ end # Blink::Objects
+
end
diff --git a/lib/blink/objects/service.rb b/lib/blink/objects/service.rb
index 8e69d1407..4e7f4b17e 100644
--- a/lib/blink/objects/service.rb
+++ b/lib/blink/objects/service.rb
@@ -78,8 +78,7 @@ module Blink
:pattern
]
- @objects = Hash.new
- @actions = Hash.new
+ @name = :service
@namevar = :name
@searchpaths = Array.new
diff --git a/lib/blink/objects/symlink.rb b/lib/blink/objects/symlink.rb
index 11187e2cf..ca08ea952 100644
--- a/lib/blink/objects/symlink.rb
+++ b/lib/blink/objects/symlink.rb
@@ -98,8 +98,7 @@ module Blink
:path
]
- @objects = Hash.new
- @actions = Hash.new
+ @name = :symlink
@namevar = :path
end # Blink::Objects::File
end # Blink::Objects