Module: Roebe::SaveFile

Defined in:
lib/roebe/toplevel_methods/write_what_into.rb

Class Method Summary collapse

Class Method Details

.append_this_onto_that_file(what, into) ⇒ Object

#

Roebe::SaveFile.append_this_onto_that_file

#


50
51
52
53
54
# File 'lib/roebe/toplevel_methods/write_what_into.rb', line 50

def self.append_this_onto_that_file(
    what, into
  )
  write_what_into(what, into, 'a+')
end

.write_what_into(what, into = 'foobar.md', use_this_mode = 'w+', change_permission = nil) ⇒ Object

#

Roebe::SaveFile.write_what_into

#


16
17
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
# File 'lib/roebe/toplevel_methods/write_what_into.rb', line 16

def self.write_what_into(
    what,
    into              = 'foobar.md',
    use_this_mode     = 'w+', # <- This is the default.
    change_permission = nil
  )
  if use_this_mode.is_a? Hash
    if use_this_mode.has_key? :permission
      # =================================================================== #
      # Example:
      #   permission: @hash_internal[:permission]
      # =================================================================== #
      permission = use_this_mode.delete(:permission).to_i(8)
    end
    if use_this_mode.is_a?(Hash) and use_this_mode.empty?
      use_this_mode = 'w+' # <- This is the default.
    end
  end
  begin
    File.open(into, use_this_mode) { |this_file|
      this_file.write(what)
    }
    if change_permission and File.file?(this_file)
      File.chmod(permission, this_file)
    end
  rescue Exception => error
    pp error
    puts 'Error encountered for the path '+into+'.'
  end
end