jsonpath 0.2.0 → 0.2.1

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/.gemtest ADDED
File without changes
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ pkg/*
2
+ Gemfile.lock
3
+ coverage/*
4
+ doc/*
5
+ .yardoc
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --colour
2
+ --format doc
3
+ --backtrace
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "http://rubygems.org"
2
+ gemspec
data/Rakefile CHANGED
@@ -10,12 +10,9 @@ Rake::RDocTask.new do |rd|
10
10
  end
11
11
 
12
12
  require 'rubygems'
13
- require 'spec'
14
- require 'spec/rake/spectask'
15
13
 
16
- Spec::Rake::SpecTask.new do |t|
17
- t.ruby_opts = ['-rubygems']
18
- t.spec_opts ||= []
19
- t.spec_opts << "--options" << "spec/spec.opts"
20
- t.spec_files = FileList['spec/*.rb']
21
- end
14
+ require 'rspec/core/rake_task'
15
+ RSpec::Core::RakeTask.new(:spec)
16
+
17
+ task :default => :spec
18
+ task :test => :spec
data/jsonpath.gemspec CHANGED
@@ -23,17 +23,7 @@ Gem::Specification.new do |s|
23
23
  s.add_runtime_dependency 'json'
24
24
  s.add_development_dependency 'code_stats'
25
25
  s.add_development_dependency 'rake'
26
- s.add_development_dependency 'rspec', '< 2.0.0'
26
+ s.add_development_dependency 'rspec', '~> 2.5.0'
27
27
  s.add_development_dependency 'bundler', '~> 1.0.0'
28
-
29
- if s.respond_to? :specification_version then
30
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
31
- s.specification_version = 3
32
-
33
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
34
- else
35
- end
36
- else
37
- end
38
28
  end
39
29
 
@@ -1,11 +1,11 @@
1
1
  class JsonPath
2
2
  class Enumerable
3
3
  include ::Enumerable
4
-
4
+
5
5
  def initialize(path, object)
6
6
  @path, @object = path.path, object
7
7
  end
8
-
8
+
9
9
  def each(node = @object, pos = 0, &blk)
10
10
  if pos == @path.size
11
11
  return blk.call(node)
@@ -23,7 +23,7 @@ class JsonPath
23
23
  when ?', ?"
24
24
  if node.is_a?(Hash)
25
25
  key = sub_path[1,sub_path.size - 2]
26
- each(node[key], pos + 1, &blk) if node.key?(key)
26
+ each(node[key], pos + 1, &blk) if node.key?(key)
27
27
  end
28
28
  when ??
29
29
  (node.is_a?(Hash) ? node.keys : (0..node.size)).each do |e|
@@ -58,4 +58,3 @@ class JsonPath
58
58
  end
59
59
  end
60
60
  end
61
-
@@ -1,3 +1,3 @@
1
1
  class JsonPath
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
data/lib/jsonpath.rb CHANGED
@@ -48,4 +48,8 @@ class JsonPath
48
48
  JsonPath::Enumerable.new(self, object)
49
49
  end
50
50
 
51
+ def self.on(object, path)
52
+ self.new(path).on(object)
53
+ end
54
+
51
55
  end
@@ -4,7 +4,7 @@ describe "JsonPath" do
4
4
 
5
5
  before(:each) do
6
6
  @object = { "store"=> {
7
- "book" => [
7
+ "book" => [
8
8
  { "category"=> "reference",
9
9
  "author"=> "Nigel Rees",
10
10
  "title"=> "Sayings of the Century",
@@ -35,7 +35,6 @@ describe "JsonPath" do
35
35
  }
36
36
  }
37
37
  end
38
- #json = JsonPath.wrap(object)
39
38
 
40
39
  it "should lookup a direct path" do
41
40
  JsonPath.new('$.store.*').on(@object).to_a.first['book'].size.should == 4
@@ -49,17 +48,17 @@ describe "JsonPath" do
49
48
  @object['store']['book'][3]['author']
50
49
  ]
51
50
  end
52
-
51
+
53
52
  it "should retrieve all prices" do
54
- JsonPath.new('$..price').on(@object).to_a.should == [
53
+ JsonPath.new('$..price').on(@object).to_a.sort.should == [
55
54
  @object['store']['bicycle']['price'],
56
55
  @object['store']['book'][0]['price'],
57
56
  @object['store']['book'][1]['price'],
58
57
  @object['store']['book'][2]['price'],
59
58
  @object['store']['book'][3]['price']
60
- ]
59
+ ].sort
61
60
  end
62
-
61
+
63
62
  it "should recognize all types of array splices" do
64
63
  JsonPath.new('$..book[0:1:1]').on(@object).to_a.should == [@object['store']['book'][0], @object['store']['book'][1]]
65
64
  JsonPath.new('$..book[1::2]').on(@object).to_a.should == [@object['store']['book'][1], @object['store']['book'][3]]
@@ -67,28 +66,31 @@ describe "JsonPath" do
67
66
  JsonPath.new('$..book[:-2:2]').on(@object).to_a.should == [@object['store']['book'][0], @object['store']['book'][2]]
68
67
  JsonPath.new('$..book[2::]').on(@object).to_a.should == [@object['store']['book'][2], @object['store']['book'][3]]
69
68
  end
70
-
69
+
71
70
  it "should recognize array comma syntax" do
72
71
  JsonPath.new('$..book[0,1]').on(@object).to_a.should == [@object['store']['book'][0], @object['store']['book'][1]]
73
72
  JsonPath.new('$..book[2,-1::]').on(@object).to_a.should == [@object['store']['book'][2], @object['store']['book'][3]]
74
73
  end
75
-
74
+
76
75
  it "should support filters" do
77
76
  JsonPath.new("$..book[?(@['isbn'])]").on(@object).to_a.should == [@object['store']['book'][2], @object['store']['book'][3]]
78
77
  JsonPath.new("$..book[?(@['price'] < 10)]").on(@object).to_a.should == [@object['store']['book'][0], @object['store']['book'][2]]
79
78
  end
80
-
79
+
81
80
  it "should support eval'd array indicies" do
82
81
  JsonPath.new('$..book[(@.length-2)]').on(@object).to_a.should == [@object['store']['book'][2]]
83
82
  end
84
-
83
+
85
84
  it "should correct retrieve the right number of all nodes" do
86
85
  JsonPath.new('$..*').on(@object).to_a.size.should == 28
87
86
  end
88
-
87
+
89
88
  it "should deal with a space in the key name" do
90
89
  JsonPath.new("$.'c d'").on({"a" => "a","b" => "b", "c d" => "e"}).to_a.should == ['e']
90
+ end
91
91
 
92
+ it "should support a convenience class method" do
93
+ JsonPath.on(@object, '$..author').to_a.should == JsonPath.new('$..author').on(@object).to_a
92
94
  end
93
-
95
+
94
96
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsonpath
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 0
10
- version: 0.2.0
9
+ - 1
10
+ version: 0.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Joshua Hull
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-17 00:00:00 -07:00
18
+ date: 2011-03-19 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -66,14 +66,14 @@ dependencies:
66
66
  requirement: &id004 !ruby/object:Gem::Requirement
67
67
  none: false
68
68
  requirements:
69
- - - <
69
+ - - ~>
70
70
  - !ruby/object:Gem::Version
71
- hash: 15
71
+ hash: 27
72
72
  segments:
73
73
  - 2
74
+ - 5
74
75
  - 0
75
- - 0
76
- version: 2.0.0
76
+ version: 2.5.0
77
77
  type: :development
78
78
  version_requirements: *id004
79
79
  - !ruby/object:Gem::Dependency
@@ -101,6 +101,10 @@ extensions: []
101
101
  extra_rdoc_files:
102
102
  - README.md
103
103
  files:
104
+ - .gemtest
105
+ - .gitignore
106
+ - .rspec
107
+ - Gemfile
104
108
  - README.md
105
109
  - Rakefile
106
110
  - VERSION
@@ -110,7 +114,6 @@ files:
110
114
  - lib/jsonpath/enumerable.rb
111
115
  - lib/jsonpath/version.rb
112
116
  - spec/jsonpath_spec.rb
113
- - spec/spec.opts
114
117
  - spec/spec_helper.rb
115
118
  has_rdoc: true
116
119
  homepage: http://github.com/joshbuddy/jsonpath
@@ -148,5 +151,4 @@ specification_version: 3
148
151
  summary: Ruby implementation of http://goessner.net/articles/JsonPath/
149
152
  test_files:
150
153
  - spec/jsonpath_spec.rb
151
- - spec/spec.opts
152
154
  - spec/spec_helper.rb
data/spec/spec.opts DELETED
@@ -1,7 +0,0 @@
1
- --colour
2
- --format
3
- specdoc
4
- --loadby
5
- mtime
6
- --reverse
7
- --backtrace