Module: ObscureYaml::Cli

Defined in:
lib/obscure_yaml/cli.rb

Constant Summary collapse

DECODE =
'decode'
ENCODE =
'encode'

Class Method Summary collapse

Class Method Details

.parse(arguments) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/obscure_yaml/cli.rb', line 8

def parse(arguments)
  mode = arguments.shift
  output = arguments.last != arguments.first ? arguments.pop : $stdout
  input = arguments.first || $stdin
  with(input, 'r') do |input_object|
    with(output, 'w+') do |output_object|
      case mode
      when DECODE
        ObscureYaml.decode(output_object, input_object)
      when ENCODE
        ObscureYaml.encode(output_object, input_object)
      end
    end
  end
end

.with(output, mode) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/obscure_yaml/cli.rb', line 24

def with(output, mode)
  if output.kind_of?(IO)
    yield output
  else
    open(output, mode) do |f|
      yield f
    end
  end
end