Class: Edoors::Door

Inherits:
Iota
  • Object
show all
Defined in:
lib/edoors/door.rb

Direct Known Subclasses

Board

Instance Attribute Summary

Attributes inherited from Iota

#name, #parent, #path, #spin, #viewer

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Iota

#hibernate!, #receive_p, #resume!, #start!, #stop!

Constructor Details

#initialize(n, p) ⇒ Door

creates a Door object from the arguments.

Parameters:

  • n (String)

    the name of this Door

  • p (Iota)

    the parent



31
32
33
34
# File 'lib/edoors/door.rb', line 31

def initialize n, p
    super n, p
    @saved = nil
end

Class Method Details

.json_create(o) ⇒ Object

creates a Door object from a JSON data

Parameters:

  • o (Hash)

    belongs to JSON parser

Raises:

  • Edoors::Exception if the json kls attribute is wrong



53
54
55
56
57
58
# File 'lib/edoors/door.rb', line 53

def self.json_create o
    raise Edoors::Exception.new "JSON #{o['kls']} != #{self.name}" if o['kls'] != self.name
    door = self.new o['name'], o['parent']
    door.resume! o
    door
end

Instance Method Details

#process_p(p) ⇒ Object

process the given particle then forward it to user code

Parameters:

  • p (Particle)

    the Particle to be processed



91
92
93
94
95
96
# File 'lib/edoors/door.rb', line 91

def process_p p
    @viewer.receive_p p if @viewer
    @saved = p
    receive_p p
    _garbage if not @saved.nil?
end

#process_sys_p(p) ⇒ Object

dead end, for now user defined Door do not have to deal with system Particle the Particle is released

Parameters:

  • p (Particle)

    the Particle to deal with



103
104
105
106
# File 'lib/edoors/door.rb', line 103

def process_sys_p p
    # nothing todo with it now
    @spin.release_p p
end

#release_p(p) ⇒ Object

release the given Particle

Parameters:

  • p (Particle)

    the Particle to be released



72
73
74
75
# File 'lib/edoors/door.rb', line 72

def release_p p
    @saved=nil if @saved==p     # particle is released, all is good
    @spin.release_p p
end

#require_p(p_kls = Edoors::Particle) ⇒ Object

require a Particle of the given class

Parameters:

  • p_kls (Class) (defaults to: Edoors::Particle)

    the class of the desired Particle



64
65
66
# File 'lib/edoors/door.rb', line 64

def require_p p_kls=Edoors::Particle
    @spin.require_p p_kls
end

#send_p(p, a = nil, d = nil) ⇒ Object

send the given Particle to the application Particle fifo

Parameters:

  • p (Particle)

    the Particle to be sent

  • a (String) (defaults to: nil)

    the post action

  • d (Iota) (defaults to: nil)

    the post destination

See Also:

  • real implementation


132
133
134
# File 'lib/edoors/door.rb', line 132

def send_p p, a=nil, d=nil
    _send p, false, a, d
end

#send_sys_p(p, a = nil, d = nil) ⇒ Object

send the given Particle to the system Particle fifo

Parameters:

  • p (Particle)

    the Particle to be sent

  • a (String) (defaults to: nil)

    the post action

  • d (Iota) (defaults to: nil)

    the post destination

See Also:

  • real implementation


144
145
146
# File 'lib/edoors/door.rb', line 144

def send_sys_p p, a=nil, d=nil
    _send p, true, a, d
end

#to_json(*a) ⇒ Object

called by JSON#generate to serialize the Door object into JSON data

Parameters:

  • a (Array)

    belongs to JSON generator



40
41
42
43
44
45
# File 'lib/edoors/door.rb', line 40

def to_json *a
    {
        'kls'   => self.class.name,
        'name'  => @name
    }.merge(hibernate!).to_json *a
end