You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I use Mongomatic classes within submodules, observers don't seem to work. With the example below, if I try to do a Bob::Person.new, I receive a NameError: wrong constant name Bob::MyCustomCallbacks error. This appears to be a result of the Module.const_defined? call in observable.rb.
module Bob
class MyCustomCallbacks < Mongomatic::Observer
def after_initialize
puts "after insert or update"
end
end
class Person < Mongomatic::Base
include Mongomatic::Observable
observer MyCustomCallbacks
end
end
The text was updated successfully, but these errors were encountered:
I can get to looking at this later this week hopefully. If you have time before then, if you could spike out a test that I can run against to ensure I fix this properly.
Observers also seem to fail in 1.8.7 entirely. I just ran the tests. @dacort what vsn of Ruby were you running. I also may have some time to recreate this weekend. @jsmestad have you started working on this already?
This commit specifically fixes the observer issues in 1.8.7 but does not solve the issue above. The fix was to use Object.const_defined? instead of Module.const_defined? which works slightly differently in 1.8.7: 63860b2
This commit fixes both problems but I'm not sure I like the use of eval("#{observer}") so let me know what you think. An alternative could be to detect observers nested in modules and properly call THE::PARENT::MODULE.const_defined? falling back to Object.const_defined? when the observer is not contained in a module: 4fba79d
If I use Mongomatic classes within submodules, observers don't seem to work. With the example below, if I try to do a Bob::Person.new, I receive a
NameError: wrong constant name Bob::MyCustomCallbacks
error. This appears to be a result of the Module.const_defined? call in observable.rb.The text was updated successfully, but these errors were encountered: