diff options
-rw-r--r-- | state.rb | 19 |
1 files changed, 15 insertions, 4 deletions
@@ -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 |