Module: Ruber::Activable
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 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.
369 370 371 372 |
# File 'lib/ruber/utils.rb', line 369 def activate self.active = true nil end |
#active=(val) ⇒ Object
Enables or disables the object
If the state of the object changes, the @activated@ or @deactivated@ signal is emitted.
object is a true value, the object will be activated, otherwise it will be deactivated
384 385 386 387 388 389 390 |
# File 'lib/ruber/utils.rb', line 384 def active= val old = @active @active = val.to_bool if old != @active emit(@active ? activated : deactivated) rescue NameError end end |
#active? ⇒ Boolean
Returns whether the object is active or not.
348 349 350 |
# File 'lib/ruber/utils.rb', line 348 def active? @active end |
#deactivate ⇒ nil
Makes the object inactive
If previously the object was active, emits the @deactivated@ signal
358 359 360 361 |
# File 'lib/ruber/utils.rb', line 358 def deactivate self.active = false nil end |