summaryrefslogtreecommitdiffstats
path: root/state.rb
diff options
context:
space:
mode:
authorCasey Dahlin <cdahlin@redhat.com>2008-10-07 10:33:14 -0400
committerCasey Dahlin <cdahlin@redhat.com>2008-10-07 10:33:14 -0400
commit3c54eacbd4a6866e86fd80e60426812c18c59824 (patch)
tree51b67940e66290db94a14b114c86f2310c0af0a1 /state.rb
parent4578965df38401a58fb7573ab5f33ef0600dbd67 (diff)
downloadupstate-3c54eacbd4a6866e86fd80e60426812c18c59824.tar.gz
upstate-3c54eacbd4a6866e86fd80e60426812c18c59824.tar.xz
upstate-3c54eacbd4a6866e86fd80e60426812c18c59824.zip
Added to_s and eql?
Classes now have to_s methods and eql? methods which are identical to ==
Diffstat (limited to 'state.rb')
-rw-r--r--state.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/state.rb b/state.rb
index b842184..6f232c9 100644
--- a/state.rb
+++ b/state.rb
@@ -85,6 +85,11 @@ class State
end
end
+ # Puts the class name and parameters
+ def to_s
+ "#{self.class.name}#{params.inspect} (#{@active ? "up" : "down"})"
+ end
+
# Hold this state. Holding a state informs the system that you would like it
# to come up or remain up. +hold+ can be an object of type Hold, an object of
# type State to establish that said state depends on this one, or one of
@@ -138,6 +143,9 @@ class State
self.hash == other.hash
end
+ # eql? is the same as ==
+ alias :eql? :==
+
# Match this State object to patterns or other State objects
def ===(other)
return other === self if other.is_a? StatePattern
@@ -271,6 +279,14 @@ class Hold
self.class == other.class
end
+ # eql? is the same as ==
+ def eql?(other); self == other; end
+
+ # The default to_s just prints the type of hold
+ def to_s
+ self.class.name
+ end
+
# A hold placed when the system has an interest in something being running
class System < Hold; end
# A hold placed when the user has asked for something to be running
@@ -291,6 +307,11 @@ class Hold
@dependent.drop
end
+ # Prints the state who has this hold
+ def to_s
+ "hold by #{@dependent}"
+ end
+
# Two Dep holds are equal if they have the same dependent
def ==(other)
return other == @dependent if other.is_a? State