Class: ComplianceEngine::DataLoader::File
- Inherits:
-
ComplianceEngine::DataLoader
- Object
- ComplianceEngine::DataLoader
- ComplianceEngine::DataLoader::File
- Defined in:
- lib/compliance_engine/data_loader/file.rb
Overview
Load compliance engine data from a file
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#mtime ⇒ Object
readonly
Returns the value of attribute mtime.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Attributes inherited from ComplianceEngine::DataLoader
Instance Method Summary collapse
-
#initialize(file, fileclass: ::File, key: file) ⇒ File
constructor
Initialize a new instance of the ComplianceEngine::DataLoader::File class.
-
#refresh ⇒ NilClass
Refresh the data from the file if it has changed.
Constructor Details
#initialize(file, fileclass: ::File, key: file) ⇒ File
Initialize a new instance of the ComplianceEngine::DataLoader::File class
13 14 15 16 17 18 19 |
# File 'lib/compliance_engine/data_loader/file.rb', line 13 def initialize(file, fileclass: ::File, key: file) @fileclass = fileclass @filename = file @size = fileclass.size(file) @mtime = fileclass.mtime(file) super(parse(fileclass.read(file)), key: key) end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
34 35 36 |
# File 'lib/compliance_engine/data_loader/file.rb', line 34 def key @key end |
#mtime ⇒ Object (readonly)
Returns the value of attribute mtime.
34 35 36 |
# File 'lib/compliance_engine/data_loader/file.rb', line 34 def mtime @mtime end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
34 35 36 |
# File 'lib/compliance_engine/data_loader/file.rb', line 34 def size @size end |
Instance Method Details
#refresh ⇒ NilClass
Refresh the data from the file if it has changed
24 25 26 27 28 29 30 31 32 |
# File 'lib/compliance_engine/data_loader/file.rb', line 24 def refresh newsize = @fileclass.size(@filename) newmtime = @fileclass.mtime(@filename) return if newsize == @size && newmtime == @mtime @size = newsize @mtime = newmtime self.data = parse(@fileclass.read(@filename)) end |