lib/serialization_helper.rb in yaml_db-0.2.3 vs lib/serialization_helper.rb in yaml_db-0.3.0
- old
+ new
@@ -2,12 +2,12 @@
class Base
attr_reader :extension
def initialize(helper)
- @dumper = helper.dumper
- @loader = helper.loader
+ @dumper = helper.dumper
+ @loader = helper.loader
@extension = helper.extension
end
def dump(filename)
disable_logger
@@ -20,11 +20,11 @@
tables = @dumper.tables
tables.each do |table|
io = File.new "#{dirname}/#{table}.#{@extension}", "w"
@dumper.before_table(io, table)
@dumper.dump_table io, table
- @dumper.after_table(io, table)
+ @dumper.after_table(io, table)
end
end
def load(filename, truncate = true)
disable_logger
@@ -36,11 +36,11 @@
Dir.entries(dirname).each do |filename|
if filename =~ /^[.]/
next
end
@loader.load(File.new("#{dirname}/#{filename}", "r"), truncate)
- end
+ end
end
def disable_logger
@@old_logger = ActiveRecord::Base.logger
ActiveRecord::Base.logger = nil
@@ -48,11 +48,11 @@
def reenable_logger
ActiveRecord::Base.logger = @@old_logger
end
end
-
+
class Load
def self.load(io, truncate = true)
ActiveRecord::Base.connection.transaction do
load_documents(io, truncate)
end
@@ -90,13 +90,12 @@
def self.reset_pk_sequence!(table_name)
if ActiveRecord::Base.connection.respond_to?(:reset_pk_sequence!)
ActiveRecord::Base.connection.reset_pk_sequence!(table_name)
end
- end
+ end
-
end
module Utils
def self.unhash(hash, keys)
@@ -179,11 +178,11 @@
id = table_column_names(table).first
boolean_columns = SerializationHelper::Utils.boolean_columns(table)
quoted_table_name = SerializationHelper::Utils.quote_table(table)
(0..pages).to_a.each do |page|
- query = Arel::Table.new(table).order(id).skip(records_per_page*page).take(records_per_page).project(Arel.sql('*'))
- records = ActiveRecord::Base.connection.select_all(query)
+ query = Arel::Table.new(table, ActiveRecord::Base).order(id).skip(records_per_page*page).take(records_per_page).project(Arel.sql('*'))
+ records = ActiveRecord::Base.connection.select_all(query.to_sql)
records = SerializationHelper::Utils.convert_booleans(records, boolean_columns)
yield records
end
end