hey-pubsub 0.0.8 → 0.1.0
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.
- checksums.yaml +4 -4
- data/lib/hey/configuration.rb +0 -1
- data/lib/hey/context.rb +1 -0
- data/lib/hey/pubsub/event.rb +2 -3
- data/lib/hey/sanitized_hash.rb +4 -2
- data/lib/hey/thread_cargo.rb +20 -24
- data/lib/hey/version.rb +1 -1
- data/lib/hey.rb +12 -7
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 590724616c1051ab959c4ac95e4a645118456819
|
4
|
+
data.tar.gz: b72160d7af916bad08377c2838928210bbc54d4f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4bb1fdfd774c144b7f9a84db60e3d406244efd9fa105333a195b6f7534511b4f0169193e3cfcf73e308856c173d4ca46f54e5c1a74fa18f38903ba53c91ee589
|
7
|
+
data.tar.gz: a04bff268858dee84d39c54400ccd1b833108b97589ded246e17c78d342c18374818b85467c04e5f338b835e92c99e1bd295d324f5c239f14b69c5aad04ec6eb
|
data/lib/hey/configuration.rb
CHANGED
data/lib/hey/context.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
class Hey::Context < OpenStruct; end
|
data/lib/hey/pubsub/event.rb
CHANGED
@@ -28,9 +28,8 @@ class Hey::Pubsub::Event
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def metadata
|
31
|
-
|
32
|
-
merged_data.
|
33
|
-
merged_data.delete(Hey::ThreadCargo::SANITIZABLE_VALUES_KEY)
|
31
|
+
context_metadata = Hey::ThreadCargo.contexts.reverse.map(&:to_h).reduce(Hash.new, :merge)
|
32
|
+
merged_data = context_metadata.merge(@metadata)
|
34
33
|
Hey::SanitizedHash.new(merged_data).to_h
|
35
34
|
end
|
36
35
|
|
data/lib/hey/sanitized_hash.rb
CHANGED
@@ -12,11 +12,13 @@ class Hey::SanitizedHash
|
|
12
12
|
attr_reader :hash
|
13
13
|
|
14
14
|
def sanitizable_values
|
15
|
-
@sanitizable_values ||= Hey::ThreadCargo.
|
15
|
+
@sanitizable_values ||= Hey::ThreadCargo.contexts.map do |context|
|
16
|
+
Array[context[Hey::SANITIZE_KEY]]
|
17
|
+
end.flatten.compact
|
16
18
|
end
|
17
19
|
|
18
20
|
def sanitize!(value)
|
19
|
-
|
21
|
+
sanitizable_values.each { |substr| value.to_s.gsub!(substr, "") }
|
20
22
|
end
|
21
23
|
|
22
24
|
def traverse(h, &block)
|
data/lib/hey/thread_cargo.rb
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
class Hey::ThreadCargo
|
2
|
-
|
3
|
-
|
4
|
-
# Sets a namespaced value on the current thread
|
5
|
-
def self.set(name, value)
|
2
|
+
def self.init!
|
6
3
|
Thread.current[:hey] = {} if Thread.current[:hey].nil?
|
7
|
-
Thread.current[:hey][
|
8
|
-
value
|
4
|
+
Thread.current[:hey][:uuid] = SecureRandom.uuid if Thread.current[:hey][:uuid].nil?
|
9
5
|
end
|
10
6
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
Thread.current[:hey][name]
|
7
|
+
def self.init_contexts!
|
8
|
+
init!
|
9
|
+
Thread.current[:hey][:contexts] = [] if Thread.current[:hey][:contexts].nil?
|
15
10
|
end
|
16
11
|
|
17
12
|
def self.uuid
|
18
|
-
|
19
|
-
|
13
|
+
init!
|
14
|
+
Thread.current[:hey][:uuid]
|
15
|
+
end
|
16
|
+
|
17
|
+
# Sets a context on the current thread
|
18
|
+
def self.add_context(context)
|
19
|
+
self.init_contexts!
|
20
|
+
Thread.current[:hey][:contexts] << context
|
20
21
|
end
|
21
22
|
|
22
|
-
#
|
23
|
-
def self.
|
24
|
-
|
25
|
-
|
26
|
-
set(SANITIZABLE_VALUES_KEY, get(SANITIZABLE_VALUES_KEY).concat(values).flatten.compact.uniq)
|
23
|
+
# Returns a context from the current thread
|
24
|
+
def self.remove_context(context)
|
25
|
+
self.init_contexts!
|
26
|
+
Thread.current[:hey][:contexts].delete(context)
|
27
27
|
end
|
28
28
|
|
29
29
|
# Removes all namespaced values from the current thread.
|
@@ -31,12 +31,8 @@ class Hey::ThreadCargo
|
|
31
31
|
Thread.current[:hey] = nil
|
32
32
|
end
|
33
33
|
|
34
|
-
def self.
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
def self.to_h
|
39
|
-
Thread.current[:hey] = {} if Thread.current[:hey].nil?
|
40
|
-
Thread.current[:hey].clone
|
34
|
+
def self.contexts
|
35
|
+
self.init_contexts!
|
36
|
+
Thread.current[:hey][:contexts]
|
41
37
|
end
|
42
38
|
end
|
data/lib/hey/version.rb
CHANGED
data/lib/hey.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
require "hey/version"
|
2
|
+
require "ostruct"
|
3
|
+
require "securerandom"
|
2
4
|
|
3
5
|
module Hey
|
6
|
+
SANITIZE_KEY = :sanitize
|
7
|
+
|
4
8
|
def self.configure
|
5
9
|
yield(configuration)
|
6
10
|
end
|
@@ -24,20 +28,21 @@ module Hey
|
|
24
28
|
pubsub_adapter.subscribe!(event_name, &block)
|
25
29
|
end
|
26
30
|
|
27
|
-
def
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
31
|
+
def context(**hash)
|
32
|
+
_context = Context.new(hash)
|
33
|
+
ThreadCargo.add_context(_context)
|
34
|
+
yield
|
35
|
+
ensure
|
36
|
+
ThreadCargo.remove_context(_context)
|
37
|
+
ThreadCargo.purge! if ThreadCargo.contexts.empty?
|
33
38
|
end
|
34
39
|
end
|
35
40
|
|
36
41
|
extend Hey::Behavior
|
37
42
|
end
|
38
43
|
|
39
|
-
require "securerandom"
|
40
44
|
require "hey/configuration"
|
45
|
+
require "hey/context"
|
41
46
|
require "hey/thread_cargo"
|
42
47
|
require "hey/sanitized_hash"
|
43
48
|
require "hey/pubsub"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hey-pubsub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ShippingEasy
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07
|
11
|
+
date: 2015-08-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -85,6 +85,7 @@ files:
|
|
85
85
|
- hey-pubsub.gemspec
|
86
86
|
- lib/hey.rb
|
87
87
|
- lib/hey/configuration.rb
|
88
|
+
- lib/hey/context.rb
|
88
89
|
- lib/hey/pubsub.rb
|
89
90
|
- lib/hey/pubsub/adapters/asn_adapter.rb
|
90
91
|
- lib/hey/pubsub/event.rb
|
@@ -111,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
112
|
version: '0'
|
112
113
|
requirements: []
|
113
114
|
rubyforge_project:
|
114
|
-
rubygems_version: 2.
|
115
|
+
rubygems_version: 2.2.2
|
115
116
|
signing_key:
|
116
117
|
specification_version: 4
|
117
118
|
summary: Pubsub wrapper with utilities to chain events, sanitize payloads and record
|