poller-json 0.1.6 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZWFlMmMyZjQwNmNkZjdlYjkxMTI0MmU5MDEzYjY2YWFjOWFhODcyMg==
4
+ ODM1YTM4NzhlY2NmMGZjMTJlM2Q1NGE5NmY3ZGM5ZTAyYzI4Mjg5Nw==
5
5
  data.tar.gz: !binary |-
6
- ZjA1MjE1NWRhMzNlMjBhMWJhZGM4MzFjNjhlYmJjY2NlYzMxYmQ4Yg==
6
+ ZjBkZjYzNWU3NzgwZDYzZDVjYWYyYzE4MzM4YmY1YmI3MDgwYmNlNA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- YmI1NzAzZGZjMGFlYzNiM2UxYTIyZmI1NzA4NDUyNzhlYjMzYTIwZjZhZDdm
10
- MWU5ZjQ0NmVmZWVkNTg2YWYyZTM5YTRkYmI5ZTUyNWU4MzMwN2VmYWJmM2Nl
11
- YjhhNjhlYTZkYmMxNmIwMjIwZWE0MDA4OGZjMDdlNWRiOTEyOWY=
9
+ YTgzZDQwNmE2MjZmMmM3MDE2ZDdiNTU0NDdhMjhlODYwNzllYWM1ZDAyMWIx
10
+ ZDYzYzU3ZTAxZDRmODg2NGE5ZWE3N2NhYTcxMzA3NDcyYThhNGIxZTA0YTRk
11
+ Y2U0M2E4MTE5ZjNhMDQwOGNjYzcwOGY1MDNjNDQzMjQ0NjI1NTc=
12
12
  data.tar.gz: !binary |-
13
- NzgzZjI0YmMxMTg1N2MyZmNiNDRjMWIyMjIyMzBmMTg2NjY4YjJmYWNhNjlh
14
- ZmQ0MmYxNmRhMmFjNmY5YjI4NzIwYzM2MzBlNDE0ZDhkMzRiMTExYjgwMDFh
15
- NTcwYzkzM2YzODhkMDAyYTg1MTBiN2RjMTczMTBkMDZmMmVlNDA=
13
+ ODk5ZDM1NjJlZDBkMmE4NDEyZjY4YzYwNmJiNWU2Y2ZhZTlhNzJlMzJhN2Nl
14
+ MDdmMmI3MjZiMDljOGNmNWMwZDYzZmZhYjJjYjBiZTNjYjhlNjMzYzM4OGFk
15
+ Mzk4MTI2OTU5NGM0MThkNDM3NmZjODZlY2U1N2E2NDZkZjY1MTA=
@@ -26,8 +26,7 @@ module Matchers
26
26
  end
27
27
 
28
28
  # TODO: the regular expressions below will catch very few errors
29
- def json_path_valid?(path)
30
- # TODO: figure out how groups could be extracted and then looked at individually (each do)
29
+ def json_path_valid?(path)
31
30
  notation = path.include?('[\'') ? :bracket : :dot
32
31
  path_regex = /^\$[a-zA-Z0-9_(\[\d\])\.]*[^\.]$/ if notation == :dot
33
32
  path_regex = /^\$[a-zA-Z0-9_(\[\d\])\.\']*[^\.]$/ if notation == :bracket
@@ -2,15 +2,10 @@ module Matchers
2
2
  module JSON
3
3
  class JSONPathHasArray
4
4
  include JSONPath
5
+ include JSONPathHasThing
5
6
 
6
7
  def initialize(json_path, json_array)
7
- @json_path = json_path
8
- @json_array = json_array.is_a?(Array) ? json_array : ::JSON.parse(json_array)
9
- end
10
-
11
- def matches?(document_s)
12
- json_hash = ::JSON.parse(document_s)
13
- value_on_path(json_hash, @json_path) == @json_array
8
+ super(json_path, json_array)
14
9
  end
15
10
  end
16
11
  end
@@ -2,15 +2,10 @@ module Matchers
2
2
  module JSON
3
3
  class JSONPathHasObject
4
4
  include JSONPath
5
+ include JSONPathHasThing
5
6
 
6
7
  def initialize(json_path, json_object)
7
- @json_path = json_path
8
- @json_object = json_object.is_a?(Hash) ? json_object : ::JSON.parse(json_object)
9
- end
10
-
11
- def matches?(document_s)
12
- json_hash = ::JSON.parse(document_s)
13
- value_on_path(json_hash, @json_path) == @json_object
8
+ super(json_path, json_object)
14
9
  end
15
10
  end
16
11
  end
@@ -0,0 +1,22 @@
1
+ module Matchers
2
+ module JSON
3
+ module JSONPathHasThing
4
+
5
+ def initialize(json_path, json_thing)
6
+ @json_path = json_path
7
+ @json_thing = discriminate json_thing
8
+ end
9
+
10
+ def matches?(document_s)
11
+ json_doc_hash = ::JSON.parse document_s
12
+ value_on_path(json_doc_hash, @json_path) == @json_thing
13
+ end
14
+
15
+ private
16
+ def discriminate(thing)
17
+ return thing if [Array, Hash].include? thing.class
18
+ ::JSON.parse thing
19
+ end
20
+ end
21
+ end
22
+ end
@@ -1,5 +1,5 @@
1
1
  module Poller
2
2
  module JSON
3
- VERSION = '0.1.6'
3
+ VERSION = '0.2.0'
4
4
  end
5
5
  end
@@ -2,6 +2,7 @@ require 'json'
2
2
  require 'poller'
3
3
  require 'matchers/json/json_path'
4
4
  require 'matchers/json/document_contains_json_path'
5
+ require 'matchers/json/json_path_has_thing'
5
6
  require 'matchers/json/json_path_has_value'
6
7
  require 'matchers/json/json_path_has_object'
7
8
  require 'matchers/json/json_path_has_array'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: poller-json
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Markus Krogemann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-18 00:00:00.000000000 Z
11
+ date: 2013-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: poller
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ! '>='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.4.2
19
+ version: 0.5.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ! '>='
25
25
  - !ruby/object:Gem::Version
26
- version: 0.4.2
26
+ version: 0.5.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: multi_json
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -77,6 +77,7 @@ files:
77
77
  - lib/matchers/json/json_path.rb
78
78
  - lib/matchers/json/json_path_has_array.rb
79
79
  - lib/matchers/json/json_path_has_object.rb
80
+ - lib/matchers/json/json_path_has_thing.rb
80
81
  - lib/matchers/json/json_path_has_value.rb
81
82
  - lib/poller/json/version.rb
82
83
  - lib/poller/poller_json.rb