class SafeDb::Write

The write use case writes (or overwrites) a file or files. Files are always ejected into the present working directory. If an overwrite is detected a backup is taken of the about to be clobbered file.

If a keyname is provided then only the file against that key is ejected. No keyname will eject every file in the opened chapter and verse.

Attributes

file_key[W]
to_dir[W]

Public Instance Methods

query_verse() click to toggle source

Use the chapter and verse setup to read the parameter {@key_name} and print its corresponding value without a line feed or return.

# File lib/controller/files/write.rb, line 18
    def query_verse()

      bcv_name = "#{@book.book_name()}/#{@book.get_open_chapter_name()}/#{@book.get_open_verse_name()}"

      puts "#{bcv_name} (#{@verse.length()})\n"

      base64_content = @verse[ Indices::INGESTED_FILE_LINE_NAME_KEY + @file_key ][ Indices::INGESTED_FILE_CONTENT64_KEY ]
      simple_filename = @verse[ Indices::INGESTED_FILE_LINE_NAME_KEY + @file_key ][ Indices::INGESTED_FILE_BASE_NAME_KEY ]

      # Do a mkdir_p if @to_dir has some valid non-whitespace text
      # If so check that we have permissions to write to the specified folder
      destination_dir = Dir.pwd if @to_dir.nil?
      destination_dir = @to_dir unless @to_dir.nil?

      file_full_path = File.join( destination_dir, simple_filename )
      backup_filename = TimeStamp.yyjjj_hhmm_sst() + "-" + simple_filename
      backup_file_path = File.join( destination_dir, backup_filename )
      will_clobber = File.file?( file_full_path )

      puts ""
      puts "Clobbered File = #{backup_filename}" if will_clobber
      puts "Prescribed Directory = #{@to_dir}" unless @to_dir.nil?
      puts "Present Directory = #{Dir.pwd}" if @to_dir.nil?
      puts "Written Out Filename = #{simple_filename}"
      puts "The Full Filepath = #{file_full_path}"
      puts "Written File Key = #{@file_key}"
      puts ""
      puts "File successfully written from safe to filesystem."

# @todo - if the permissions key is found then change them please
# @todo - if the permissions key is found then change them please
# @todo - if the permissions key is found then change them please
# @todo - if the permissions key is found then change them please

=begin
FileUtils.chmod 0755, 'somecommand'
FileUtils.chmod 0644, %w(my.rb your.rb his.rb her.rb)
FileUtils.chmod 0755, '/usr/bin/ruby', :verbose => true
=end

      File.write( backup_file_path, File.read( file_full_path ) ) if will_clobber
      ::File.write( file_full_path, Base64.urlsafe_decode64( base64_content ) )

    end