#-- # Copyright (C) 2007 Dimitrij Denissenko # Please read LICENSE document for more information. #++ # has_and_belongs_to_many should not store duplicates when used in :uniq => true mode ActiveRecord::Associations::AssociationCollection.class_eval do def <<(*records) result = true load_target if @owner.new_record? @owner.transaction do flatten_deeper(records).each do |record| raise_on_type_mismatch(record) unless (@reflection.options[:uniq] and @target.include?(record)) callback(:before_add, record) result &&= insert_record(record) unless @owner.new_record? @target << record callback(:after_add, record) end end end result && self end end # Fix DISTINCT select in combination with extended SQL statements in ORDER BY clauses in the PostgreSQL ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.class_eval do def distinct(columns, order_by) return "DISTINCT #{columns}" if order_by.blank? # Construct a clean list of column names from the ORDER BY clause, removing # any ASC/DESC modifiers order_columns = order_by.split(',').map { |s| s.gsub(/\b(DE|A)SC\s*$/i, '').strip }.reject(&:blank?) order_columns = order_columns.zip((0...order_columns.size).to_a).map { |s,i| "#{s} AS alias_#{i}" } # return a DISTINCT ON() clause that's distinct on the columns we want but includes # all the required columns for the ORDER BY to work properly sql = "DISTINCT ON (#{columns}) #{columns}, " sql << order_columns * ', ' end end if ActiveRecord::ConnectionAdapters.const_defined?('PostgreSQLAdapter') # Include text attachments TMail::Mail.class_eval do def attachment?(part) (part['content-disposition'] && !part['content-disposition']['filename'].blank?) || part.header['content-type'].main_type != "text" end end if ENABLE_SUBVERSION module Svn @@dirty_runs = 0 def self.sweep_garbage! GC.start if (@@dirty_runs = (@@dirty_runs + 1) % 10).zero? end module Core class Stream def close_with_manual_garbage_collection close_without_manual_garbage_collection Svn.sweep_garbage! end alias_method_chain :close, :manual_garbage_collection end end module Fs class FileSystem def root_with_manual_garbage_collection(rev=nil) Svn.sweep_garbage! root_without_manual_garbage_collection(rev) end #alias_method_chain :root, :manual_garbage_collection end class Root def copied_from_with_manual_garbage_collection(*args) Svn.sweep_garbage! copied_from_without_manual_garbage_collection(*args) end alias_method_chain :copied_from, :manual_garbage_collection end end end end