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)
- 
  
    
      - (nil) activate 
    
    
  
  
  
  
  
  
  
  
    Makes the object active. 
- 
  
    
      - (Object) active(val) 
    
    
  
  
  
  
  
  
  
  
    Enables or disables the object. 
- 
  
    
      - (Boolean) active? 
    
    
  
  
  
  
  
  
  
  
    Whether the object is active or not. 
- 
  
    
      - (nil) deactivate 
    
    
  
  
  
  
  
  
  
  
    Makes the object inactive. 
- 
  
    
      - (nil) do_activation 
    
    
  
  
  
  
  private
  
  
  
    Method called after the state changes from inactive to active. 
- 
  
    
      - (nil) do_deactivation 
    
    
  
  
  
  
  private
  
  
  
    Method called after the state changes from active to inactive. 
Instance Method Details
- (nil) activate
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 | 
- (Object) active=(val)
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 | 
- (Boolean) active?
Whether the object is active or not
| 351 352 353 | # File 'lib/ruber/utils.rb', line 351 def active? @active end | 
- (nil) deactivate
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 | 
- (nil) do_activation (private)
Method called after the state changes from inactive to active
It emits the activated signal, if the class including the module has the signal.
Including classes can override this method to perform other actions every time the object becomes active. In this case, they should call super if they want the signal to be emitted
| 421 422 423 | # File 'lib/ruber/utils.rb', line 421 def do_activation emit activated rescue NameError end | 
- (nil) do_deactivation (private)
Method called after the state changes from active to inactive
It emits the deactivated signal, if the class including the module has the signal.
Including classes can override this method to perform other actions every time the object becomes inactive. In this case, they should call super if they want the signal to be emitted
| 407 408 409 | # File 'lib/ruber/utils.rb', line 407 def do_deactivation emit deactivated rescue NameError end |