Commit 0ccf1b38 authored by Ohad Dahan's avatar Ohad Dahan

Update version, set_override_pluck , protect against :orig_pluck not defined

parent 1540a935
PATH
remote: .
specs:
nativepluck (0.1.2)
nativepluck (0.1.3)
pg
rails (>= 4.2)
......
......@@ -84,26 +84,29 @@ module Nativepluck
module ::ActiveRecord
module Calculations
alias_method :orig_pluck, :pluck
include Nativepluck::InstanceMethods
end
module Querying
alias_method :orig_pluck, :pluck
delegate :nativepluck, to: :all
end
end
def self.set_override_pluck(selection)
raise ArgumentError.new("#{__method__}:: Input should be true/false and not #{selection.class}") unless (selection.is_a?(TrueClass) || selection.is_a?(FalseClass))
Nativepluck.override_pluck = selection
if selection
::ActiveRecord::Calculations.class_eval do
alias_method :orig_pluck, :pluck
alias_method :pluck, :nativepluck
end
::ActiveRecord::Querying.class_eval do
alias_method :orig_pluck, :pluck
alias_method :pluck, :nativepluck
end
else
unless Nativepluck.override_pluck
raise ArgumentError.new("#{__method__}:: Cannot turn off pluck overriding since it wasn't set yet")
end
::ActiveRecord::Calculations.class_eval do
alias_method :pluck, :orig_pluck
end
......@@ -111,5 +114,6 @@ module Nativepluck
alias_method :pluck, :orig_pluck
end
end
Nativepluck.override_pluck = selection
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment