Class: SafeDb::FileMe
Overview
The file use case pulls a file in from either an accessible filesystem or from a remote http, https, git, S3, GoogleDrive and/or ssh source.
The @file_url is the most common parameter given to this use case.
Constant Summary
Constants inherited from UseCase
UseCase::APP_DIR_NAME, UseCase::COMMANDMENT, UseCase::ENV_VAR_KEY_NAME, UseCase::ENV_VAR_PREFIX_A, UseCase::ENV_VAR_PREFIX_B, UseCase::FILE_CONTENT_KEY, UseCase::FILE_KEY_PREFIX, UseCase::FILE_NAME_KEY
Instance Attribute Summary collapse
-
#file_key ⇒ Object
writeonly
Sets the attribute file_key.
-
#file_url ⇒ Object
writeonly
Sets the attribute file_url.
Attributes inherited from UseCase
Instance Method Summary collapse
-
#execute ⇒ Object
There are 3 maps involved in the implementation and they are all (or in part) retrieved and/or created as necessary.
Methods inherited from UseCase
#check_post_conditions, #check_pre_conditions, #cleanup, #config_directory, #config_file, #flow_of_events, #get_master_database, #initialize, #post_validation
Constructor Details
This class inherits a constructor from SafeDb::UseCase
Instance Attribute Details
#file_key=(value) ⇒ Object (writeonly)
Sets the attribute file_key
11 12 13 |
# File 'lib/usecase/files/file_me.rb', line 11 def file_key=(value) @file_key = value end |
#file_url=(value) ⇒ Object (writeonly)
Sets the attribute file_url
11 12 13 |
# File 'lib/usecase/files/file_me.rb', line 11 def file_url=(value) @file_url = value end |
Instance Method Details
#execute ⇒ Object
There are 3 maps involved in the implementation and they are all (or in part) retrieved and/or created as necessary. They are
-
the current chapter as a map
-
the current verse as a map
-
the file’s keyname as a map
Once the maps have been found and/or created if necessary the file’s keyname map is either populated or amended with the following data.
-
filename | UseCase::FILE_NAME_KEY | the file’s simple name
-
content64 | UseCase::FILE_CONTENT_KEY | the file’s base64 content
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/usecase/files/file_me.rb', line 25 def execute return unless ops_key_exists? master_db = KeyApi.read_master_db() return if unopened_envelope?( master_db ) chapter_id = ENVELOPE_KEY_PREFIX + master_db[ ENV_PATH ] chapter_exists = KeyApi.db_envelope_exists?( master_db[ chapter_id ] ) chapter_data = KeyDb.from_json( KeyApi.content_unlock( master_db[ chapter_id ] ) ) if chapter_exists chapter_data = KeyDb.new() unless chapter_exists content_hdr = create_header() master_db[ chapter_id ] = {} unless chapter_exists verse_id = master_db[ KEY_PATH ] file_full_path = ::File.absolute_path( @file_url ) file_base_name = ::File.basename( file_full_path ) file_content64 = Base64.urlsafe_encode64( ::File.read( file_full_path ) ) log.info(x) { "Key name of the file to ingest => #{@file_key}" } log.info(x) { "Ingesting file at path => #{file_full_path}" } log.info(x) { "The name of the file to ingest is => #{file_base_name}" } log.info(x) { "Size of base64 file content => [#{file_content64.length}]" } chapter_data.create_map_entry( verse_id, "#{FILE_KEY_PREFIX}#{@file_key}", FILE_NAME_KEY, file_base_name ) chapter_data.create_map_entry( verse_id, "#{FILE_KEY_PREFIX}#{@file_key}", FILE_CONTENT_KEY, file_content64 ) KeyApi.content_lock( master_db[ chapter_id ], chapter_data.to_json, content_hdr ) KeyApi.write_master_db( content_hdr, master_db ) Show.new.flow_of_events end |