summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2005-04-14 16:12:29 +0000
committerLuke Kanies <luke@madstop.com>2005-04-14 16:12:29 +0000
commitc0c1f1a2c4b93abfe410c308d6787eeef0276348 (patch)
tree272662df334c3142948c028b63289160f8cc3ffa
parent6dce8fc1bc5b6b78dd284273f1d10b123d56c01d (diff)
renaming attributes to states
git-svn-id: https://reductivelabs.com/svn/puppet/library/trunk@156 980ebf18-57e1-0310-9a29-db15c13687c0
-rw-r--r--lib/blink/interface.rb17
-rw-r--r--lib/blink/state.rb (renamed from lib/blink/attribute.rb)34
-rw-r--r--lib/blink/types.rb106
-rw-r--r--lib/blink/types/file.rb30
-rw-r--r--lib/blink/types/process.rb7
-rw-r--r--lib/blink/types/service.rb6
-rw-r--r--lib/blink/types/symlink.rb16
7 files changed, 92 insertions, 124 deletions
diff --git a/lib/blink/interface.rb b/lib/blink/interface.rb
index 6362fcc39..f778dc802 100644
--- a/lib/blink/interface.rb
+++ b/lib/blink/interface.rb
@@ -5,10 +5,10 @@
# our duck type interface -- if your object doesn't match this interface,
# it won't work
-# all of our first-class objects (objects, attributes, and components) will
+# all of our first-class objects (objects, states, and components) will
# respond to these methods
-# although attributes don't inherit from Blink::Interface
-# although maybe Blink::Attribute should...
+# although states don't inherit from Blink::Interface
+# although maybe Blink::State should...
# the default behaviour that this class provides is to just call a given
# method on each contained object, e.g., in calling 'sync', we just run:
@@ -51,6 +51,17 @@ module Blink
#---------------------------------------------------------------
#---------------------------------------------------------------
+ def presync
+ self.each { |contained|
+ # this gets right to the heart of our question:
+ # do all subclasses of Interface contain all of their
+ # content in contained objects?
+ Blink::Modification.new(contained)
+ }
+ end
+ #---------------------------------------------------------------
+
+ #---------------------------------------------------------------
# if all contained objects are in sync, then we're in sync
def insync?
insync = true
diff --git a/lib/blink/attribute.rb b/lib/blink/state.rb
index e6c2d83bd..d952b7a8a 100644
--- a/lib/blink/attribute.rb
+++ b/lib/blink/state.rb
@@ -3,14 +3,14 @@
# $Id$
module Blink
- # this is a virtual base class for attributes
- # attributes are self-contained building blocks for objects
+ # this is a virtual base class for states
+ # states are self-contained building blocks for objects
- # Attributes can currently only be used for comparing a virtual "should" value
+ # States can currently only be used for comparing a virtual "should" value
# against the real state of the system. For instance, you could verify that
# a file's owner is what you want, but you could not create two file objects
# and use these methods to verify that they have the same owner
- class Attribute
+ class State
include Comparable
attr_accessor :value
@@ -18,17 +18,17 @@ module Blink
attr_accessor :object
#-----------------------------------
- # every attribute class must tell us what it's name will be (as a symbol)
- # this determines how we will refer to the attribute during usage
- # e.g., the Owner attribute for Files might say its name is :owner;
+ # every state class must tell us what it's name will be (as a symbol)
+ # this determines how we will refer to the state during usage
+ # e.g., the Owner state for Files might say its name is :owner;
# this means that we can say "file[:owner] = 'yayness'"
- def Attribute.name
+ def State.name
return @name
end
#-----------------------------------
#-----------------------------------
- # we aren't actually comparing the attributes themselves, we're only
+ # we aren't actually comparing the states themselves, we're only
# comparing the "should" value with the "real" value
def insync?
Blink.debug "%s value is %s, should be %s" % [self,self.value,self.should]
@@ -43,9 +43,9 @@ module Blink
#-----------------------------------
#-----------------------------------
- # DISABLED: we aren't comparing attributes, just attribute values
+ # DISABLED: we aren't comparing states, just state values
# are we in sync?
- # this could be a comparison between two attributes on two objects,
+ # this could be a comparison between two states on two objects,
# or a comparison between an object and the live system -- we'll
# let the object decide that, rather than us
#def <=>(other)
@@ -58,7 +58,7 @@ module Blink
#-----------------------------------
#-----------------------------------
- # each attribute class must define the name() method
+ # each state class must define the name() method
def name
return self.class.name
end
@@ -78,12 +78,12 @@ module Blink
#-----------------------------------
#-----------------------------------
- # this class is for attributes that don't reflect on disk,
+ # this class is for states that don't reflect on disk,
# like 'path' on files and 'name' on processes
- # these are basically organizational attributes, not functional ones
+ # these are basically organizational states, not functional ones
#
# we provide stub methods, so that from the outside it looks like
- # other attributes
+ # other states
#
# see objects.rb for how this is used
class Symbol
@@ -123,9 +123,9 @@ module Blink
end
# this class is supposed to be used to solve cases like file modes,
- # where one command (stat) retrieves enough data to cover many attributes
+ # where one command (stat) retrieves enough data to cover many states
# (e.g., setuid, setgid, world-read, etc.)
- class MetaAttribute
+ class MetaState
include Comparable
attr_accessor :parent
attr_accessor :value
diff --git a/lib/blink/types.rb b/lib/blink/types.rb
index 00e9b1804..8b050ca04 100644
--- a/lib/blink/types.rb
+++ b/lib/blink/types.rb
@@ -2,17 +2,17 @@
# $Id$
-require 'blink/attribute'
+require 'blink/state'
require 'blink/interface'
#---------------------------------------------------------------
# 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.
+# the subclasses include states which do the actual work.
+# See state.rb for how work is actually done.
module Blink
- class Types
+ class Types < Blink::Interface
include Enumerable
@objects = Hash.new
@@allobjects = Array.new # and then an array for all objects
@@ -26,46 +26,6 @@ module Blink
#---------------------------------------------------------------
# the class methods
- #---------------------------------------------------------------
- # retrieve a named object
- def Types.[](name)
- if @objects.has_key?(name)
- return @objects[name]
- else
- raise "Object '#{name}' does not exist"
- end
- end
- #---------------------------------------------------------------
-
- #---------------------------------------------------------------
- # this is special, because it can be equivalent to running new
- # this allows cool syntax like Blink::File["/etc/inetd.conf"] = ...
- def Types.[]=(name,object)
- newobj = nil
- if object.is_a?(Blink::Types)
- newobj = object
- else
- raise "must pass a Blink::Types object"
- end
-
- if @objects.has_key?(newobj.name)
- puts @objects
- raise "'#{newobj.name}' already exists in " +
- "class '#{newobj.class}': #{@objects[newobj.name]}"
- else
- Blink.debug("adding %s of type %s to class list" %
- [object.name,object.class])
- @objects[newobj.name] = newobj
- end
- end
- #---------------------------------------------------------------
-
- #---------------------------------------------------------------
- def Types.has_key?(name)
- return @objects.has_key?(name)
- end
- #---------------------------------------------------------------
-
#-----------------------------------
# all objects total
def Types.push(object)
@@ -144,7 +104,7 @@ module Blink
@params.each { |param|
if param.is_a? Symbol
# store the Symbol class, not the symbol itself
- symbolattr = Blink::Attribute::Symbol.new(param)
+ symbolattr = Blink::State::Symbol.new(param)
@paramsbyname[param] = symbolattr
elsif param.respond_to?(:name)
@@ -168,8 +128,8 @@ module Blink
#-----------------------------------
# parameter access and stuff
def [](param)
- if @attributes.has_key?(param)
- return @attributes[param].should
+ if @states.has_key?(param)
+ return @states[param].should
else
raise "Undefined parameter '#{param}' in #{self}"
end
@@ -177,38 +137,38 @@ module Blink
#-----------------------------------
#-----------------------------------
- # because all object parameters are actually attributes, we
+ # because all object parameters are actually states, we
# have to do some shenanigans to make it look from the outside
- # like @attributes is just a simple hash
+ # like @states is just a simple hash
# the Symbol stuff is especially a bit hackish
def []=(param,value)
- if @attributes.has_key?(param)
- @attributes[param].should = value
+ if @states.has_key?(param)
+ @states[param].should = value
return
end
attrclass = self.class.classparambyname[param]
- Blink.debug("creating attribute of type '%s'" % attrclass)
- # any given object can normally only have one of any given attribute
- # type, but it might have many Symbol attributes
+ Blink.debug("creating state of type '%s'" % attrclass)
+ # any given object can normally only have one of any given state
+ # type, but it might have many Symbol states
#
- # so, we need to make sure that the @attributes hash behaves
- # the same whether it has a unique attribute or a bunch of Symbol
- # attributes
- if attrclass.is_a?(Blink::Attribute::Symbol)
+ # so, we need to make sure that the @states hash behaves
+ # the same whether it has a unique state or a bunch of Symbol
+ # states
+ if attrclass.is_a?(Blink::State::Symbol)
attrclass.should = value
- @attributes[param] = attrclass
+ @states[param] = attrclass
else
attr = attrclass.new(value)
attr.object = self
if attr.is_a?(Array)
attr.each { |xattr|
- @attributes[xattr.name] = attr
+ @states[xattr.name] = attr
}
else
Blink.debug "Creating attr %s in %s" % [attr.name,self]
- @attributes[attr.name] = attr
+ @states[attr.name] = attr
end
end
end
@@ -229,12 +189,12 @@ module Blink
#-----------------------------------
#-----------------------------------
- # removing attributes
+ # removing states
def delete(attr)
- if @attributes.has_key?(attr)
- @attributes.delete(attr)
+ if @states.has_key?(attr)
+ @states.delete(attr)
else
- raise "Undefined attribute '#{attr}' in #{self}"
+ raise "Undefined state '#{attr}' in #{self}"
end
end
#-----------------------------------
@@ -261,7 +221,7 @@ module Blink
unless block_given?
raise "'Each' was not given a block"
end
- @attributes.each { |name,attr|
+ @states.each { |name,attr|
#Blink.debug "'%s' yielding '%s' of type '%s'" % [self,attr,attr.class]
yield(attr)
}
@@ -358,9 +318,9 @@ module Blink
#-----------------------------------
# yay
def initialize(*args)
- # params are for classes, attributes are for instances
+ # params are for classes, states are for instances
# hokey but true
- @attributes = Hash.new
+ @states = Hash.new
@monitor = Array.new
# default to always syncing
@@ -373,12 +333,12 @@ module Blink
self.class.to_s)
end
- # if they passed in a list of attributes they're interested in,
+ # if they passed in a list of states they're interested in,
# we mark them as "interesting"
# XXX maybe we should just consider params set to nil as 'interesting'
#
# this isn't used as much as it should be, but the idea is that
- # the "interesting" attributes would be the ones retrieved during a
+ # the "interesting" states would be the ones retrieved during a
# 'retrieve' call
if hash.include?(:check)
@monitor = hash[:check].dup
@@ -386,7 +346,7 @@ module Blink
end
# we have to set the name of our object before anything else,
- # because it might be used in creating the other attributes
+ # because it might be used in creating the other states
if hash.has_key?(self.class.namevar)
self[self.class.namevar] = hash[self.class.namevar]
hash.delete(self.class.namevar)
@@ -427,12 +387,12 @@ module Blink
def name
#namevar = self.class.namevar
#Blink.debug "namevar is '%s'" % namevar
- #nameattr = @attributes[namevar]
+ #nameattr = @states[namevar]
#Blink.debug "nameattr is '%s'" % nameattr
#name = nameattr.value
#Blink.debug "returning %s from attr %s and namevar %s" % [name,nameattr,namevar]
#return name
- return @attributes[self.class.namevar].value
+ return @states[self.class.namevar].value
end
#-----------------------------------
diff --git a/lib/blink/types/file.rb b/lib/blink/types/file.rb
index 77e977993..233f77962 100644
--- a/lib/blink/types/file.rb
+++ b/lib/blink/types/file.rb
@@ -4,14 +4,14 @@
require 'digest/md5'
require 'etc'
-require 'blink/attribute'
+require 'blink/state'
module Blink
- # we first define all of the attribute that our file will use
+ # we first define all of the state that our file will use
# because the objects must be defined for us to use them in our
# definition of the file object
- class Attribute
- class FileUID < Blink::Attribute
+ class State
+ class FileUID < Blink::State
require 'etc'
attr_accessor :file
@name = :owner
@@ -66,10 +66,10 @@ module Blink
end
end
- # this attribute should actually somehow turn into many attributes,
+ # this state should actually somehow turn into many states,
# one for each bit in the mode
- # I think MetaAttributes are the answer, but I'm not quite sure
- class FileMode < Blink::Attribute
+ # I think MetaStates are the answer, but I'm not quite sure
+ class FileMode < Blink::State
require 'etc'
@name = :mode
@@ -98,11 +98,11 @@ module Blink
end
# not used until I can figure out how to solve the problem with
- # metaattributes
- class FileSetUID < Blink::Attribute
+ # metastates
+ class FileSetUID < Blink::State
require 'etc'
- @parent = Blink::Attribute::FileMode
+ @parent = Blink::State::FileMode
@name = :setuid
@@ -120,7 +120,7 @@ module Blink
end
end
- class FileGroup < Blink::Attribute
+ class FileGroup < Blink::State
require 'etc'
@name = :group
@@ -198,10 +198,10 @@ module Blink
attr_reader :stat, :path, :params
# class instance variable
@params = [
- Blink::Attribute::FileUID,
- Blink::Attribute::FileGroup,
- Blink::Attribute::FileMode,
- Blink::Attribute::FileSetUID,
+ Blink::State::FileUID,
+ Blink::State::FileGroup,
+ Blink::State::FileMode,
+ Blink::State::FileSetUID,
:path
]
diff --git a/lib/blink/types/process.rb b/lib/blink/types/process.rb
index 333191e37..ff0870dba 100644
--- a/lib/blink/types/process.rb
+++ b/lib/blink/types/process.rb
@@ -1,14 +1,11 @@
#!/usr/local/bin/ruby -w
-require 'blink/operation'
-require 'blink/operation/processes'
-
# DISABLED
# I'm only working on services, not processes, right now
module Blink
- class Attribute
- class ProcessRunning < Attribute
+ class State
+ class ProcessRunning < State
def retrieve
running = 0
regex = Regexp.new(@params[:pattern])
diff --git a/lib/blink/types/service.rb b/lib/blink/types/service.rb
index 0abfc7b32..8508a6dbd 100644
--- a/lib/blink/types/service.rb
+++ b/lib/blink/types/service.rb
@@ -9,8 +9,8 @@
# which is why they have a search path for initscripts and such
module Blink
- class Attribute
- class ServiceRunning < Attribute
+ class State
+ class ServiceRunning < State
@name = :running
def retrieve
@@ -73,7 +73,7 @@ module Blink
class Service < Types
attr_reader :stat
@params = [
- Blink::Attribute::ServiceRunning,
+ Blink::State::ServiceRunning,
:name,
:pattern
]
diff --git a/lib/blink/types/symlink.rb b/lib/blink/types/symlink.rb
index b4a2f9a2e..195454328 100644
--- a/lib/blink/types/symlink.rb
+++ b/lib/blink/types/symlink.rb
@@ -3,14 +3,14 @@
# $Id$
require 'etc'
-require 'blink/attribute'
-require 'blink/objects/file'
+require 'blink/state'
+require 'blink/types/file'
module Blink
# okay, how do we deal with parameters that don't have operations
# associated with them?
- class Attribute
- class SymlinkTarget < Blink::Attribute
+ class State
+ class SymlinkTarget < Blink::State
require 'etc'
attr_accessor :file
@@ -91,10 +91,10 @@ module Blink
attr_reader :stat, :path, :params
# class instance variable
@params = [
- Blink::Attribute::FileUID,
- Blink::Attribute::FileGroup,
- Blink::Attribute::FileMode,
- Blink::Attribute::SymlinkTarget,
+ Blink::State::FileUID,
+ Blink::State::FileGroup,
+ Blink::State::FileMode,
+ Blink::State::SymlinkTarget,
:path
]