Class: Izokatu::FileImporter
- Inherits:
-
Object
- Object
- Izokatu::FileImporter
- Extended by:
- Callable
- Includes:
- Contracts, Helpers
- Defined in:
- lib/izokatu/importer/file_importer.rb
Overview
Izokatu importer for importing data from some file
Constant Summary
Constants included from Helpers
Helpers::EC_CIPHER, Helpers::KEY_SYMBOL, Helpers::RBNACL_KEY_CLASSES
Instance Attribute Summary collapse
-
#decode ⇒ TrueClass || FalseClass
readonly
Status of ability to decode imported data.
-
#delete_imported ⇒ TrueClass, FalseClass
readonly
Status of ability to delete file after import.
-
#filename ⇒ String
readonly
Name of file to import from.
Instance Method Summary collapse
-
#initialize(filename:, delete_imported:, decode:) ⇒ FileImporter
constructor
Initializing options for import.
-
#perform ⇒ Hash
Performing import of data.
Methods included from Callable
Methods included from Helpers
#decode_data, #encode_data, #export_data, #export_decrypted!, #export_encrypted!, #generate_ec_keypair, #generate_rbnacl_keypair, #generate_rsa_keypair, #import_data, #import_encrypted!, #import_encrypted_in_options!
Constructor Details
#initialize(filename:, delete_imported:, decode:) ⇒ FileImporter
Initializing options for import
26 27 28 29 30 |
# File 'lib/izokatu/importer/file_importer.rb', line 26 def initialize(filename:, delete_imported:, decode:) @filename = filename @delete_imported = delete_imported @decode = decode end |
Instance Attribute Details
#decode ⇒ TrueClass || FalseClass (readonly)
Returns status of ability to decode imported data.
16 17 18 |
# File 'lib/izokatu/importer/file_importer.rb', line 16 def decode @decode end |
#delete_imported ⇒ TrueClass, FalseClass (readonly)
Returns status of ability to delete file after import.
14 15 16 |
# File 'lib/izokatu/importer/file_importer.rb', line 14 def delete_imported @delete_imported end |
#filename ⇒ String (readonly)
Returns name of file to import from.
12 13 14 |
# File 'lib/izokatu/importer/file_importer.rb', line 12 def filename @filename end |
Instance Method Details
#perform ⇒ Hash
Performing import of data
38 39 40 41 42 43 44 45 |
# File 'lib/izokatu/importer/file_importer.rb', line 38 def perform raise 'No data file!' unless File.exist?(filename) encoded = File.read(filename) File.delete(filename) if delete_imported data = JSON.parse(encoded).transform_keys(&:to_sym) decode ? decode_data(data) : data end |