Class: Secrets::App::Outputs::ToFile

Inherits:
Object
  • Object
show all
Defined in:
lib/secrets/app/outputs/to_file.rb

Direct Known Subclasses

ToStdout

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cli) ⇒ ToFile

Returns a new instance of ToFile.



7
8
9
# File 'lib/secrets/app/outputs/to_file.rb', line 7

def initialize(cli)
  self.cli = cli
end

Instance Attribute Details

#cliObject

Returns the value of attribute cli.



5
6
7
# File 'lib/secrets/app/outputs/to_file.rb', line 5

def cli
  @cli
end

Instance Method Details

#optsObject



11
12
13
# File 'lib/secrets/app/outputs/to_file.rb', line 11

def opts
  cli.opts
end

#output_procObject



15
16
17
18
19
20
21
22
23
# File 'lib/secrets/app/outputs/to_file.rb', line 15

def output_proc
  ->(data) {
    File.open(opts[:output], 'w') { |f| f.write(data) }
    if opts[:verbose]
      puts %Q\File #{opts[:file].bold.green} (#{File.size(opts[:file])/1024}Kb) has been #{action}ypted.\ + "\n" +
           %Q\Encrypted version written to #{(opts[:output] || 'STDOUT').bold.green} (#{File.size(opts[:output]) / 1024}Kb)\
    end
  }
end