lib/better_ar/calculations.rb in better_ar-0.1.1 vs lib/better_ar/calculations.rb in better_ar-0.2.0

- old
+ new

@@ -11,18 +11,27 @@ # if the key :conditions is present it will fall back to legacy # # @param [Hash] # Optional follows same convention as {#all} # @return [Integer] - def count(opts = {}, extra = {}) - if opts.nil? || opts.empty? - super(nil, extra) - elsif opts.key?(:conditions) - super(opts, extra) + def count(column_name = nil, count_options = {}) + if column_name.is_a?(Hash) + count_options = column_name + column_name = nil + end + + if count_options.empty? + super + elsif count_options.key?(:conditions) + super(column_name, count_options) else - all(opts).count + all(count_options).count end end end end -ActiveRecord::Relation.send(:include, BetterAr::Calculations) +ActiveSupport.on_load(:active_record) do + class << ActiveRecord::Base + prepend BetterAr::Calculations + end +end