jazor 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,24 @@
1
+ = Change Log
2
+
3
+ == 0.1.1 (2011-08-24)
4
+
5
+ * Added sort option (Dan Hopkins)
6
+
7
+ == 0.1.0 (2011-08-23)
8
+
9
+ * Code refactoring
10
+ * Documentation rewrite
11
+ * Changed test option to a switch that operates on all expressions
12
+
13
+ == 0.0.4 (2011-01-25)
14
+
15
+ * Print help summary on absence of input
16
+ * Bug fixes
17
+
18
+ == 0.0.3 (2011-01-25)
19
+
20
+ * Bug fixes
21
+
22
+ == 0.0.2 (2011-01-24)
23
+
24
+ * Initial public release
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (C) 2011 Michael T. Conigliaro
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7
+ of the Software, and to permit persons to whom the Software is furnished to do
8
+ so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
@@ -1,6 +1,6 @@
1
1
  = Jazor
2
2
 
3
- Jazor (rhymes with "razor") is a simple command line JSON parsing tool.
3
+ Jazor (JSON + razor) is a simple command line JSON parsing tool.
4
4
 
5
5
  == Installation
6
6
 
@@ -63,6 +63,10 @@ scripts.
63
63
  $ jazor '["a", "b", "c"]' self.count
64
64
  3
65
65
 
66
- == Author
66
+ == Authors
67
67
 
68
- Michael T. Conigliaro <mike [at] conigliaro [dot] org>
68
+ * Michael T. Conigliaro <mike [at] conigliaro [dot] org>
69
+
70
+ == Contributers
71
+
72
+ * {Daniel Hopkins}[https://github.com/danielhopkins]
data/bin/jazor CHANGED
@@ -40,6 +40,12 @@ OptionParser.new do |opts|
40
40
  options[:rest_request] = opt
41
41
  end
42
42
 
43
+ if Jazor::HAS_ORDERED_HASH
44
+ opts.on('-s', '--sort', "Sort output") do
45
+ options[:sort] = true
46
+ end
47
+ end
48
+
43
49
  opts.on_tail('-h', '--help', 'Show this message') do
44
50
  puts opts.help
45
51
  exit
@@ -74,6 +80,14 @@ begin
74
80
  end
75
81
  end
76
82
 
83
+ if options[:sort] && obj.respond_to?(:sort)
84
+ obj = if obj.respond_to?(:keys) && obj.respond_to?(:values)
85
+ Hash[obj.sort]
86
+ else
87
+ obj.sort{ |a,b| a.to_s <=> b.to_s }
88
+ end
89
+ end
90
+
77
91
  (ARGV.length > 0 ? ARGV[0..ARGV.length] : [nil]).each do |expression|
78
92
  result = expression.nil? ? obj : obj.instance_eval(expression)
79
93
  if options[:test]
@@ -10,15 +10,17 @@ require 'json'
10
10
  module Jazor
11
11
 
12
12
  NAME = 'jazor'
13
- VERSION = '0.1.0'
13
+ VERSION = '0.1.1'
14
14
  AUTHOR = 'Michael T. Conigliaro'
15
15
  AUTHOR_EMAIL = 'mike [at] conigliaro [dot] org'
16
- DESCRIPTION = 'Jazor is a simple command line JSON parsing tool'
16
+ DESCRIPTION = 'Jazor (JSON + razor) is a simple command line JSON parsing tool.'
17
17
  URL = 'http://github.com/mconigliaro/jazor'
18
18
 
19
19
  LOG = Logger.new(STDOUT)
20
20
  LOG.level = Logger::INFO
21
21
 
22
+ HAS_ORDERED_HASH = (RUBY_VERSION.split('.').map(&:to_i) <=> [1, 9, 1]) >= 0
23
+
22
24
  def self.parse(input=nil)
23
25
  # FIXME: https://github.com/flori/json/issues/16
24
26
  obj = (JSON.parse(input) rescue false) || (Integer(input) rescue false) || (Float(input) rescue false) || String(input)
@@ -43,4 +43,17 @@ class TestExecute < Test::Unit::TestCase
43
43
  assert `#{@jazor_bin} -t #{@init_file} 'value1==1234'` =~ /failed/
44
44
  end
45
45
 
46
+ def test_sorting
47
+ if Jazor::HAS_ORDERED_HASH
48
+ {
49
+ '[3, 2, 1]' => [1, 2, 3],
50
+ '["foo", "bar", 1]' => [1, 'bar', 'foo'],
51
+ '{"foo":1, "bar":2}' => {'bar' => 2, 'foo' => 1},
52
+ '{"1":1, "bar":2}' => {'1' => 1, 'bar' => 2}
53
+ }.each do |k,v|
54
+ assert JSON.parse(`#{@jazor_bin} -s '#{k}'`) == v
55
+ end
56
+ end
57
+ end
58
+
46
59
  end
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: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Michael T. Conigliaro
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-08-23 00:00:00 Z
18
+ date: 2011-08-24 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: json
@@ -34,7 +34,7 @@ dependencies:
34
34
  description: |
35
35
  = Jazor
36
36
 
37
- Jazor (rhymes with "razor") is a simple command line JSON parsing tool.
37
+ Jazor (JSON + razor) is a simple command line JSON parsing tool.
38
38
 
39
39
  == Installation
40
40
 
@@ -97,12 +97,15 @@ description: |
97
97
  $ jazor '["a", "b", "c"]' self.count
98
98
  3
99
99
 
100
- == Author
100
+ == Authors
101
+
102
+ * Michael T. Conigliaro <mike [at] conigliaro [dot] org>
103
+
104
+ == Contributers
101
105
 
102
- Michael T. Conigliaro <mike [at] conigliaro [dot] org>
106
+ * {Daniel Hopkins}[https://github.com/danielhopkins]
103
107
 
104
- email:
105
- - mike [at] conigliaro [dot] org
108
+ email: mike [at] conigliaro [dot] org
106
109
  executables:
107
110
  - jazor
108
111
  extensions: []
@@ -110,7 +113,8 @@ extensions: []
110
113
  extra_rdoc_files: []
111
114
 
112
115
  files:
113
- - COPYING.txt
116
+ - CHANGELOG.rdoc
117
+ - LICENSE
114
118
  - Rakefile
115
119
  - README.rdoc
116
120
  - bin/jazor
@@ -151,6 +155,6 @@ rubyforge_project: jazor
151
155
  rubygems_version: 1.8.6
152
156
  signing_key:
153
157
  specification_version: 3
154
- summary: Jazor is a simple command line JSON parsing tool
158
+ summary: Jazor (JSON + razor) is a simple command line JSON parsing tool.
155
159
  test_files: []
156
160
 
@@ -1,23 +0,0 @@
1
- # Copyright (C) 2011 by Michael T. Conigliaro. All rights reserved.
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # No portion of this Software shall be used in any application which does not
14
- # use the ReportGrid platform to provide some subset of its functionality.
15
- #
16
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
- # THE SOFTWARE.
23
- #