lib/direction.rb in direction-0.0.2 vs lib/direction.rb in direction-0.0.3
- old
+ new
@@ -5,11 +5,12 @@
# message forwarding.
#
# class SomeClass
# extend Direction
#
-# command [:name, :id] => :collaborator, [:color, :type] => :@partner
+# command [:print_details, :setup_things] => :collaborator
+# query [:name, :id] => :collaborator, :type => :@partner
# end
#
# This will define methods on instances that forward to the
# provided receiver while enforcing encapsulation of the
# relationship between objects.
@@ -20,9 +21,23 @@
Array(key).map do |command_name|
method_defs.unshift %{
def #{command_name}(*args, &block)
#{value}.__send__(:#{command_name}, *args, &block)
self
+ end
+ }
+ end
+ end
+ self.class_eval method_defs.join(' '), __FILE__, __LINE__
+ end
+
+ def query(options)
+ method_defs = []
+ options.each_pair do |key, value|
+ Array(key).map do |command_name|
+ method_defs.unshift %{
+ def #{command_name}(*args, &block)
+ #{value}.__send__(:#{command_name}, *args, &block)
end
}
end
end
self.class_eval method_defs.join(' '), __FILE__, __LINE__