Class: StatusPageVi::BackupFileValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/status_page_vi/validators/backup_file_validator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path) ⇒ BackupFileValidator

Returns a new instance of BackupFileValidator.



5
6
7
# File 'lib/status_page_vi/validators/backup_file_validator.rb', line 5

def initialize(file_path)
  self.file_path = file_path
end

Instance Attribute Details

#file_pathObject

Returns the value of attribute file_path.



3
4
5
# File 'lib/status_page_vi/validators/backup_file_validator.rb', line 3

def file_path
  @file_path
end

#json_dataObject

Returns the value of attribute json_data.



3
4
5
# File 'lib/status_page_vi/validators/backup_file_validator.rb', line 3

def json_data
  @json_data
end

#resourceObject

Returns the value of attribute resource.



3
4
5
# File 'lib/status_page_vi/validators/backup_file_validator.rb', line 3

def resource
  @resource
end

Instance Method Details

#valid_backup?Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/status_page_vi/validators/backup_file_validator.rb', line 9

def valid_backup?
  extention = File.extname(self.file_path)
  return false if extention != ".json"

  file_name = File.basename(self.file_path, extention)
  self.resource = RESOURCES[file_name]
  return false unless self.resource

  begin
    self.json_data = JSON.parse(File.read(self.file_path))
  rescue JSON::ParserError
    return false
  end
end