Class: Izokatu::FileImporter

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Methods included from Callable

call

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

Parameters:

Since:

  • 0.1.0



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

#decodeTrueClass || FalseClass (readonly)

Returns status of ability to decode imported data.

Returns:

  • (TrueClass || FalseClass)

    status of ability to decode imported data



16
17
18
# File 'lib/izokatu/importer/file_importer.rb', line 16

def decode
  @decode
end

#delete_importedTrueClass, FalseClass (readonly)

Returns status of ability to delete file after import.

Returns:

  • (TrueClass, FalseClass)

    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

#filenameString (readonly)

Returns name of file to import from.

Returns:

  • (String)

    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

#performHash

Performing import of data

Returns:

  • (Hash)

    imported data

Since:

  • 0.1.0



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