Class: Roro::Crypto::Exposer

Inherits:
Object
  • Object
show all
Includes:
FileReflection
Defined in:
lib/roro/crypto/exposer.rb

Instance Method Summary collapse

Methods included from FileReflection

#gather_environments, #get_key, #source_files

Constructor Details

#initializeExposer

Returns a new instance of Exposer.



9
10
11
12
# File 'lib/roro/crypto/exposer.rb', line 9

def initialize
  @writer = Roro::Crypto::FileWriter.new
  @cipher = Roro::Crypto::Cipher.new
end

Instance Method Details

#expose(environments, directory, ext) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/roro/crypto/exposer.rb', line 20

def expose(environments, directory, ext)
  if environments.empty?
    environments = gather_environments(directory, ext)
  else
    environments.each { |environment| get_key(environment) }
  end
  environments.each do |environment|
    exposable = source_files(directory, "#{environment}*#{ext}")
    exposable.each { |file| expose_file(file, get_key(environment)) }
  end
end

#expose_file(file, key) ⇒ Object



14
15
16
17
18
# File 'lib/roro/crypto/exposer.rb', line 14

def expose_file(file, key)
  encrypted_content = File.read(file)
  decrypted_content = @cipher.decrypt(encrypted_content, key)
  @writer.write_to_file(file.split('.enc').first, decrypted_content)
end