Class: SafeDb::Read

Inherits:
EditVerse show all
Defined in:
lib/controller/files/read.rb

Overview

The read use case pulls a file in from either an accessible filesystem.

This use case expects a @file_url parameter.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from EditVerse

#execute

Methods inherited from Controller

#check_post_conditions, #check_pre_conditions, #execute, #flow, #initialize, #open_remote_backend_location, #post_validation, #pre_validation, #read_verse, #set_verse, #update_verse

Constructor Details

This class inherits a constructor from SafeDb::Controller

Instance Attribute Details

#file_key=(value) ⇒ Object (writeonly)

Sets the attribute file_key

Parameters:

  • value

    the value to set the attribute file_key to.



10
11
12
# File 'lib/controller/files/read.rb', line 10

def file_key=(value)
  @file_key = value
end

#file_url=(value) ⇒ Object (writeonly)

Sets the attribute file_url

Parameters:

  • value

    the value to set the attribute file_url to.



10
11
12
# File 'lib/controller/files/read.rb', line 10

def file_url=(value)
  @file_url = value
end

Instance Method Details

#edit_verseObject

The read use case pulls a file in from an accessible filesystem.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/controller/files/read.rb', line 13

def edit_verse()

  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}]" }

  filedata_map = {}
  filedata_map.store( Indices::INGESTED_FILE_BASE_NAME_KEY, file_base_name )
  filedata_map.store( Indices::INGESTED_FILE_CONTENT64_KEY, file_content64 )

  @verse.store( Indices::INGESTED_FILE_LINE_NAME_KEY + @file_key, filedata_map )

end