Diff
Modified: MacRuby/trunk/lib/hotcocoa/mappings.rb (804 => 805)
--- MacRuby/trunk/lib/hotcocoa/mappings.rb 2009-01-21 09:47:51 UTC (rev 804)
+++ MacRuby/trunk/lib/hotcocoa/mappings.rb 2009-01-22 16:30:36 UTC (rev 805)
@@ -34,13 +34,9 @@
if mapped_value.kind_of?(Class)
add_mapping(mapped_name, mapped_value, &block)
else
- constant = Object.full_const_get(mapped_value)
- if framework.nil? || constant
+ on_framework(framework) do
+ constant = Object.full_const_get(mapped_value)
add_mapping(mapped_name, constant, &block)
- else
- on_framework(framework) do
- add_mapping(mapped_name, constant, &block)
- end
end
end
end
@@ -57,16 +53,27 @@
end
def self.on_framework(name, &block)
- (frameworks[name.to_s.downcase] ||= []) << block
+ name = name.nil? ? nil : name.to_s.downcase
+ if name.nil? or loaded_frameworks.include?(name)
+ block.call
+ else
+ (frameworks[name] ||= []) << block
+ end
end
def self.frameworks
@frameworks ||= {}
end
+ def self.loaded_frameworks
+ @loaded_frameworks ||= Set.new
+ end
+
def self.framework_loaded(name)
- if frameworks[name.to_s.downcase]
- frameworks[name.to_s.downcase].each do |mapper|
+ name = name.to_s.downcase
+ loaded_frameworks << name
+ if frameworks[name]
+ frameworks[name].each do |mapper|
mapper.call
end
end
Modified: MacRuby/trunk/lib/hotcocoa/object_ext.rb (804 => 805)
--- MacRuby/trunk/lib/hotcocoa/object_ext.rb 2009-01-21 09:47:51 UTC (rev 804)
+++ MacRuby/trunk/lib/hotcocoa/object_ext.rb 2009-01-22 16:30:36 UTC (rev 805)
@@ -12,8 +12,8 @@
list.each do |x|
# This is required because const_get tries to look for constants in the
# ancestor chain, but we only want constants that are HERE
- obj = obj.const_defined?(x) ? obj.const_get(x) : nil
- return false unless obj
+ raise NameError, "uninitialized constant #{self.name}::#{name}" unless obj.const_defined?(x)
+ obj = obj.const_get(x)
end
obj
end
Modified: MacRuby/trunk/test-macruby/cases/hotcocoa/mappings_test.rb (804 => 805)
--- MacRuby/trunk/test-macruby/cases/hotcocoa/mappings_test.rb 2009-01-21 09:47:51 UTC (rev 804)
+++ MacRuby/trunk/test-macruby/cases/hotcocoa/mappings_test.rb 2009-01-22 16:30:36 UTC (rev 805)
@@ -62,6 +62,7 @@
it "should create a mapping to a class in a framework with #map" do
mock = Mock.new
+ eval "class ::ClassInTheFrameWork; end"
Mappings.map(:klass => 'ClassInTheFrameWork', :framework => 'TheFramework') do
mock.call!
end
@@ -89,7 +90,7 @@
it "should resolve a constant when a framework, that's registered with #map, is loaded" do
assert_nothing_raised(NameError) do
- Mappings.map(:klass => 'ClassFromFramework', :framework => 'TheFramework') {}
+ Mappings.map(:klass => 'ClassFromFramework', :framework => 'TheFrameworkAfterLoad') {}
end
# The mapping should not yet exist
@@ -97,7 +98,7 @@
# now we actually define the class and fake the loading of the framework
eval "class ::ClassFromFramework; end"
- Mappings.framework_loaded('TheFramework')
+ Mappings.framework_loaded('TheFrameworkAfterLoad')
# It should be loaded by now
assert_equal ClassFromFramework, Mappings.mappings[:klass].control_class