Module: OMU::Support::Sensitive
- Defined in:
- lib/omu_support/sensitive.rb
Overview
Sensitive file read/write
Constant Summary collapse
- EXT =
'.enc'
Class Method Summary collapse
- .content_decrypt(content) ⇒ Object
- .encryptor(file) ⇒ Object
- .expand_path(path) ⇒ Object
- .read(path) ⇒ Object
- .read_write(path) ⇒ Object
- .readlines(path) ⇒ Object
- .write(path, content) ⇒ Object
- .writelines(path, contents) ⇒ Object
Class Method Details
.content_decrypt(content) ⇒ Object
34 35 36 |
# File 'lib/omu_support/sensitive.rb', line 34 def content_decrypt(content) encryptor('').__send__(:decrypt, content) end |
.encryptor(file) ⇒ Object
44 45 46 47 48 49 50 51 |
# 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) ⇒ Object
40 41 42 |
# File 'lib/omu_support/sensitive.rb', line 40 def (path) File.(path, Rails.root) + EXT end |
.read(path) ⇒ Object
11 12 13 |
# File 'lib/omu_support/sensitive.rb', line 11 def read(path) encryptor((path)).read end |
.read_write(path) ⇒ Object
30 31 32 |
# File 'lib/omu_support/sensitive.rb', line 30 def read_write(path) write(path, File.read(path)) end |
.readlines(path) ⇒ Object
15 16 17 |
# File 'lib/omu_support/sensitive.rb', line 15 def readlines(path) read(path).split "\n" end |
.write(path, content) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/omu_support/sensitive.rb', line 19 def write(path, content) unless Dir.exist?(dir = File.dirname(file = (path))) FileUtils.mkdir_p(dir) end encryptor(file).write(content) end |
.writelines(path, contents) ⇒ Object
26 27 28 |
# File 'lib/omu_support/sensitive.rb', line 26 def writelines(path, contents) write(path, contents.join("\n")) end |