Module: Ruber::Activable

Included in:
Document, Project
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 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

Instance Method Details

#activatenil

Makes the object active

If previously the object was inactive, emits the @activated@ signal.

Returns:

  • (nil)


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

Parameters:

  • val (Object)

    whether the object should be activated or deactivated. If the

Returns:



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.

Returns:

  • (Boolean)

    whether the object is active or not



348
349
350
# File 'lib/ruber/utils.rb', line 348

def active?
  @active
end

#deactivatenil

Makes the object inactive

If previously the object was active, emits the @deactivated@ signal

Returns:

  • (nil)


358
359
360
361
# File 'lib/ruber/utils.rb', line 358

def deactivate
  self.active = false
  nil
end