jazor 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/bin/jazor +53 -53
  2. data/lib/jazor.rb +1 -1
  3. metadata +4 -4
data/bin/jazor CHANGED
@@ -9,56 +9,57 @@ require 'jazor'
9
9
 
10
10
  module Jazor
11
11
 
12
- options = {
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
- opts.on('-H', '--header HEADER', 'Header sent with REST request') do |opt|
29
- key, value = opt.split(':')
30
- options[:rest_headers][key.strip] = value.strip
31
- end
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
- opts.on('-t', '--test EXPRESSION', 'Test expression') do |opt|
34
- options[:tests] << opt
35
- end
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
- opts.on('-v', '--verbose', 'Turn on verbose logging') do |opt|
38
- LOG.level = Logger::DEBUG
39
- end
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
- opts.on('-X', '--request REQUEST', 'REST request method (default: %s)' % options[:rest_request]) do |opt|
42
- options[:rest_request] = opt
43
- end
40
+ opts.on('-v', '--verbose', 'Turn on verbose logging') do |opt|
41
+ LOG.level = Logger::DEBUG
42
+ end
44
43
 
45
- opts.on_tail('-h', '--help', 'Show this message') do
46
- puts opts.help
47
- exit
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
- opts.on_tail('--version', 'Show version') do
51
- puts "%s %s\n%s <%s>\n%s" % [opts.program_name, opts.version, AUTHOR, AUTHOR_EMAIL, URL]
52
- exit
53
- end
48
+ opts.on_tail('-h', '--help', 'Show this message') do
49
+ puts opts.help
50
+ exit
51
+ end
54
52
 
55
- if ARGV.length == 0 && STDIN.fcntl(Fcntl::F_GETFL, 0) != 0
56
- puts opts.help
57
- exit(1)
58
- end
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
- begin
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
@@ -8,7 +8,7 @@ require 'uri'
8
8
  module Jazor
9
9
 
10
10
  NAME = 'jazor'
11
- VERSION_INFO = ['0', '0', '3']
11
+ VERSION_INFO = ['0', '0', '4']
12
12
  VERSION = VERSION_INFO.join('.')
13
13
  AUTHOR = 'Michael T. Conigliaro'
14
14
  AUTHOR_EMAIL = 'mike [at] conigliaro [dot] org'
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: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
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