Upgrade to Pro — share decks privately, control downloads, hide ads and more …

America's Next Top Engineer

Aaron Patterson
June 07, 2013
2.1k

America's Next Top Engineer

Presentation popularity at RedDot RubyConf

Aaron Patterson

June 07, 2013
Tweet

Transcript

  1. protected def method_missing(method, *args, &block) if Array.method_defined?(method) to_a.send(method, *args, &block)

    elsif @klass.scopes[method] merge(@klass.send(method, *args, &block)) elsif @klass.respond_to?(method) scoping { @klass.send(method, *args, &block) } elsif arel.respond_to?(method) arel.send(method, *args, &block) elsif match = DynamicFinderMatch.match(method) attributes = match.attribute_names super unless @klass.send(:all_attributes_exists?, attributes) if match.finder? find_by_attributes(match, attributes, *args) elsif match.instantiator? find_or_instantiator_by_attributes(match, attributes, *args, &block) end else super end end private def references_eager_loaded_tables? # always convert table names to downcase as in Oracle quoted table names are in uppercase joined_tables = (tables_in_string(arel.joins(arel)) + [table.name, table.table_alias]).compact.map{ |t| t.downcase }.uniq (tables_in_string(to_sql) - joined_tables).any? end