Skip to content

Commit 3770b4e

Browse files
author
Ivan Evgrafov
authored
Merge pull request #16 from rssdev10/master
Dir::Tmpname.make_tmpname replaced by own method
2 parents 8c82c24 + f1c3905 commit 3770b4e

File tree

5 files changed

+14
-3
lines changed

5 files changed

+14
-3
lines changed

lib/gnuplotrb.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ def require_if_available(name)
1919
require 'gnuplotrb/external_classes/string'
2020
require 'gnuplotrb/external_classes/array'
2121
require 'gnuplotrb/external_classes/daru'
22+
require 'gnuplotrb/external_classes/dir'
23+
2224

2325
require 'gnuplotrb/version'
2426
require 'gnuplotrb/staff/settings'

lib/gnuplotrb/animation.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def plot(path = nil, **options)
5858
plot_opts.merge(term: ['gif', anim_opts])
5959
end.to_h
6060
need_output = plot_options[:output].nil?
61-
plot_options[:output] = Dir::Tmpname.make_tmpname('anim', 0) if need_output
61+
plot_options[:output] = Dir.gnuplot_tmpname('anim') if need_output
6262
terminal = Terminal.new
6363
multiplot(terminal, plot_options)
6464
# guaranteed wait for plotting to finish

lib/gnuplotrb/external_classes/dir.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
##
2+
# Utility methods for GnuplotRB.
3+
class Dir
4+
# @return temporary file name
5+
def self.gnuplot_tmpname(name)
6+
t = Time.now.strftime('%Y%m%d')
7+
"#{Dir.tmpdir}/gnuplotrb-#{name}-#{t}-#{$PID}-#{rand(0x100000000).to_s(36)}"
8+
end
9+
end

lib/gnuplotrb/mixins/plottable.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def to_specific_term(terminal, path = nil, **options)
110110
if path
111111
result = plot(term: [terminal, options], output: path)
112112
else
113-
path = Dir::Tmpname.make_tmpname(terminal, 0)
113+
path = Dir.gnuplot_tmpname(terminal)
114114
plot(term: [terminal, options], output: path)
115115
result = File.binread(path)
116116
File.delete(path)

lib/gnuplotrb/staff/datablock.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def initialize(data, stored_in_file = false)
1313
@stored_in_file = stored_in_file
1414
data_str = data.to_gnuplot_points
1515
if @stored_in_file
16-
@file_name = Dir::Tmpname.make_tmpname('tmp_data', 0)
16+
@file_name = Dir.gnuplot_tmpname('tmp_data')
1717
File.write(@file_name, data_str)
1818
name = File.join(Dir.pwd, @file_name)
1919
ObjectSpace.define_finalizer(self, proc { File.delete(name) })

0 commit comments

Comments
 (0)