Class: Cript::CriptCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/cript/cript_command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ CriptCommand

Returns a new instance of CriptCommand.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/cript/cript_command.rb', line 9

def initialize(argv)
  @argv = argv.dup

  @options = {
    mode:    nil,
    infile:  '-',
    outfile: '-',
    public:  File.join(ENV['HOME'], '.ssh/id_rsa.pub'),
    private: File.join(ENV['HOME'], '.ssh/id_rsa'),
    force:   false,
    debug:   false
  }

  parse!
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/cript/cript_command.rb', line 7

def options
  @options
end

Instance Method Details

#run!Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/cript/cript_command.rb', line 25

def run!
  cripter = build_cripter
  data = read_data
  get_writer do |writer|
    if @options[:mode] == 'encrypt'
      writer.print cripter.encrypt(data)
    else
      writer.print cripter.decrypt(data)
    end
  end
end