./lib/ambition/processor.rb in ambition-0.2.0 vs ./lib/ambition/processor.rb in ambition-0.2.1
- old
+ new
@@ -1,6 +1,7 @@
require 'active_record/connection_adapters/abstract/quoting'
+require 'ambition/proc_to_ruby'
module Ambition
class Processor
include ActiveRecord::ConnectionAdapters::Quoting
@@ -27,11 +28,10 @@
return @receiver.to_s
end
def process_array(exp)
arrayed = exp.map { |m| process(m) }
- exp.clear
return arrayed.join(', ')
end
##
# Helper methods
@@ -50,21 +50,29 @@
when false, 'false'
'0'
when Regexp
"'#{value.source}'"
else
- ActiveRecord::Base.connection.quote(value)
+ if active_connection?
+ ActiveRecord::Base.connection.quote(value)
+ else
+ quote(value)
+ end
end
- rescue ActiveRecord::ConnectionNotEstablished
- quote(value)
rescue
"'#{value}'"
end
def quote_column_name(value)
- ActiveRecord::Base.connection.quote_column_name(value)
- rescue ActiveRecord::ConnectionNotEstablished
- value.to_s
+ if active_connection?
+ ActiveRecord::Base.connection.quote_column_name(value)
+ else
+ value.to_s
+ end
+ end
+
+ def active_connection?
+ ActiveRecord::Base.active_connection_name
end
def statement(*args)
@statement_instnace ||= DatabaseStatements.const_get(adapter_name).new
@statement_instnace.send(*args)