json_stream_trigger 0.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/json_path.rb +7 -5
- data/lib/json_stream_trigger.rb +1 -1
- metadata +19 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e6d5e7c8e753631a0a8ce5dbe1d5cc78483932b
|
4
|
+
data.tar.gz: a8650c2fe960232c9268e5ef4a43d820e3999ccc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 722d61756f66fd9e4a9ff7c97af83eb43ee8294951b5c30e13231f31f78d7ae384cbfefbfd749aa2e8a0c80e15ec622f3f43b36a3b1e069c8c8c97c8ddb28ce8
|
7
|
+
data.tar.gz: a4c2939859f9fd960c803b4c3b1744babab2ef185f766f3ad4c9799c020e32e19e698605b04f91fc42a4fb9abb26198b2b913ed178b7ea71710d5035f2aceac4
|
data/lib/json_path.rb
CHANGED
@@ -1,22 +1,24 @@
|
|
1
1
|
|
2
2
|
class JsonPath
|
3
|
-
|
3
|
+
DEBUG=false
|
4
4
|
def self.matches?(path, pattern)
|
5
5
|
re = self.convert_to_re(pattern)
|
6
6
|
!path.match(re).nil?
|
7
7
|
end
|
8
8
|
|
9
|
+
|
9
10
|
def self.convert_to_re(pattern)
|
10
11
|
re = pattern.dup
|
11
12
|
re = re.gsub('[', '\[').gsub(']', '\]')# escape brackets
|
12
13
|
re.gsub!(/^\$/, '^\$') # escape $ and fix it to root
|
14
|
+
re.gsub!('.', '\.') # escape dots
|
13
15
|
re.gsub!(/ \\\[ \* \\\] /x, '\[\d+\]') # change [*] to [\d+]
|
14
|
-
re.gsub!('
|
15
|
-
re.gsub!('
|
16
|
+
re.gsub!('\.\.', '(?<=[\.\$\]]).*[\.\]]') # change .. to match a dot, $, or ] followed by anything, and ending in a . or ]
|
17
|
+
re.gsub!('\.*', '\.[^\.\[\]]+') # wild card will match any key
|
16
18
|
|
17
19
|
re += '(?=$)' #'(?=$|\.)
|
18
|
-
|
20
|
+
puts "#{pattern}\t=>\t#{re}" if DEBUG
|
21
|
+
Regexp.new(re)
|
19
22
|
end
|
20
|
-
|
21
23
|
end
|
22
24
|
|
data/lib/json_stream_trigger.rb
CHANGED
@@ -126,7 +126,7 @@ class JsonStreamTrigger
|
|
126
126
|
active_patterns = @active_buffers.keys
|
127
127
|
active_patterns.each do |pattern|
|
128
128
|
if JsonPath.matches?(@key_path, pattern)
|
129
|
-
debug "<< Calling trigger for '#{pattern}'"
|
129
|
+
debug "<< Calling trigger for '#{pattern}' when at #{@key_path}"
|
130
130
|
@triggers[pattern].call @active_buffers[pattern]
|
131
131
|
if pattern[-3..3] == '[*]'
|
132
132
|
@active_buffers[pattern] = ''
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json_stream_trigger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tyler Roberts
|
@@ -9,7 +9,21 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2016-01-12 00:00:00.000000000 Z
|
12
|
-
dependencies:
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json-stream
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
description: ''
|
14
28
|
email: code@polar-concepts.com
|
15
29
|
executables: []
|
@@ -29,17 +43,17 @@ require_paths:
|
|
29
43
|
- lib
|
30
44
|
required_ruby_version: !ruby/object:Gem::Requirement
|
31
45
|
requirements:
|
32
|
-
- -
|
46
|
+
- - ">="
|
33
47
|
- !ruby/object:Gem::Version
|
34
48
|
version: '0'
|
35
49
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
50
|
requirements:
|
37
|
-
- -
|
51
|
+
- - ">="
|
38
52
|
- !ruby/object:Gem::Version
|
39
53
|
version: '0'
|
40
54
|
requirements: []
|
41
55
|
rubyforge_project:
|
42
|
-
rubygems_version: 2.
|
56
|
+
rubygems_version: 2.5.0
|
43
57
|
signing_key:
|
44
58
|
specification_version: 4
|
45
59
|
summary: Parse large JSON files as a stream and trigger events upon key matching.
|