Method: OpenSecret::FileMe#execute
- Defined in:
- lib/usecase/files/file_me.rb
#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 = OpenKey::KeyApi.read_master_db() return if unopened_envelope?( master_db ) chapter_id = ENVELOPE_KEY_PREFIX + master_db[ ENV_PATH ] chapter_exists = OpenKey::KeyApi.db_envelope_exists?( master_db[ chapter_id ] ) chapter_data = OpenKey::KeyDb.from_json( OpenKey::KeyApi.content_unlock( master_db[ chapter_id ] ) ) if chapter_exists chapter_data = OpenKey::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 ) OpenKey::KeyApi.content_lock( master_db[ chapter_id ], chapter_data.to_json, content_hdr ) OpenKey::KeyApi.write_master_db( content_hdr, master_db ) Show.new.flow_of_events end |