summaryrefslogtreecommitdiffstats
path: root/state.rb
diff options
context:
space:
mode:
authorCasey Dahlin <cdahlin@redhat.com>2008-10-03 14:10:43 -0400
committerCasey Dahlin <cdahlin@redhat.com>2008-10-03 14:23:58 -0400
commit42f1039dfd7c83ba811fca91f7adc41117ffbdda (patch)
treedca554ce4c0f614baf5d8a1cff8dc171e17bd26f /state.rb
parentf387145da2a8bde2911b977a8526f1461755a435 (diff)
downloadupstate-42f1039dfd7c83ba811fca91f7adc41117ffbdda.tar.gz
upstate-42f1039dfd7c83ba811fca91f7adc41117ffbdda.tar.xz
upstate-42f1039dfd7c83ba811fca91f7adc41117ffbdda.zip
Make params a method
The params attribute is now a method that aggregates parameters on demand
Diffstat (limited to 'state.rb')
-rw-r--r--state.rb19
1 files changed, 15 insertions, 4 deletions
diff --git a/state.rb b/state.rb
index fc29cce..e3777ae 100644
--- a/state.rb
+++ b/state.rb
@@ -15,7 +15,6 @@ An instance of State exists whenever a state can become true without having to
toggle any other states, or whenever a state _is_ true.
=end
class State
- attr :params # Parameters to this state
attr :holds # Holds that are had on this state
attr :active # Are we active?
class << self
@@ -39,7 +38,6 @@ class State
@holds = Set.new
@deps = deps.to_set
- @params = {}
@active = false
return if @@states.include? self
@@ -100,6 +98,12 @@ class State
becomes_defunct
end
+ # Parameters to this state
+ def params
+ @deps.map{ |x| x.params }.inject{ |x,y| x.merge y }.merge \
+ @holds.map{ |x| x.params }.inject{ |x,y| x.merge y}
+ end
+
# Set this state to untrue without running any falling edge code
def becomes_defunct
return unless @active
@@ -123,7 +127,7 @@ class State
# Our ID is a function of our class and deps
def hash
- @deps.inject(self.class.hash){ |x,y| (x ** 2 + y) % 0x4000000000000000 }
+ @deps.inject(self.class.hash){ |x,y| (x ** 2 + y.object_id) % 0x4000000000000000 }
end
# A state is rooted in a set of states if any state in the set which it _may_
@@ -215,8 +219,13 @@ A Hold is placed on a State when something has an interest in that State being
up. States drop automatically when they cease to have any holds on them.
=end
class Hold
- def initialize #:nodoc:
+ attr :params # Parameters of this hold
+
+ # +params+ should be a hash of parameters.
+ def initialize(params)
raise NoMethodError if self.class == Hold
+ raise TypeError unless params.is_a? Hash
+ @params = params
end
# Inform interested parties that this hold can no longer be maintained, and
@@ -242,6 +251,8 @@ class Hold
@dependent = dependent
end
+ def params; {}; end #:nodoc:
+
# Kill the dependent state so that the depended state can drop
def clear
@dependent.drop