active_spy 1.3.3 → 1.3.4
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/VERSION +1 -1
- data/active_spy.gemspec +3 -3
- data/app/controllers/active_spy/notifications_controller.rb +30 -32
- data/lib/active_spy/rails/base.rb +19 -5
- data/lib/active_spy/spy/spy_list.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd8af5ef2d2ca9a598b4e4281f4294a38ca06111
|
4
|
+
data.tar.gz: 18c1075f1a80d95a0b86f6fa14394568eed58d50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5f1c15a7b3df2e3569a15171241fb15b03b24e3ee596143f9b2638f32039421eb5260d99ca3f8535f5b9ba524200689ff4e94981c53cccf554e9a49f8c328de
|
7
|
+
data.tar.gz: b993c8c2260dde7eb909e5b59f7fa1f77fb7fa01df36c235a837ba90d239efca7723e69bb2754a87eccfcf09b938144f68942e4aec981fcb8f8e298b79b50ceb
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.3.
|
1
|
+
1.3.4
|
data/active_spy.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: active_spy 1.3.
|
5
|
+
# stub: active_spy 1.3.4 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "active_spy"
|
9
|
-
s.version = "1.3.
|
9
|
+
s.version = "1.3.4"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Douglas Camata"]
|
14
|
-
s.date = "2014-08-
|
14
|
+
s.date = "2014-08-15"
|
15
15
|
s.description = " Watch for a method call in any class and run before/after callbacks.\n You can even watch your Rails models for events (like create, update,\n destroy), send these events to a event-runner instance and it redirect these\n events to other apps that are subscrived for them. This gem also provides\n classes that you can use to process the received events too.\n"
|
16
16
|
s.email = "d.camata@gmail.com"
|
17
17
|
s.extra_rdoc_files = [
|
@@ -9,50 +9,48 @@ module ActiveSpy
|
|
9
9
|
result = nil
|
10
10
|
hooks.each do |hook|
|
11
11
|
if hook['post_class'].downcase == params['class']
|
12
|
-
handle_result and return
|
12
|
+
handle_result(hook, params) and return
|
13
13
|
end
|
14
14
|
end
|
15
15
|
render nothing: true, status: :not_found
|
16
16
|
end
|
17
|
-
end
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
18
|
+
def handle_result(hook, params)
|
19
|
+
result = get_result(hook, params)
|
20
|
+
::Rails.logger.warn("[EVENT][#{hook['post_class']}] Listener result: #{result}")
|
21
|
+
if result.is_a? Array
|
22
|
+
handle_array_result(hook, result, params)
|
23
|
+
else
|
24
|
+
handle_model_result(hook, result, params)
|
25
|
+
end
|
26
26
|
end
|
27
|
-
end
|
28
27
|
|
29
28
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
29
|
+
def get_result(hook, params)
|
30
|
+
listener = "#{hook['post_class']}Listener".constantize
|
31
|
+
result = listener.new.handle(params['event'])
|
32
|
+
end
|
34
33
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
34
|
+
def handle_model_result(hook, result, params)
|
35
|
+
if result.errors.present?
|
36
|
+
::Rails.logger.warn("[EVENT][#{hook['post_class']}] Error receiving event #{params}")
|
37
|
+
::Rails.logger.warn("[EVENT][#{hook['post_class']}] Result errors: #{result.errors}")
|
38
|
+
render json: result.errors
|
39
|
+
else
|
40
|
+
render nothing: true
|
41
|
+
end
|
43
42
|
end
|
44
|
-
end
|
45
43
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
44
|
+
def handle_array_result(hook, result, params)
|
45
|
+
model_with_errors = result.select { |m| m.errors.present? }
|
46
|
+
if model_with_errors.any?
|
47
|
+
::Rails.logger.warn("[EVENT][#{hook['post_class']}] Error receiving event #{params}")
|
48
|
+
model_with_errors.each do |model|
|
49
|
+
::Rails.logger.warn("[EVENT][#{hook['post_class']}] #{model} errors: #{model.errors}")
|
50
|
+
end
|
51
|
+
else
|
52
|
+
render nothing: true
|
53
53
|
end
|
54
|
-
else
|
55
|
-
render nothing: true
|
56
54
|
end
|
57
55
|
end
|
58
56
|
end
|
@@ -41,18 +41,32 @@ module ActiveSpy
|
|
41
41
|
# after callback is not explicitly defined.
|
42
42
|
#
|
43
43
|
def method_missing(method, *_args, &_block)
|
44
|
-
|
45
|
-
|
46
|
-
|
44
|
+
request_params = get_request_params(method)
|
45
|
+
@event_json = { event: request_params }.to_json
|
46
|
+
ActiveSpy::Rails::Validation::Event.new(@event_json).validate! unless ActiveSpy::Configuration.skip_validations
|
47
|
+
after_callback = "after_#{request_params[:action]}"
|
48
|
+
send(after_callback) if respond_to? after_callback
|
47
49
|
remove_is_new_method(@object)
|
48
50
|
end
|
49
51
|
|
52
|
+
def after_create
|
53
|
+
send_event_request unless ActiveSpy::Configuration.development_mode
|
54
|
+
end
|
55
|
+
|
56
|
+
def after_update
|
57
|
+
send_event_request unless ActiveSpy::Configuration.development_mode
|
58
|
+
end
|
59
|
+
|
60
|
+
def after_destroy
|
61
|
+
send_event_request unless ActiveSpy::Configuration.development_mode
|
62
|
+
end
|
63
|
+
|
50
64
|
# Sends the event request to the configured event-runner instance.
|
51
65
|
#
|
52
|
-
def send_event_request
|
66
|
+
def send_event_request
|
53
67
|
host = ActiveSpy::Configuration.event_host
|
54
68
|
port = ActiveSpy::Configuration.event_port
|
55
|
-
RestClient.post "#{host}:#{port}/events", event_json,
|
69
|
+
RestClient.post "#{host}:#{port}/events", @event_json,
|
56
70
|
content_type: :json
|
57
71
|
end
|
58
72
|
|
@@ -16,7 +16,7 @@ module ActiveSpy
|
|
16
16
|
|
17
17
|
attr_reader :spies
|
18
18
|
|
19
|
-
# Proxy all methods called in the {ActiveSpy::SpyList} to
|
19
|
+
# Proxy all methods called in the {ActiveSpy::SpyList} class to a
|
20
20
|
# {ActiveSpy::SpyList} instance. Just a syntax sugar.
|
21
21
|
#
|
22
22
|
def self.method_missing(method, *args, &block)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_spy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Douglas Camata
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|