[macruby-changes] [816] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Fri Feb 27 04:54:37 PST 2009


Revision: 816
          http://trac.macosforge.org/projects/ruby/changeset/816
Author:   eloy.de.enige at gmail.com
Date:     2009-02-27 04:54:37 -0800 (Fri, 27 Feb 2009)
Log Message:
-----------
Make HotCocoa mapper builder methods callable on the HotCocoa module as well as on instances.

Modified Paths:
--------------
    MacRuby/trunk/lib/hotcocoa/mapper.rb
    MacRuby/trunk/test-macruby/cases/hotcocoa/mappings_test.rb

Modified: MacRuby/trunk/lib/hotcocoa/mapper.rb
===================================================================
--- MacRuby/trunk/lib/hotcocoa/mapper.rb	2009-02-27 12:44:55 UTC (rev 815)
+++ MacRuby/trunk/lib/hotcocoa/mapper.rb	2009-02-27 12:54:37 UTC (rev 816)
@@ -49,7 +49,7 @@
           Views[guid] = control if guid
           inst.customize(control)
           map.each do |key, value|
-            if control.respond_to?(key) && value == true
+            if control.respond_to?(key) and not control.respond_to?("#{key}=") and value == true
               if control.respond_to?("set#{key.to_s.capitalize}")
                 eval "control.set#{key.to_s.capitalize}(true)"
               else
@@ -71,6 +71,10 @@
           end
           control
         end
+        # make the function callable using HotCocoa.xxxx
+        HotCocoa.send(:module_function, builder_method)
+        # module_function makes the instance method private, but we want it to stay public
+        HotCocoa.send(:public, builder_method)
         self
       end
       

Modified: MacRuby/trunk/test-macruby/cases/hotcocoa/mappings_test.rb
===================================================================
--- MacRuby/trunk/test-macruby/cases/hotcocoa/mappings_test.rb	2009-02-27 12:44:55 UTC (rev 815)
+++ MacRuby/trunk/test-macruby/cases/hotcocoa/mappings_test.rb	2009-02-27 12:54:37 UTC (rev 816)
@@ -31,6 +31,12 @@
     assert Mappings.frameworks.is_a?(Hash)
   end
   
+  it "should create a mapping to a class with a module and instance method" do
+    Mappings.map(:method_name_that_does_not_already_exist => SampleClass) {}
+    assert_respond_to HotCocoa, :method_name_that_does_not_already_exist
+    assert_respond_to HotCocoa.new, :method_name_that_does_not_already_exist
+  end
+  
   it "should create a mapping to a class with a Class instance given to #map" do
     Mappings.map(:klass => SampleClass) {}
     assert_equal SampleClass, Mappings.mappings[:klass].control_class
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090227/86eb292e/attachment.html>


More information about the macruby-changes mailing list