jazor 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/CHANGELOG.rdoc +4 -0
  2. data/bin/jazor +9 -8
  3. data/lib/jazor.rb +1 -1
  4. metadata +28 -122
data/CHANGELOG.rdoc CHANGED
@@ -1,5 +1,9 @@
1
1
  = Change Log
2
2
 
3
+ == 0.1.2 (2011-08-24)
4
+
5
+ * Apply sort after evaluating expression
6
+
3
7
  == 0.1.1 (2011-08-24)
4
8
 
5
9
  * Added sort option (Dan Hopkins)
data/bin/jazor CHANGED
@@ -80,16 +80,17 @@ begin
80
80
  end
81
81
  end
82
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
-
91
83
  (ARGV.length > 0 ? ARGV[0..ARGV.length] : [nil]).each do |expression|
92
84
  result = expression.nil? ? obj : obj.instance_eval(expression)
85
+
86
+ if options[:sort] && result.respond_to?(:sort)
87
+ result = if result.respond_to?(:keys) && result.respond_to?(:values)
88
+ Hash[result.sort]
89
+ else
90
+ result.sort{ |a,b| a.to_s <=> b.to_s }
91
+ end
92
+ end
93
+
93
94
  if options[:test]
94
95
  if result
95
96
  Jazor::LOG.info("Test passed: #{expression} => #{[Hash, Array].include?(result.class) ? result.to_json : result}")
data/lib/jazor.rb CHANGED
@@ -10,7 +10,7 @@ require 'json'
10
10
  module Jazor
11
11
 
12
12
  NAME = 'jazor'
13
- VERSION = '0.1.1'
13
+ VERSION = '0.1.2'
14
14
  AUTHOR = 'Michael T. Conigliaro'
15
15
  AUTHOR_EMAIL = 'mike [at] conigliaro [dot] org'
16
16
  DESCRIPTION = 'Jazor (JSON + razor) is a simple command line JSON parsing tool.'
metadata CHANGED
@@ -1,118 +1,34 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: jazor
3
- version: !ruby/object:Gem::Version
4
- hash: 25
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- - 1
10
- version: 0.1.1
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Michael T. Conigliaro
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-08-24 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2011-08-24 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: json
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &2152331680 !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 0
31
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
32
22
  type: :runtime
33
- version_requirements: *id001
34
- description: |
35
- = Jazor
36
-
37
- Jazor (JSON + razor) is a simple command line JSON parsing tool.
38
-
39
- == Installation
40
-
41
- gem install jazor
42
-
43
- == Usage
44
-
45
- jazor [options] [source] [expression ...]
46
-
47
- === Options
48
-
49
- See the *--help* command line option.
50
-
51
- === Sources
52
-
53
- The *source* argument refers to a file, URL or string containing a JSON object.
54
- Since attempts to implement a full-featured HTTP client within Jazor would have
55
- been futile, Jazor also accepts input from STDIN. This means if you ever need
56
- to use an advanced HTTP option that Jazor doesn't implement, you can always use
57
- a *real* HTTP client (e.g. {cURL}[http://curl.haxx.se/]) and simply pipe the
58
- output to Jazor.
59
-
60
- === Expressions
61
-
62
- Jazor accepts one or more Ruby *expressions* which are simply eval'ed within
63
- the context of your JSON object. After Jazor parses your JSON input into native
64
- Ruby data types (Hash, Array, etc.), these expressions are used to slice and
65
- dice the data any way you want. The results will be "pretty printed" to STDOUT.
66
-
67
- Note that hash keys can be accessed via standard Ruby (e.g. foo['bar'],
68
- foo.fetch('bar'), etc.) or Javascript (e.g. foo.bar) syntax.
69
-
70
- === Expression Testing
71
-
72
- Expression testing (*--test*) allows you to test the "truthiness" of your
73
- expression results. If any expression returns a "falsy" value, Jazor will exit
74
- with a non-zero return code. This is useful for calling Jazor from within shell
75
- scripts.
76
-
77
- == Examples
78
-
79
- $ jazor http://github.com/api/v2/json/commits/list/mconigliaro/jazor/master commits.count
80
- 16
81
-
82
- $ curl --silent http://github.com/api/v2/json/commits/list/mconigliaro/jazor/master | jazor commits.last.message
83
- initial commit
84
-
85
- $ jazor '{ "foo": "abc", "bar": [1, 2, 3] }' 'foo.split(//)'
86
- ["a", "b", "c"]
87
-
88
- $ jazor '{ "foo": "abc", "bar": [1, 2, 3] }' 'bar.inject { |memo,obj| memo + obj }'
89
- 6
90
-
91
- $ jazor '[1, 2, 3, 4, 5]' 'select { |obj| obj.even? }'
92
- [2, 4]
93
-
94
- $ jazor '[1, 2, 3, 4, 5]' 'select { |obj| obj.odd? }'
95
- [1, 3, 5]
96
-
97
- $ jazor '["a", "b", "c"]' self.count
98
- 3
99
-
100
- == Authors
101
-
102
- * Michael T. Conigliaro <mike [at] conigliaro [dot] org>
103
-
104
- == Contributers
105
-
106
- * {Daniel Hopkins}[https://github.com/danielhopkins]
107
-
23
+ prerelease: false
24
+ version_requirements: *2152331680
25
+ description: Jazor (JSON + razor) is a simple command line JSON parsing tool.
108
26
  email: mike [at] conigliaro [dot] org
109
- executables:
27
+ executables:
110
28
  - jazor
111
29
  extensions: []
112
-
113
30
  extra_rdoc_files: []
114
-
115
- files:
31
+ files:
116
32
  - CHANGELOG.rdoc
117
33
  - LICENSE
118
34
  - Rakefile
@@ -125,36 +41,26 @@ files:
125
41
  - test/test_rest_client.rb
126
42
  homepage: http://github.com/mconigliaro/jazor
127
43
  licenses: []
128
-
129
44
  post_install_message:
130
45
  rdoc_options: []
131
-
132
- require_paths:
46
+ require_paths:
133
47
  - lib
134
- required_ruby_version: !ruby/object:Gem::Requirement
48
+ required_ruby_version: !ruby/object:Gem::Requirement
135
49
  none: false
136
- requirements:
137
- - - ">="
138
- - !ruby/object:Gem::Version
139
- hash: 3
140
- segments:
141
- - 0
142
- version: "0"
143
- required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
144
55
  none: false
145
- requirements:
146
- - - ">="
147
- - !ruby/object:Gem::Version
148
- hash: 3
149
- segments:
150
- - 0
151
- version: "0"
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
152
60
  requirements: []
153
-
154
61
  rubyforge_project: jazor
155
62
  rubygems_version: 1.8.6
156
63
  signing_key:
157
64
  specification_version: 3
158
65
  summary: Jazor (JSON + razor) is a simple command line JSON parsing tool.
159
66
  test_files: []
160
-