module OMU::Support::Sensitive

Sensitive file read/write

Constants

EXT

Public Instance Methods

content_decrypt(content) click to toggle source
# File lib/omu_support/sensitive.rb, line 34
def content_decrypt(content)
  encryptor('').__send__(:decrypt, content)
end
encryptor(file) click to toggle source
# File lib/omu_support/sensitive.rb, line 44
def encryptor(file)
  ActiveSupport::EncryptedFile.new(
    content_path:         file,
    env_key:              'RAILS_MASTER_KEY',
    key_path:             Rails.root.join('config/master.key'),
    raise_if_missing_key: true
  )
end
expand_path(path) click to toggle source
# File lib/omu_support/sensitive.rb, line 40
def expand_path(path)
  File.expand_path(path, Rails.root) + EXT
end
read(path) click to toggle source
# File lib/omu_support/sensitive.rb, line 11
def read(path)
  encryptor(expand_path(path)).read
end
read_write(path) click to toggle source
# File lib/omu_support/sensitive.rb, line 30
def read_write(path)
  write(path, File.read(path))
end
readlines(path) click to toggle source
# File lib/omu_support/sensitive.rb, line 15
def readlines(path)
  read(path).split "\n"
end
write(path, content) click to toggle source
# File lib/omu_support/sensitive.rb, line 19
def write(path, content)
  unless Dir.exist?(dir = File.dirname(file = expand_path(path)))
    FileUtils.mkdir_p(dir)
  end
  encryptor(file).write(content)
end
writelines(path, contents) click to toggle source
# File lib/omu_support/sensitive.rb, line 26
def writelines(path, contents)
  write(path, contents.join("\n"))
end