jazor 0.0.3 → 0.0.4
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.
- data/bin/jazor +53 -53
- data/lib/jazor.rb +1 -1
- metadata +4 -4
data/bin/jazor
CHANGED
@@ -9,56 +9,57 @@ require 'jazor'
|
|
9
9
|
|
10
10
|
module Jazor
|
11
11
|
|
12
|
-
|
13
|
-
:tests => [],
|
14
|
-
:rest_data => '',
|
15
|
-
:rest_headers => {},
|
16
|
-
:rest_request => 'GET'
|
17
|
-
}
|
18
|
-
|
19
|
-
OptionParser.new do |opts|
|
20
|
-
opts.version = VERSION
|
21
|
-
opts.banner = "Usage: #{$0} [options] [source] [slice]\n" \
|
22
|
-
+ "Example: #{$0} http://example.com/example.json a.b.c\n\n"
|
23
|
-
|
24
|
-
opts.on('-d', '--data DATA', 'Data sent with REST request') do |opt|
|
25
|
-
options[:rest_data] = opt
|
26
|
-
end
|
12
|
+
begin
|
27
13
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
14
|
+
options = {
|
15
|
+
:tests => [],
|
16
|
+
:rest_data => {},
|
17
|
+
:rest_headers => {},
|
18
|
+
:rest_request => 'GET'
|
19
|
+
}
|
20
|
+
|
21
|
+
OptionParser.new do |opts|
|
22
|
+
opts.version = VERSION
|
23
|
+
opts.banner = "Usage: #{$0} [options] [source] [slice]\n" \
|
24
|
+
+ "Example: #{$0} http://example.com/example.json a.b.c\n\n"
|
25
|
+
|
26
|
+
opts.on('-d', '--data DATA', 'Data sent with REST request (e.g. <name>=<value>)') do |opt|
|
27
|
+
key, value = opt.split('=')
|
28
|
+
options[:rest_data][key] = value
|
29
|
+
end
|
32
30
|
|
33
|
-
|
34
|
-
|
35
|
-
|
31
|
+
opts.on('-H', '--header HEADER', 'Header sent with REST request (e.g. <name>:<value>)') do |opt|
|
32
|
+
key, value = opt.split(':')
|
33
|
+
options[:rest_headers][key.strip] = value.strip
|
34
|
+
end
|
36
35
|
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
opts.on('-t', '--test EXPRESSION', 'Test expression (e.g. "a.b.c == 123")') do |opt|
|
37
|
+
options[:tests] << opt
|
38
|
+
end
|
40
39
|
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
opts.on('-v', '--verbose', 'Turn on verbose logging') do |opt|
|
41
|
+
LOG.level = Logger::DEBUG
|
42
|
+
end
|
44
43
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
end
|
44
|
+
opts.on('-X', '--request REQUEST', 'REST request method (default: %s)' % options[:rest_request]) do |opt|
|
45
|
+
options[:rest_request] = opt
|
46
|
+
end
|
49
47
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
48
|
+
opts.on_tail('-h', '--help', 'Show this message') do
|
49
|
+
puts opts.help
|
50
|
+
exit
|
51
|
+
end
|
54
52
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
end.parse!
|
53
|
+
opts.on_tail('--version', 'Show version') do
|
54
|
+
puts "%s %s\n%s <%s>\n%s" % [opts.program_name, opts.version, AUTHOR, AUTHOR_EMAIL, URL]
|
55
|
+
exit
|
56
|
+
end
|
60
57
|
|
61
|
-
|
58
|
+
if ARGV.length == 0 && STDIN.fcntl(Fcntl::F_GETFL, 0) != 0
|
59
|
+
puts opts.help
|
60
|
+
exit(1)
|
61
|
+
end
|
62
|
+
end.parse!
|
62
63
|
|
63
64
|
jazor = if STDIN.fcntl(Fcntl::F_GETFL, 0) == 0
|
64
65
|
json = STDIN.read
|
@@ -85,20 +86,19 @@ module Jazor
|
|
85
86
|
puts [Hash, Array].include?(obj.class) ? JSON.pretty_generate(obj) : obj
|
86
87
|
end
|
87
88
|
|
89
|
+
options[:tests].each do |test|
|
90
|
+
if jazor.instance_eval(test)
|
91
|
+
LOG.info("Test passed: %s" % test)
|
92
|
+
else
|
93
|
+
LOG.error("Test failed: %s" % test)
|
94
|
+
exit(1)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
88
98
|
rescue StandardError => e
|
89
|
-
#puts e
|
90
|
-
#puts e.backtrace
|
91
99
|
LOG.error(e.message)
|
100
|
+
puts e.backtrace if LOG.level == Logger::DEBUG
|
92
101
|
exit(1)
|
93
102
|
end
|
94
103
|
|
95
|
-
options[:tests].each do |test|
|
96
|
-
if jazor.instance_eval(test)
|
97
|
-
LOG.info("Test passed: %s" % test)
|
98
|
-
else
|
99
|
-
LOG.error("Test failed: %s" % test)
|
100
|
-
exit(1)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
104
|
end
|
data/lib/jazor.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jazor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Michael T. Conigliaro
|
@@ -47,9 +47,9 @@ files:
|
|
47
47
|
- README.rdoc
|
48
48
|
- bin/jazor
|
49
49
|
- lib/jazor.rb
|
50
|
+
- test/test_jazor_bin.rb
|
50
51
|
- test/test.json
|
51
52
|
- test/test_jazor.rb
|
52
|
-
- test/test_jazor_bin.rb
|
53
53
|
- test/test_rest_client.rb
|
54
54
|
has_rdoc: true
|
55
55
|
homepage: http://github.com/mconigliaro/jazor
|