Class: HegemonTransition
- Inherits:
-
Object
- Object
- HegemonTransition
- Defined in:
- lib/hegemon.rb
Instance Attribute Summary collapse
-
#dest_state ⇒ Object
readonly
Returns the value of attribute dest_state.
-
#src_state ⇒ Object
readonly
Returns the value of attribute src_state.
Instance Method Summary collapse
- #after(&block) ⇒ Object
-
#auto_update(val = :just_ask) ⇒ Object
Get or set the @auto_update value.
- #before(&block) ⇒ Object
- #condition(&block) ⇒ Object
-
#initialize(object, src_state, dest_state, &block) ⇒ HegemonTransition
constructor
A new instance of HegemonTransition.
- #ready?(*flags) ⇒ Boolean
- #requirement(&block) ⇒ Object
- #sufficient(&block) ⇒ Object
- #try(*flags) ⇒ Object
Constructor Details
#initialize(object, src_state, dest_state, &block) ⇒ HegemonTransition
Returns a new instance of HegemonTransition.
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 |
# File 'lib/hegemon.rb', line 324 def initialize(object, src_state, dest_state, &block) raise ScriptError, "HegemonTransition must be initialized with a block"\ unless block.is_a? Proc @object = object @src_state = src_state @dest_state = dest_state @object.instance_variable_set(:@_hegemon_transition_lock, (@transition_lock = Monitor.new)) \ unless (@transition_lock = @object.instance_variable_get( \ :@_hegemon_transition_lock)) @conditions = [] @sufficients = [] @requirements = [] @befores = [] @afters = [] @progress = nil @auto_update = true instance_eval(&block) end |
Instance Attribute Details
#dest_state ⇒ Object (readonly)
Returns the value of attribute dest_state.
322 323 324 |
# File 'lib/hegemon.rb', line 322 def dest_state @dest_state end |
#src_state ⇒ Object (readonly)
Returns the value of attribute src_state.
322 323 324 |
# File 'lib/hegemon.rb', line 322 def src_state @src_state end |
Instance Method Details
#after(&block) ⇒ Object
354 |
# File 'lib/hegemon.rb', line 354 def after (&block); @afters << block if block; end |
#auto_update(val = :just_ask) ⇒ Object
Get or set the @auto_update value
357 358 359 360 361 |
# File 'lib/hegemon.rb', line 357 def auto_update(val=:just_ask) (val==:just_ask) ? (@auto_update) : (@auto_update = (true and val)) end |
#before(&block) ⇒ Object
353 |
# File 'lib/hegemon.rb', line 353 def before (&block); @befores << block if block; end |
#condition(&block) ⇒ Object
350 |
# File 'lib/hegemon.rb', line 350 def condition (&block); @conditions << block if block; end |
#ready?(*flags) ⇒ Boolean
363 364 365 366 367 368 369 370 371 |
# File 'lib/hegemon.rb', line 363 def ready?(*flags) return false unless @object.state==@src_state return false if @progress result = (procs_and @requirements) return result if (flags.include? :force) return result && ((procs_or @sufficients) or (procs_and @conditions)) end |
#requirement(&block) ⇒ Object
352 |
# File 'lib/hegemon.rb', line 352 def requirement(&block); @requirements << block if block; end |
#sufficient(&block) ⇒ Object
351 |
# File 'lib/hegemon.rb', line 351 def sufficient (&block); @sufficients << block if block; end |
#try(*flags) ⇒ Object
373 374 375 376 377 |
# File 'lib/hegemon.rb', line 373 def try(*flags) (ready?(*flags)) ? (perform; true) : (false) end |