Class: SerializationHelper::Base
- Inherits:
-
Object
- Object
- SerializationHelper::Base
- Defined in:
- lib/serialization_helper.rb
Instance Attribute Summary collapse
-
#extension ⇒ Object
readonly
Returns the value of attribute extension.
Instance Method Summary collapse
- #disable_logger ⇒ Object
- #dump(filename) ⇒ Object
- #dump_to_dir(dirname) ⇒ Object
-
#initialize(helper) ⇒ Base
constructor
A new instance of Base.
- #load(filename, truncate = true) ⇒ Object
- #load_from_dir(dirname, truncate = true) ⇒ Object
- #reenable_logger ⇒ Object
Constructor Details
#initialize(helper) ⇒ Base
Returns a new instance of Base.
6 7 8 9 10 |
# File 'lib/serialization_helper.rb', line 6 def initialize(helper) @dumper = helper.dumper @loader = helper.loader @extension = helper.extension end |
Instance Attribute Details
#extension ⇒ Object (readonly)
Returns the value of attribute extension.
4 5 6 |
# File 'lib/serialization_helper.rb', line 4 def extension @extension end |
Instance Method Details
#disable_logger ⇒ Object
44 45 46 47 |
# File 'lib/serialization_helper.rb', line 44 def disable_logger @@old_logger = ActiveRecord::Base.logger ActiveRecord::Base.logger = nil end |
#dump(filename) ⇒ Object
12 13 14 15 16 |
# File 'lib/serialization_helper.rb', line 12 def dump(filename) disable_logger @dumper.dump(File.new(filename, "w")) reenable_logger end |
#dump_to_dir(dirname) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/serialization_helper.rb', line 18 def dump_to_dir(dirname) Dir.mkdir(dirname) 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) end end |
#load(filename, truncate = true) ⇒ Object
29 30 31 32 33 |
# File 'lib/serialization_helper.rb', line 29 def load(filename, truncate = true) disable_logger @loader.load(File.new(filename, "r"), truncate) reenable_logger end |
#load_from_dir(dirname, truncate = true) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/serialization_helper.rb', line 35 def load_from_dir(dirname, truncate = true) Dir.entries(dirname).each do |filename| if filename =~ /^[.]/ next end @loader.load(File.new("#{dirname}/#{filename}", "r"), truncate) end end |
#reenable_logger ⇒ Object
49 50 51 |
# File 'lib/serialization_helper.rb', line 49 def reenable_logger ActiveRecord::Base.logger = @@old_logger end |