Permalink
Browse files

Allow others to hook to const_missing, too.

  • Loading branch information...
1 parent 4dd6ea6 commit 82c8c2e67d00c9ba7e3def272df6d1ab13e9c803 @djanowski djanowski committed Jul 2, 2010
Showing with 39 additions and 4 deletions.
  1. +10 −3 Rakefile
  2. +9 −1 lib/ohm.rb
  3. +20 −0 test/wrapper_test.rb
View
@@ -24,7 +24,14 @@ task :stop do
end
end
-Rake::TestTask.new(:test) do |t|
- t.pattern = 'test/**/*_test.rb'
- t.ruby_opts = ["-rubygems"] if RUBY_VERSION < "1.9"
+task :test do
+ Dir["test/**/*_test.rb"].each do |file|
+ fork do
+ load file
+ end
+
+ Process.wait
+
+ exit $?.exitstatus unless $?.success?
+ end
end
View
@@ -767,7 +767,15 @@ def write_remote(att, value)
end
def self.const_missing(name)
- Wrapper.new(name) { const_get(name) }
+ wrapper = Wrapper.new(name) { const_get(name) }
+
+ # Allow others to hook to const_missing.
+ begin
+ super(name)
+ rescue NameError
+ end
+
+ wrapper
end
private
View
@@ -0,0 +1,20 @@
+require File.expand_path(File.join(File.dirname(__FILE__), "test_helper"))
+
+$missing_constants = []
+
+class Object
+ def self.const_missing(name)
+ $missing_constants << name
+ super(name)
+ end
+end
+
+class Foo < Ohm::Model
+ set :bars, Bar
+end
+
+class Tests < Test::Unit::TestCase
+ test "calls other const_missing hooks" do
+ assert_equal [:Bar], $missing_constants
+ end
+end

0 comments on commit 82c8c2e

Please sign in to comment.