Class: PStore

Inherits:
Object
  • Object
show all
Defined in:
lib/tdiary/compatible.rb

Instance Method Summary collapse

Instance Method Details

#compatible_transaction_originalObject



11
# File 'lib/tdiary/compatible.rb', line 11

alias compatible_transaction_original transaction

#transaction(*args, &block) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/tdiary/compatible.rb', line 12

def transaction(*args, &block)
	begin
		compatible_transaction_original(*args, &block)
	rescue PStoreRuby18Exception
		# first loaded the pstore file (it's created by Ruby-1.8)
		# force convert ASCII_8BIT pstore data to UTF_8
		file = open_and_lock_file(@filename, false)
		table = Marshal::load(file, proc {|obj|
			if obj.respond_to?('force_encoding') && obj.encoding == Encoding::ASCII_8BIT
				obj.force_encoding('UTF-8')
			end
			obj
		})
		table[:__ruby_version] = RUBY_VERSION
		if on_windows?
			save_data_with_fast_strategy(Marshal::dump(table), file)
		else
			save_data_with_atomic_file_rename_strategy(Marshal::dump(table), file)
		end
		retry
	end
end