hash-joiner 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/consolidate-yaml-files +113 -0
- data/lib/hash-joiner/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8eca336800ab36a4c406e6a262e863594e9b7e16
|
4
|
+
data.tar.gz: d4eb421fd3de376cc8d94f8c128cc6118d593842
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f09e4fb98c5421d3c6ce8748891965691f40b22df2e43c9fc4b6259afcca76f4e53f9590780573788101e1b4c45d5002d7a944211866de70119ffe28cc39d64b
|
7
|
+
data.tar.gz: ff0714d4cb8631633a98ff214a042e1e7e8ffa23de3bf4f490afc805307c5fdbf2eeabb44b19fd9af40d5dc8330f5ca51fd0c4d8ebd7e970b3718377e99ae3ee
|
@@ -0,0 +1,113 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
# hash-joiner - Pruning, promoting, deep-merging, and joining Hash data
|
3
|
+
#
|
4
|
+
# Written in 2015 by Mike Bland (michael.bland@gsa.gov)
|
5
|
+
# on behalf of the 18F team, part of the US General Services Administration:
|
6
|
+
# https://18f.gsa.gov/
|
7
|
+
#
|
8
|
+
# To the extent possible under law, the author(s) have dedicated all copyright
|
9
|
+
# and related and neighboring rights to this software to the public domain
|
10
|
+
# worldwide. This software is distributed without any warranty.
|
11
|
+
#
|
12
|
+
# You should have received a copy of the CC0 Public Domain Dedication along
|
13
|
+
# with this software. If not, see
|
14
|
+
# <https://creativecommons.org/publicdomain/zero/1.0/>.
|
15
|
+
#
|
16
|
+
# ---
|
17
|
+
#
|
18
|
+
# Script to generate a 'public' Array version of 'private' YAML files.
|
19
|
+
#
|
20
|
+
# The command line flags support stripping object properties other than
|
21
|
+
# `private:`, or promoting the data associated with the property rather than
|
22
|
+
# stripping it out.
|
23
|
+
#
|
24
|
+
# Author: Mike Bland (michael.bland@gsa.gov)
|
25
|
+
# Date: 2015-02-18
|
26
|
+
|
27
|
+
require 'hash-joiner'
|
28
|
+
require 'optparse'
|
29
|
+
require 'safe_yaml'
|
30
|
+
|
31
|
+
options = {
|
32
|
+
:property => 'private',
|
33
|
+
}
|
34
|
+
|
35
|
+
opt_parser = OptionParser.new do |opts|
|
36
|
+
opts.banner = "Usage: #{$0} [-hp] [--promote] [file ...]"
|
37
|
+
|
38
|
+
opts.separator ''
|
39
|
+
opts.separator <<EOF
|
40
|
+
By default, reads a collection of YAML files containing "private" data, i.e.
|
41
|
+
objects containing a `private:` property, and prints a single YAML Array to
|
42
|
+
standard output with all the private data stripped out.
|
43
|
+
|
44
|
+
Using the option flags, other properties besides `private:` can be removed, or
|
45
|
+
the data associated with the target PROPERTY can be promoted rather than
|
46
|
+
stripped.
|
47
|
+
|
48
|
+
Options:
|
49
|
+
EOF
|
50
|
+
|
51
|
+
opts.on('-h', '--help', "Show this help") do
|
52
|
+
puts opts
|
53
|
+
exit
|
54
|
+
end
|
55
|
+
|
56
|
+
opts.on('-p', '--property PROPERTY',
|
57
|
+
'Property to strip/promote ' +
|
58
|
+
"(default: #{options[:property]})") do |property|
|
59
|
+
options[:property] = property
|
60
|
+
end
|
61
|
+
|
62
|
+
opts.on('--promote',
|
63
|
+
'Promote the PROPERTY rather than strip it') do |promote|
|
64
|
+
options[:promote] = promote
|
65
|
+
end
|
66
|
+
end
|
67
|
+
opt_parser.parse!
|
68
|
+
|
69
|
+
if ARGV.length < 1
|
70
|
+
STDERR.puts 'No input files specified'
|
71
|
+
exit 1
|
72
|
+
end
|
73
|
+
|
74
|
+
input_files = []
|
75
|
+
errors = []
|
76
|
+
|
77
|
+
ARGV.each do |input_file|
|
78
|
+
if !File.exists? input_file
|
79
|
+
errors << "File does not exist: #{input_file}"
|
80
|
+
elsif !File.readable? input_file
|
81
|
+
errors << "File not readable: #{input_file}"
|
82
|
+
else
|
83
|
+
input_files << input_file
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
unless errors.empty?
|
88
|
+
STDERR.puts errors.join "\n"
|
89
|
+
STDERR.puts "Aborting; no files processed."
|
90
|
+
exit 1
|
91
|
+
end
|
92
|
+
|
93
|
+
FILTERED_PROPERTY = options[:property]
|
94
|
+
FILTER_OPERATION = options[:promote] ? :promote_data : :remove_data
|
95
|
+
|
96
|
+
result = []
|
97
|
+
|
98
|
+
input_files.each do |input_file|
|
99
|
+
data = SafeYAML.load_file(input_file, :safe=>true)
|
100
|
+
if data
|
101
|
+
result << HashJoiner.send(FILTER_OPERATION, data, FILTERED_PROPERTY)
|
102
|
+
else
|
103
|
+
errors << "Failed to parse #{source}"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
unless errors.empty?
|
108
|
+
STDERR.puts "\n*** Errors:"
|
109
|
+
STDERR.puts errors.join "\n"
|
110
|
+
exit 1
|
111
|
+
end
|
112
|
+
|
113
|
+
puts result.to_yaml
|
data/lib/hash-joiner/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hash-joiner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Bland
|
@@ -86,10 +86,12 @@ description: Performs pruning or one-level promotion of Hash attributes (typical
|
|
86
86
|
email: michael.bland@gsa.gov
|
87
87
|
executables:
|
88
88
|
- filter-yaml-files
|
89
|
+
- consolidate-yaml-files
|
89
90
|
extensions: []
|
90
91
|
extra_rdoc_files: []
|
91
92
|
files:
|
92
93
|
- README.md
|
94
|
+
- bin/consolidate-yaml-files
|
93
95
|
- bin/filter-yaml-files
|
94
96
|
- lib/hash-joiner.rb
|
95
97
|
- lib/hash-joiner/version.rb
|