active_spy 1.3.8 → 1.3.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/active_spy.gemspec +3 -3
- data/app/controllers/active_spy/notifications_controller.rb +2 -2
- data/lib/active_spy/rails/base.rb +29 -12
- 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: 958e1adca6d2520d73bdbb3f5fd9533f9ac207a0
|
4
|
+
data.tar.gz: 5af7b7c09aaf6cdf2a741bcf6b07eb4953bf39a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 638d8b4b04fb4988cdfd4746a1858ad58c2c2a1956a244d3f5f8c9eae167c46d935edf3b11ed206a87c93314595d3526d1b0767d6ca377fcc396228459472c71
|
7
|
+
data.tar.gz: 47bc762bb0b25b0c1d295cc4d3f722a3f7ac2df3ae88a0c574d16efdb06e23563a14e8ed7d4a5ad3e32a8a21f293680223fecf13a31c4b089ddd470ef80b61b4
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.3.
|
1
|
+
1.3.9
|
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.9 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.9"
|
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-
|
14
|
+
s.date = "2014-10-20"
|
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 = [
|
@@ -35,7 +35,7 @@ module ActiveSpy
|
|
35
35
|
def handle_model_result(hook, result, params)
|
36
36
|
if result.errors.present?
|
37
37
|
::Rails.logger.warn("[EVENT][#{hook['post_class']}] Error receiving event #{params}")
|
38
|
-
::Rails.logger.warn("[EVENT][#{hook['post_class']}] Result errors: #{result.errors}")
|
38
|
+
::Rails.logger.warn("[EVENT][#{hook['post_class']}] Result errors: #{result.errors.full_messages}")
|
39
39
|
render json: result.errors, status: :unprocessable_entity
|
40
40
|
else
|
41
41
|
render nothing: true
|
@@ -47,7 +47,7 @@ module ActiveSpy
|
|
47
47
|
if model_with_errors.any?
|
48
48
|
::Rails.logger.warn("[EVENT][#{hook['post_class']}] Error receiving event #{params}")
|
49
49
|
model_with_errors.each do |model|
|
50
|
-
::Rails.logger.warn("[EVENT][#{hook['post_class']}] #{model} errors: #{model.errors}")
|
50
|
+
::Rails.logger.warn("[EVENT][#{hook['post_class']}] #{model} errors: #{model.errors.full_messages}")
|
51
51
|
end
|
52
52
|
render nothing: true, status: :internal_server_error
|
53
53
|
else
|
@@ -37,30 +37,47 @@ module ActiveSpy
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
#
|
41
|
-
#
|
40
|
+
# Handles the generic +save+. Determines which rail action was done,
|
41
|
+
# +create+ or +update+ and call the right callback.
|
42
42
|
#
|
43
|
-
def
|
44
|
-
|
45
|
-
|
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
|
49
|
-
remove_is_new_method(@object)
|
43
|
+
def after_save
|
44
|
+
action = get_action('save')
|
45
|
+
send("after_#{action}")
|
50
46
|
end
|
51
47
|
|
48
|
+
# Handles a +create+ callback, prepare and send the request to the event-runner.
|
49
|
+
#
|
52
50
|
def after_create
|
51
|
+
request_params = get_request_params('create')
|
52
|
+
prepare_request(request_params)
|
53
53
|
send_event_request unless ActiveSpy::Configuration.development_mode
|
54
54
|
end
|
55
55
|
|
56
|
+
# Handles an +update+ callback, prepare and send the request to the event-runner.
|
57
|
+
#
|
56
58
|
def after_update
|
59
|
+
request_params = get_request_params('update')
|
60
|
+
prepare_request(request_params)
|
57
61
|
send_event_request unless ActiveSpy::Configuration.development_mode
|
58
62
|
end
|
59
63
|
|
64
|
+
# Handles an +destroy+ callback, prepare and send the request to the event-runner.
|
65
|
+
#
|
60
66
|
def after_destroy
|
67
|
+
request_params = get_request_params('destroy')
|
68
|
+
prepare_request(request_params)
|
61
69
|
send_event_request unless ActiveSpy::Configuration.development_mode
|
62
70
|
end
|
63
71
|
|
72
|
+
# Prepare a request with +request_params+, validates the request and
|
73
|
+
# remove the injected +is_mew_method+, because it's not needed anymore.
|
74
|
+
#
|
75
|
+
def prepare_request(request_params)
|
76
|
+
@event_json = { event: request_params }.to_json
|
77
|
+
ActiveSpy::Rails::Validation::Event.new(@event_json).validate! unless ActiveSpy::Configuration.skip_validations
|
78
|
+
remove_is_new_method(@object)
|
79
|
+
end
|
80
|
+
|
64
81
|
# Sends the event request to the configured event-runner instance.
|
65
82
|
#
|
66
83
|
def send_event_request
|
@@ -81,9 +98,9 @@ module ActiveSpy
|
|
81
98
|
|
82
99
|
# Get the event request params for a given +method+.
|
83
100
|
#
|
84
|
-
def get_request_params(
|
85
|
-
real_method = method.to_s.split('_').last
|
86
|
-
action = get_action(real_method)
|
101
|
+
def get_request_params(action)
|
102
|
+
# real_method = method.to_s.split('_').last
|
103
|
+
# action = get_action(real_method)
|
87
104
|
{
|
88
105
|
type: @object.class.name,
|
89
106
|
actor: @object.instance_variable_get('@actor'),
|
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.9
|
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-
|
11
|
+
date: 2014-10-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|