Class: LogStash::Outputs::Qingstor::TemporaryFile
- Inherits:
-
Object
- Object
- LogStash::Outputs::Qingstor::TemporaryFile
- Extended by:
- Forwardable
- Defined in:
- lib/logstash/outputs/qingstor/temporary_file.rb
Instance Attribute Summary collapse
-
#dir_path ⇒ Object
readonly
Returns the value of attribute dir_path.
-
#fd ⇒ Object
readonly
Returns the value of attribute fd.
Class Method Summary collapse
Instance Method Summary collapse
- #ctime ⇒ Object
- #delete! ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(key, fd, dir_path) ⇒ TemporaryFile
constructor
A new instance of TemporaryFile.
- #key ⇒ Object
- #key=(key) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(key, fd, dir_path) ⇒ TemporaryFile
Returns a new instance of TemporaryFile.
19 20 21 22 23 24 |
# File 'lib/logstash/outputs/qingstor/temporary_file.rb', line 19 def initialize(key, fd, dir_path) @key = key @fd = fd @dir_path = dir_path @created_at = Time.now end |
Instance Attribute Details
#dir_path ⇒ Object (readonly)
Returns the value of attribute dir_path.
17 18 19 |
# File 'lib/logstash/outputs/qingstor/temporary_file.rb', line 17 def dir_path @dir_path end |
#fd ⇒ Object (readonly)
Returns the value of attribute fd.
17 18 19 |
# File 'lib/logstash/outputs/qingstor/temporary_file.rb', line 17 def fd @fd end |
Class Method Details
.create_from_existing_file(file_path, tmp_folder) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/logstash/outputs/qingstor/temporary_file.rb', line 57 def self.create_from_existing_file(file_path, tmp_folder) key_parts = Pathname.new(file_path).relative_path_from(tmp_folder) .to_s.split(::File::SEPARATOR) TemporaryFile.new(key_parts.join('/'), ::File.open(file_path, 'r'), tmp_folder.to_s) end |
Instance Method Details
#ctime ⇒ Object
26 27 28 |
# File 'lib/logstash/outputs/qingstor/temporary_file.rb', line 26 def ctime @created_at end |
#delete! ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/logstash/outputs/qingstor/temporary_file.rb', line 44 def delete! begin @fd.close rescue IOError end FileUtils.rm_f(path) end |
#empty? ⇒ Boolean
53 54 55 |
# File 'lib/logstash/outputs/qingstor/temporary_file.rb', line 53 def empty? size.zero? end |
#key ⇒ Object
36 37 38 |
# File 'lib/logstash/outputs/qingstor/temporary_file.rb', line 36 def key @key.gsub(/^\//, '') end |
#key=(key) ⇒ Object
40 41 42 |
# File 'lib/logstash/outputs/qingstor/temporary_file.rb', line 40 def key=(key) @key = key end |
#size ⇒ Object
30 31 32 33 34 |
# File 'lib/logstash/outputs/qingstor/temporary_file.rb', line 30 def size @fd.size rescue IOError ::File.size(path) end |