Class: YDD::SerializationHelper::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/ydd/serialization_helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(helper) ⇒ Base

Returns a new instance of Base.



7
8
9
10
11
# File 'lib/ydd/serialization_helper.rb', line 7

def initialize(helper)
  @dumper    = helper.dumper
  @loader    = helper.loader
  @extension = helper.extension
end

Instance Attribute Details

#extensionObject (readonly)

Returns the value of attribute extension.



5
6
7
# File 'lib/ydd/serialization_helper.rb', line 5

def extension
  @extension
end

Instance Method Details

#disable_loggerObject



25
26
27
28
# File 'lib/ydd/serialization_helper.rb', line 25

def disable_logger
  @@old_logger = ActiveRecord::Base.logger
  ActiveRecord::Base.logger = nil
end

#dump(filename) ⇒ Object



13
14
15
16
17
# File 'lib/ydd/serialization_helper.rb', line 13

def dump(filename)
  disable_logger
  @dumper.dump(File.new(filename, "w"))
  reenable_logger
end

#load(filename, truncate = true) ⇒ Object



19
20
21
22
23
# File 'lib/ydd/serialization_helper.rb', line 19

def load(filename, truncate = true)
  disable_logger
  @loader.load(File.new(filename, "r"), truncate)
  reenable_logger
end

#reenable_loggerObject



30
31
32
# File 'lib/ydd/serialization_helper.rb', line 30

def reenable_logger
  ActiveRecord::Base.logger = @@old_logger
end