bake 0.18.1 → 0.18.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/bake/input.rb +26 -5
- data/bake/output.rb +22 -4
- data/lib/bake/version.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +1 -1
- metadata.gz.sig +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3bcf5cd8672eaa2a698d0df26ac16b853d574ff386f2134e2540b6a601cfaa1
|
4
|
+
data.tar.gz: d06efeba9bd097c2f5bad7adf529a970a8fe9e010540a6b1d8449d1d3897b005
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8fa7311b0fd77dc5388801f2aeca08395ad9499df10008b087b1bbc172ec131cf57827aceb19dff1d1365d4cbce58975f9cb9addbed830971546297e35411e41
|
7
|
+
data.tar.gz: 7ca9417bfb9d2659113c517e4f8ef530bd4fd7d54617e6ea1931694ab2b036dba4d18f092d3403a6cd76ea930b67cc0dc2112c8058cc947bcd67a7f240d27356
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/bake/input.rb
CHANGED
@@ -4,11 +4,15 @@ FORMATS = {
|
|
4
4
|
yaml: ->(file){require 'yaml'; YAML.load(file.read)},
|
5
5
|
}
|
6
6
|
|
7
|
-
# Parse an input file (defaulting to stdin) in the specified format
|
7
|
+
# Parse an input file (defaulting to stdin) in the specified format. The format can be extracted from the file extension if left unspecified.
|
8
8
|
# @parameter file [Input] The input file.
|
9
9
|
# @parameter format [Symbol] The input format, e.g. json, yaml.
|
10
|
-
def input(file: $stdin, format:
|
11
|
-
format_for(format)
|
10
|
+
def input(file: $stdin, format: nil)
|
11
|
+
if format = format_for(file, format)
|
12
|
+
format.call(file)
|
13
|
+
else
|
14
|
+
raise "Unable to determine input format of #{file}!"
|
15
|
+
end
|
12
16
|
end
|
13
17
|
|
14
18
|
# Parse some input text in the specified format (defaulting to JSON).
|
@@ -16,11 +20,28 @@ end
|
|
16
20
|
# @parameter format [Symbol] The input format, e.g. json, yaml.
|
17
21
|
def parse(text, format: :json)
|
18
22
|
file = StringIO.new(text)
|
19
|
-
|
23
|
+
|
24
|
+
if format = format_for(nil, format)
|
25
|
+
format.call(file)
|
26
|
+
else
|
27
|
+
raise "Unable to determine input format!"
|
28
|
+
end
|
20
29
|
end
|
21
30
|
|
22
31
|
private
|
23
32
|
|
24
|
-
def format_for(name)
|
33
|
+
def format_for(file, name)
|
34
|
+
if file.respond_to?(:path) and path = file.path
|
35
|
+
name ||= file_type(path)
|
36
|
+
end
|
37
|
+
|
25
38
|
FORMATS[name]
|
26
39
|
end
|
40
|
+
|
41
|
+
def file_type(path)
|
42
|
+
if extension = File.extname(path)
|
43
|
+
extension.sub!(/\A\./, '')
|
44
|
+
return if extension.empty?
|
45
|
+
return extension.to_sym
|
46
|
+
end
|
47
|
+
end
|
data/bake/output.rb
CHANGED
@@ -7,11 +7,14 @@ FORMATS = {
|
|
7
7
|
}
|
8
8
|
|
9
9
|
# Dump the last result to the specified file (defaulting to stdout) in the specified format (defaulting to Ruby's pretty print).
|
10
|
-
# @parameter input [Array(Integer)]
|
11
10
|
# @parameter file [Output] The input file.
|
12
11
|
# @parameter format [Symbol] The output format.
|
13
|
-
def output(input:, file: $stdout, format:
|
14
|
-
format_for(
|
12
|
+
def output(input:, file: $stdout, format: nil)
|
13
|
+
if format = format_for(file, format)
|
14
|
+
format.call(file, input)
|
15
|
+
else
|
16
|
+
raise "Unable to determine output format!"
|
17
|
+
end
|
15
18
|
|
16
19
|
# Allow chaining of output processing:
|
17
20
|
return input
|
@@ -19,6 +22,21 @@ end
|
|
19
22
|
|
20
23
|
private
|
21
24
|
|
22
|
-
def format_for(name)
|
25
|
+
def format_for(file, name)
|
26
|
+
if file.respond_to?(:path) and path = file.path
|
27
|
+
name ||= file_type(path)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Default to pretty print:
|
31
|
+
name ||= :pp
|
32
|
+
|
23
33
|
FORMATS[name]
|
24
34
|
end
|
35
|
+
|
36
|
+
def file_type(path)
|
37
|
+
if extension = File.extname(path)
|
38
|
+
extension.sub!(/\A\./, '')
|
39
|
+
return if extension.empty?
|
40
|
+
return extension.to_sym
|
41
|
+
end
|
42
|
+
end
|
data/lib/bake/version.rb
CHANGED
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
metadata.gz.sig
CHANGED
@@ -1,2 +1,3 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
��/{�&�,fI7�J_e�S�: ���TVe��u�<�)���YL/Nń��zʥU���E
|
2
|
+
J��~%��{ap��h����[�U�B6"ܗ�ˑ$���
|
3
|
+
�@�Whw���}��L@rm��n�W�,�A����8����vM`zj&G�k�Lk
|