mirror of
https://github.com/fluent/fluentd-ui.git
synced 2025-08-10 08:17:06 +02:00
and move backup_file model under it. prepare for gathering models that concernig about archive
42 lines
881 B
Ruby
42 lines
881 B
Ruby
class Fluentd
|
|
module SettingArchive
|
|
class BackupFile
|
|
attr_accessor :file_path
|
|
|
|
def self.find_by_file_id(backup_dir, file_id)
|
|
file_path = Pathname.new(backup_dir).join("#{file_id}.conf")
|
|
raise "No such a file #{file_path}" unless File.exist?(file_path)
|
|
|
|
new(file_path)
|
|
end
|
|
|
|
def initialize(file_path)
|
|
@file_path = file_path
|
|
end
|
|
|
|
def file_id
|
|
@file_id ||= with_file { name.gsub(/.conf\Z/,'') }
|
|
end
|
|
|
|
def name
|
|
@name ||= with_file { File.basename(file_path) }
|
|
end
|
|
|
|
def content
|
|
@content ||= with_file { File.open(file_path, "r") { |f| f.read } }
|
|
end
|
|
|
|
def ctime
|
|
with_file { File.ctime(file_path) }
|
|
end
|
|
|
|
private
|
|
|
|
def with_file
|
|
return nil unless file_path && File.exist?(file_path)
|
|
yield
|
|
end
|
|
end
|
|
end
|
|
end
|