Module: Ruber::Activable
- Included in:
- Document, Project, World::Environment
- Defined in:
- lib/ruber/utils.rb
Overview
Module for objects which can be activated and disactivated. It provides methods for inquiring the active state and to change it. If the object is a @Qt::Object@, and has an @activated()@ and a @deactivated@ signals, they will be emitted when the state change. If the object is not a @Qt::Object@, or doesn’t have those signals, everything else will still work (in the rest of the documentation, every time emitting a signal is mentioned, it’s understood that the signal won’t be emitted if it doesn’t exist).
Classes including this module may customize what is done when the state change by overriding the #do_activation and #do_deactivation methods.
Classes mixing-in this module should initialize an instance variable called @active
. If they don’t, one initialized to nil will be created the first time it’ll be needed (possibly with a warning).
Instance Method Summary collapse
-
#activate ⇒ nil
Makes the object active If previously the object was inactive, emits the @activated@ signal.
-
#active=(val) ⇒ Object
Enables or disables the object.
-
#active? ⇒ Boolean
Whether the object is active or not.
-
#deactivate ⇒ nil
Makes the object inactive If previously the object was active, emits the @deactivated@ signal.
Instance Method Details
#activate ⇒ nil
Makes the object active
If previously the object was inactive, emits the @activated@ signal.
372 373 374 375 |
# File 'lib/ruber/utils.rb', line 372 def activate self.active = true nil end |
#active=(val) ⇒ Object
Enables or disables the object
If the state of the object changes, the #do_activation or #do_deactivation methods are called. This happens after the state has been changed.
object is a true value, the object will be activated, otherwise it will be deactivated
387 388 389 390 391 392 393 |
# File 'lib/ruber/utils.rb', line 387 def active= val old = @active @active = val.to_bool if old != @active @active ? do_activation : do_deactivation end end |
#active? ⇒ Boolean
Returns whether the object is active or not.
351 352 353 |
# File 'lib/ruber/utils.rb', line 351 def active? @active end |
#deactivate ⇒ nil
Makes the object inactive
If previously the object was active, emits the @deactivated@ signal
361 362 363 364 |
# File 'lib/ruber/utils.rb', line 361 def deactivate self.active = false nil end |