YAML bug in Og 0.27.0
January 29th, 2006 | by mj |Dumping an Og::Collection using to_yaml or YAML::dump results in a hard to track error: TypeError: can't dump anonymous class Class. This is because Collection has an instance variable which contains a literal Class. This patch fixes the problem, by storing the member_class as a String, and converting as necessary in the code.
--- new_collection.rb 2006-01-30 10:06:47.000000000 +1100
+++ collection.rb 2006-01-30 10:06:53.000000000 +1100
@@ -55,7 +55,7 @@
remove_proc = nil, find_proc = nil,
count_proc = nil, find_options = {})
@owner = owner
- @member_class = member_class.to_s
+ @member_class = member_class
@insert_proc = insert_proc
@remove_proc = remove_proc
@find_proc = find_proc
@@ -217,8 +217,7 @@
# Allows to perform a scoped query.
def find(options = {})
- klass = const_get(@member_class.to_sym)
- klass.with_scope(options) do
+ @member_class.with_scope(options) do
return @owner.send(@find_proc, @find_options)
end
end
@@ -238,8 +237,7 @@
def method_missing(symbol, *args, &block)
load_members
- klass = const_get(@member_class.to_sym)
- if klass.instance_methods.include? symbol.to_s
+ if @member_class.instance_methods.include? symbol.to_s
@members.inject([]) { |a, x| a << x.send(symbol) }.flatten
else
@members.send(symbol, *args, &block)