Class: SafeDb::Write
- Inherits:
-
QueryVerse
- Object
- Controller
- QueryVerse
- SafeDb::Write
- Defined in:
- lib/controller/files/write.rb
Overview
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.
Instance Attribute Summary collapse
-
#file_key ⇒ Object
writeonly
Sets the attribute file_key.
-
#to_dir ⇒ Object
writeonly
Sets the attribute to_dir.
Instance Method Summary collapse
-
#query_verse ⇒ Object
Use the chapter and verse setup to read the parameter @key_name and print its corresponding value without a line feed or return.
Methods inherited from QueryVerse
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
14 15 16 |
# File 'lib/controller/files/write.rb', line 14 def file_key=(value) @file_key = value end |
#to_dir=(value) ⇒ Object (writeonly)
Sets the attribute to_dir
14 15 16 |
# File 'lib/controller/files/write.rb', line 14 def to_dir=(value) @to_dir = value end |
Instance Method Details
#query_verse ⇒ Object
Use the chapter and verse setup to read the parameter @key_name and print its corresponding value without a line feed or return.
18 19 20 21 22 23 24 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 58 59 60 61 |
# 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 |