Class: StatusPageVi::BackupFileValidator
- Inherits:
-
Object
- Object
- StatusPageVi::BackupFileValidator
- Defined in:
- lib/status_page_vi/validators/backup_file_validator.rb
Instance Attribute Summary collapse
-
#file_path ⇒ Object
Returns the value of attribute file_path.
-
#json_data ⇒ Object
Returns the value of attribute json_data.
-
#resource ⇒ Object
Returns the value of attribute resource.
Instance Method Summary collapse
-
#initialize(file_path) ⇒ BackupFileValidator
constructor
A new instance of BackupFileValidator.
- #valid_backup? ⇒ Boolean
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_path ⇒ Object
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_data ⇒ Object
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 |
#resource ⇒ Object
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
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 |