Class: Bcdatabase::Commands::Encrypt

Inherits:
Object
  • Object
show all
Defined in:
lib/bcdatabase/commands/encrypt.rb

Instance Method Summary collapse

Constructor Details

#initialize(inputfile = nil, outputfile = nil) ⇒ Encrypt

Returns a new instance of Encrypt.



5
6
7
8
# File 'lib/bcdatabase/commands/encrypt.rb', line 5

def initialize(inputfile=nil, outputfile=nil)
  @input = (Pathname.new(inputfile) if inputfile)
  @output = (Pathname.new(outputfile) if outputfile)
end

Instance Method Details

#runObject



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/bcdatabase/commands/encrypt.rb', line 10

def run
  begin
    # try to preserve the order by replacing everything using regexes
    contents = inio.read
    contents.gsub!(/\bpassword:.*?$/) { |line|
      "epassword: #{Bcdatabase.encrypt(YAML.load(line)['password'])}"
    }
    outio.write(contents)
  ensure
    @inio.close if @close_in && @inio
    @outio.close if @close_out && @outio
  end
end