Permalink
Browse files

Changed the way the Calculations module is patched

  • Loading branch information...
1 parent 54ceb78 commit 75d54ebbfb72215fba2e493ab97ba5d36f453226 @datwright datwright committed Apr 24, 2012
Showing with 32 additions and 24 deletions.
  1. +1 −1 lib/multipluck.rb
  2. +0 −23 lib/multipluck/calculations.rb
  3. +31 −0 lib/multipluck/pluck.rb
View
@@ -1,4 +1,4 @@
-require "multipluck/calculations"
+require "multipluck/pluck"
module Multipluck
end
@@ -1,23 +0,0 @@
-module ActiveRecord
- module Calculations
- # Preserve the original pluck functionality
- alias single_column_pluck pluck
-
- def pluck(column_name_or_array)
- return single_column_pluck(column_name_or_array) unless column_name_or_array.instance_of?(Array)
-
- column_names = column_name_or_array.map(&:to_s)
-
- # Array of rows
- rows = klass.connection.select_all(select(column_names).arel)
-
- # Row is a hash of of 'column_name' => value
- rows.map! do |row|
- attrs = klass.initialize_attributes(row)
- column_names.map do |col_name|
- klass.type_cast_attribute(col_name, attrs)
- end
- end
- end
- end
-end
View
@@ -0,0 +1,31 @@
+
+module Multipluck
+ module Pluck
+ extend ActiveSupport::Concern
+
+ included do
+ # Preserve the original pluck functionality
+ alias_method :single_column_pluck, :pluck
+
+ def pluck(column_name_or_array)
+ return single_column_pluck(column_name_or_array) unless column_name_or_array.instance_of?(Array)
+
+ column_names = column_name_or_array.map(&:to_s)
+
+ # Array of rows
+ rows = klass.connection.select_all(select(column_names).arel)
+
+ # Row is a hash of of 'column_name' => value
+ rows.map! do |row|
+ attrs = klass.initialize_attributes(row)
+ column_names.map do |col_name|
+ klass.type_cast_attribute(col_name, attrs)
+ end
+ end
+ end
+
+ end
+ end
+end
+
+ActiveRecord::Calculations.send(:include, Multipluck::Pluck)

0 comments on commit 75d54eb

Please sign in to comment.