lib/sugarcrm/associations/associations.rb in sugarcrm-0.9.9 vs lib/sugarcrm/associations/associations.rb in sugarcrm-0.9.10

- old
+ new

@@ -17,10 +17,17 @@ def initialize @associations = Set.new self end + # Returns the proxy methods of all the associations in the collection + def proxy_methods + @associations.inject([]) { |pm,a| + pm = pm | a.proxy_methods + } + end + # Looks up an association by object, link_field, or method. # Raises an exception if not found def find!(target) @associations.each do |a| return a if a.include? target @@ -30,29 +37,16 @@ # Looks up an association by object, link_field, or method. # Returns false if not found def find(association) begin - find! + find!(association) rescue InvalidAssociation false end end - - def inspect - self - end - - def to_s - methods = [] - @associations.each do |a| - a.methods.each do |m| - methods << m - end - end - "[#{methods.join(', ')}]" - end - + alias :include? :find + # delegate undefined methods to the @collection array # E.g. contact.cases should behave like an array and allow `length`, `size`, `each`, etc. def method_missing(method_name, *args, &block) @associations.send(method_name.to_sym, *args, &block) end \ No newline at end of file