Permalink
Browse files

Better methods to know what channels will be used on Object

  • Loading branch information...
1 parent 6f1eac2 commit 00a38d7e0ef5ccddbb7b486510040bb5d8e7b808 @krakatoa krakatoa committed Sep 25, 2012
Showing with 42 additions and 8 deletions.
  1. +3 −3 lib/protocol/action_specification.rb
  2. +15 −3 lib/protocol/object_specification.rb
  3. +2 −2 spec/mock/protocol.ini
  4. +22 −0 spec/protocol_spec.rb
@@ -28,15 +28,15 @@ def read_by=(read_by)
end
def uses_box
- @uses_box || object_specification.uses_box
+ @uses_box || object_specification.has_default?(:box)
end
def uses_mailbox
- @uses_mailbox || object_specification.uses_mailbox
+ @uses_mailbox || object_specification.has_default?(:mailbox)
end
def uses_board
- @uses_board || object_specification.uses_board
+ @uses_board || object_specification.has_default?(:board)
end
def serialize
@@ -10,6 +10,8 @@ def initialize(class_name)
@role = :both # both receiver emitter
@action_specifications = []
+
+ @uses = :box
super()
end
@@ -19,17 +21,27 @@ def role=(role)
raise "invalid role!" if ![:both, :receiver, :emitter].include?(role)
@role = role
end
+
+ def default_uses=(uses)
+ uses = uses.to_sym
+ raise "invalid uses type!" if ![:box, :board, :mailbox].include?(uses)
+ @uses = uses
+ end
+
+ def has_default?(uses)
+ @uses == uses
+ end
def uses_box
- @uses_box || false
+ @action_specifications.select(&:uses_box).size > 0
end
def uses_mailbox
- @uses_mailbox || false
+ @action_specifications.select(&:uses_mailbox).size > 0
end
def uses_board
- @uses_board || false
+ @action_specifications.select(&:uses_board).size > 0
end
def serialize
View
@@ -1,14 +1,14 @@
[engine]
role = receiver
- uses_box = true
- uses_board = true
+ default_uses = mailbox
serialize = msgpack
compression = gzip
; cp = 1425
[engine#create_vps]
from = core
respond_to = class+object
+ uses_board = true
serialize = none
read_by = core
View
@@ -6,6 +6,7 @@
end
describe "#parse" do
+=begin
it "should return a valid SpecificationSet" do
@loader = Cucub::Protocol::Loader.instance
@loader.set_path(@filepath + "/mock/protocol.ini")
@@ -21,6 +22,27 @@
#puts obj_spec.inspect
}
end
+=end
+
+ it "should return a valid SpecificationSet" do
+ @loader = Cucub::Protocol::Loader.instance
+ @loader.set_path(@filepath + "/mock/protocol.ini")
+ specification_set = @loader.parse
+ specification_set.object_specifications.each {|obj_spec|
+ puts "object: #{obj_spec.class_name}"
+ puts "uses box: #{obj_spec.uses_box}"
+ puts "uses mailbox: #{obj_spec.uses_mailbox}"
+ puts "uses board: #{obj_spec.uses_board}"
+ obj_spec.action_specifications.each {|act|
+ puts "\taction: #{act.action_name}"
+ puts "\tuses box: #{act.uses_box}"
+ puts "\tuses mailbox: #{act.uses_mailbox}"
+ puts "\tuses board: #{act.uses_board}"
+ }
+ puts "\n"
+ #puts obj_spec.inspect
+ }
+ end
end
=begin

0 comments on commit 00a38d7

Please sign in to comment.