obscure_yaml 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7d03aa807687824a25fbe84157baa752f6707d1c
4
- data.tar.gz: 6bde24370f2d14c8c35b392b2c360e99dce8fab6
3
+ metadata.gz: f8cb65381c4bb6f6f29047bf4b7edf7080fb1cbb
4
+ data.tar.gz: f900378b076ebfcbf898bee3b7e1fb6aa7a7c3d7
5
5
  SHA512:
6
- metadata.gz: fe9ab40fbe9efdbc54b66912f50e818f5b3ea753a4a7d7d84bf43b74d64c8915acd65cf074089b434ba23d98809e960973489228e9d316eba2ae248440d7d5ac
7
- data.tar.gz: 454cd7bfb0d48b316da75dd89f08371b663632ec670314a91ca85cca0e448a68d2661d3aa5c3b0766762ac0647fd4ccdd87bae5bb92cf6e3aa72a5f46346f74b
6
+ metadata.gz: 48cda1819f12cd9776993a1cc376fe9d50e63c25e6613fa2e70ff20140e9657adc1a7ba3b85c731dd2338de2c2e7898287541675ffbb3d832f7e0b67d32a823d
7
+ data.tar.gz: 13036cb2318f7a05d122491bd37f93b0ef12bd51439c9d412a89e0f9495460f7bf2eccf7eb8edf298101ae8793beeec161a69d251e8509b78a17167c8e36a373
@@ -6,11 +6,28 @@ module ObscureYaml
6
6
  module_function
7
7
 
8
8
  def parse(arguments)
9
- case arguments.shift
10
- when DECODE
11
- ObscureYaml.decode(*arguments)
12
- when ENCODE
13
- ObscureYaml.encode(arguments.pop, *arguments)
9
+ mode = arguments.shift
10
+ output = arguments.last != arguments.first ? arguments.pop : $stdout
11
+ input = arguments.first || $stdin
12
+ with(input, 'r') do |input_object|
13
+ with(output, 'w+') do |output_object|
14
+ case mode
15
+ when DECODE
16
+ ObscureYaml.decode(output_object, input_object)
17
+ when ENCODE
18
+ ObscureYaml.encode(output_object, input_object)
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ def with(output, mode)
25
+ if output.kind_of?(IO)
26
+ yield output
27
+ else
28
+ open(output, mode) do |f|
29
+ yield f
30
+ end
14
31
  end
15
32
  end
16
33
 
@@ -1,3 +1,3 @@
1
1
  module ObscureYaml
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/obscure_yaml.rb CHANGED
@@ -1,27 +1,26 @@
1
1
  # require 'obscure_yaml/base64'
2
2
  require 'yaml'
3
3
  require 'base64'
4
+ require 'open-uri'
4
5
  module ObscureYaml
5
6
  DEFAULT_DATA_KEY = 'data'
6
7
  MAGIC_DELIMITER = '@'
7
8
  module_function
8
9
 
9
- def decode(file_path, output=$stdout)
10
- output << construct_yaml(file_path, :output)
10
+ def decode(output, input)
11
+ output << construct_yaml(input, :output)
11
12
  end
12
13
 
13
- def encode(output_path, file_path)
14
- File.open(output_path, 'w+') do |f|
15
- f.write(construct_yaml(file_path, :input))
16
- end
14
+ def encode(output, input)
15
+ output << construct_yaml(input, :input)
17
16
  end
18
17
 
19
18
  private
20
19
 
21
20
  module_function
22
21
 
23
- def construct_yaml(file_path, direction)
24
- YAML::load_file(file_path).tap { |hsh|
22
+ def construct_yaml(yaml_source, direction)
23
+ YAML::load(yaml_source.read).tap { |hsh|
25
24
  data = hsh[obscured_data_key]
26
25
  hsh[obscured_data_key] = data.map { |key, value|
27
26
  [key, handle_coding(direction, value)]
@@ -35,7 +34,6 @@ module ObscureYaml
35
34
 
36
35
  def value_or_file_contents(value)
37
36
  return value unless detect_file(value)
38
- require 'open-uri'
39
37
  value_contents = open(value.gsub(magic_delimiter, '')) { |f| f.read }
40
38
  end
41
39
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: obscure_yaml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Glusman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-21 00:00:00.000000000 Z
11
+ date: 2016-09-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: " There was no call for this really, except we needed it.\n"
14
14
  email: