[macruby-changes] [605] MacRuby/trunk/lib/hotcocoa
source_changes at macosforge.org
source_changes at macosforge.org
Thu Sep 18 18:17:43 PDT 2008
Revision: 605
http://trac.macosforge.org/projects/ruby/changeset/605
Author: rich at infoether.com
Date: 2008-09-18 18:17:43 -0700 (Thu, 18 Sep 2008)
Log Message:
-----------
enable delegate methods to be required before setting the delegate on the control
Modified Paths:
--------------
MacRuby/trunk/lib/hotcocoa/delegate_builder.rb
MacRuby/trunk/lib/hotcocoa/mapper.rb
Modified: MacRuby/trunk/lib/hotcocoa/delegate_builder.rb
===================================================================
--- MacRuby/trunk/lib/hotcocoa/delegate_builder.rb 2008-09-19 01:17:07 UTC (rev 604)
+++ MacRuby/trunk/lib/hotcocoa/delegate_builder.rb 2008-09-19 01:17:43 UTC (rev 605)
@@ -2,10 +2,11 @@
class DelegateBuilder
- attr_reader :control, :delegate, :method_count
+ attr_reader :control, :delegate, :method_count, :required_methods
- def initialize(control)
+ def initialize(control, required_methods)
@control = control
+ @required_methods = required_methods
@method_count = 0
@delegate = Object.new
end
@@ -15,7 +16,7 @@
increment_method_count
bind_block_to_delegate_instance_variable(block)
create_delegate_method(selector_name, parameters)
- set_delegate
+ set_delegate if required_methods.empty?
end
private
@@ -29,6 +30,7 @@
end
def create_delegate_method(selector_name, parameters)
+ required_methods.delete(selector_name)
eval %{
def delegate.#{parameterize_selector_name(selector_name)}
#{block_instance_variable}.call(#{parameter_values_for_mapping(selector_name, parameters)})
Modified: MacRuby/trunk/lib/hotcocoa/mapper.rb
===================================================================
--- MacRuby/trunk/lib/hotcocoa/mapper.rb 2008-09-19 01:17:07 UTC (rev 604)
+++ MacRuby/trunk/lib/hotcocoa/mapper.rb 2008-09-19 01:17:43 UTC (rev 605)
@@ -121,12 +121,16 @@
def delegate_module_for_control_class
return Mapper.delegate_modules[control_class] if Mapper.delegate_modules.has_key?(control_class)
delegate_module = Module.new
+ required_methods = []
inherited_delegate_methods.each do |delegate_method, mapping|
+ required_methods << delegate_method if mapping[:required]
+ end
+ inherited_delegate_methods.each do |delegate_method, mapping|
parameters = mapping[:parameters] ? ", "+mapping[:parameters].map {|param| %{"#{param}"} }.join(",") : ""
delegate_module.module_eval %{
def #{mapping[:to]}(&block)
raise "Must pass in a block to use this delegate method" unless block_given?
- @_delegate_builder ||= HotCocoa::DelegateBuilder.new(self)
+ @_delegate_builder ||= HotCocoa::DelegateBuilder.new(self, #{required_methods.inspect})
@_delegate_builder.add_delegated_method(block, "#{delegate_method}" #{parameters})
end
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macruby-changes/attachments/20080918/2aba72ca/attachment-0001.html
More information about the macruby-changes
mailing list