summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoro <o@immerda.ch>2011-06-27 10:06:55 +0200
committero <o@immerda.ch>2011-06-27 10:06:55 +0200
commitb92ce2ee90910da67a4e040312f184f65a020282 (patch)
treeaf7e6ad31d0d8e8d747dcfe5dd1dc6b7e6f4bcec
parent9ad4dd3a722a0afdf6271a6ee90ce681ee644a38 (diff)
fixed some problems with tagged subclasses
-rw-r--r--lib/fpg/_helpers/class.rb8
-rw-r--r--lib/fpg/_helpers/tagged_subclasses.rb2
-rw-r--r--lib/fpg/parse/packet.rb4
3 files changed, 10 insertions, 4 deletions
diff --git a/lib/fpg/_helpers/class.rb b/lib/fpg/_helpers/class.rb
index b952540..f07672c 100644
--- a/lib/fpg/_helpers/class.rb
+++ b/lib/fpg/_helpers/class.rb
@@ -1,5 +1,11 @@
class Class
def subclasses
- ObjectSpace.each_object(Class).select { |klass| klass < self }
+ subclasses = ObjectSpace.each_object(Class).select { |klass| klass < self }
+ end
+ def subclasses_in_submodule
+ #select subclasses in the same submodule
+ classes = subclasses
+ submodule_name = self.to_s.split("::")[0..1]
+ classes.reject{ |klass| submodule_name != klass.to_s.split("::")[0..1] }
end
end
diff --git a/lib/fpg/_helpers/tagged_subclasses.rb b/lib/fpg/_helpers/tagged_subclasses.rb
index fb9edf0..0fce1b7 100644
--- a/lib/fpg/_helpers/tagged_subclasses.rb
+++ b/lib/fpg/_helpers/tagged_subclasses.rb
@@ -5,7 +5,7 @@ module FPG
end
module FindSubclasses
def with_tag(tag)
- klass = subclasses.detect{ |klass| klass.tag == tag }
+ klass = subclasses_in_submodule.detect{ |klass| klass.tag == tag }
raise "did not find a subclass for tag: #{tag}" if klass.nil?
klass.new
end
diff --git a/lib/fpg/parse/packet.rb b/lib/fpg/parse/packet.rb
index f8590cd..d845437 100644
--- a/lib/fpg/parse/packet.rb
+++ b/lib/fpg/parse/packet.rb
@@ -61,7 +61,7 @@ module FPG
def parse_content
- stream.seek(partial_byte_size,IO::SEEK_CUR)
+ stream.seek(byte_size,IO::SEEK_CUR)
end
private
@@ -111,7 +111,7 @@ module FPG
include PacketParser
include TaggedSubclasses
def self.subclasses
- Packets::Packet.subclasses
+ Packets::Packet.subclasses - [self]
end
end
end