Class: TinyConveyor::Parcel

Inherits:
Object
  • Object
show all
Defined in:
lib/tiny_conveyor/parcel.rb

Overview

Encapsulate an action to run in a separated thread

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, description, action) ⇒ Parcel

Returns newly created parcel.

Parameters:

  • name (string)

    name of the task

  • description (string)

    small description of the task

  • action (Proc)

    action to run in separate thread



13
14
15
16
17
18
19
# File 'lib/tiny_conveyor/parcel.rb', line 13

def initialize(name, description, action)
  @name = name
  @description = description
  @action = action
  @state = :pending
  @uuid = SecureRandom.uuid
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



7
8
9
# File 'lib/tiny_conveyor/parcel.rb', line 7

def description
  @description
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/tiny_conveyor/parcel.rb', line 7

def name
  @name
end

#stateObject (readonly)

Returns the value of attribute state.



7
8
9
# File 'lib/tiny_conveyor/parcel.rb', line 7

def state
  @state
end

#uuidObject (readonly)

Returns the value of attribute uuid.



7
8
9
# File 'lib/tiny_conveyor/parcel.rb', line 7

def uuid
  @uuid
end

Instance Method Details

#executeObject



21
22
23
24
# File 'lib/tiny_conveyor/parcel.rb', line 21

def execute
  @state = :running
  @action.call
end

#running?boolean

Returns true if the parcel is executed, false otherwhise.

Returns:

  • (boolean)

    true if the parcel is executed, false otherwhise



27
28
29
# File 'lib/tiny_conveyor/parcel.rb', line 27

def running?
  @state == :running
end