active_spy 1.3.2 → 1.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 56617f3765e3e7026148c98c1285bec0a7e8d672
4
- data.tar.gz: 8ec5dd20bda1b57a6ccfbdb504fe55902b11f5e1
3
+ metadata.gz: 9eddbc6ab774adc7bef8293f674e5edb6543a136
4
+ data.tar.gz: 97362082bf6dcea5a8e019a659ad3431056404d2
5
5
  SHA512:
6
- metadata.gz: 57d0d785bfa03abedaff77350567b59948338a59b7f2efd05752075127671c81d1b3dedd583759c0c37430949a3de4b15f58d424ec15a1cc15e68ec7018f6e78
7
- data.tar.gz: 784ec1190721e1b8e235a7a6469bca8676758ee317cc43133e424f73a03f01576bfd9407f3c41d25edd1f5a17314bf0f024b54dd74f4b7e5e47933240155ad16
6
+ metadata.gz: d2887a5140377f86276206b62c0750aafbf13906ddfe1657c3a51dd6dc19a9b65d7895a015cc8536171b14bb92cbd7b8781ecd1b98fecd28bfa6d872af3b8a52
7
+ data.tar.gz: 3c5ef3b2fdc8a046adfccfe11aa3104719a8fcb0d7e333be1957eb28fa4f55a02150198288a84805d6f61e3a0040c14fb08640b14abc74fe3659c60382ea03e1
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.2
1
+ 1.3.3
data/active_spy.gemspec CHANGED
@@ -2,11 +2,11 @@
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.2 ruby lib
5
+ # stub: active_spy 1.3.3 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "active_spy"
9
- s.version = "1.3.2"
9
+ s.version = "1.3.3"
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"]
@@ -9,17 +9,50 @@ module ActiveSpy
9
9
  result = nil
10
10
  hooks.each do |hook|
11
11
  if hook['post_class'].downcase == params['class']
12
- listener = "#{hook['post_class']}Listener".constantize
13
- result = listener.new.handle(params['event'])
14
- if result.errors.present?
15
- Rails.logger.warn("[EVENT][#{hook['post_class']}] Error on save #{result}: #{result.errors}")
16
- render json: result.errors
17
- else
18
- render json: result
19
- end and return
12
+ handle_result and return
20
13
  end
21
14
  end
22
15
  render nothing: true, status: :not_found
23
16
  end
24
17
  end
18
+
19
+ private
20
+ def handle_result(hook, params)
21
+ result = get_result(hook, params)
22
+ if result.is_a? Array
23
+ handle_array_result(result, params)
24
+ else
25
+ handle_model_result(result, params)
26
+ end
27
+ end
28
+
29
+
30
+ def get_result(hook, params)
31
+ listener = "#{hook['post_class']}Listener".constantize
32
+ result = listener.new.handle(params['event'])
33
+ end
34
+
35
+ def handle_model_result(result, params)
36
+ if result.errors.present?
37
+ Rails.logger.warn("[EVENT][#{hook['post_class']}] Error receiving event #{params}")
38
+ Rails.logger.warn("[EVENT][#{hook['post_class']}] Listener result: #{result}")
39
+ Rails.logger.warn("[EVENT][#{hook['post_class']}] Result errors: #{result.errors}")
40
+ render json: result.errors
41
+ else
42
+ render nothing: true
43
+ end
44
+ end
45
+
46
+ def handle_array_result(result, params)
47
+ model_with_errors = result.select { |m| m.errors.present? }
48
+ if model_with_errors.any?
49
+ Rails.logger.warn("[EVENT][#{hook['post_class']}] Error receiving event #{params}")
50
+ Rails.logger.warn("[EVENT][#{hook['post_class']}] Listener result: #{result}")
51
+ model_with_errors.each do |model|
52
+ Rails.logger.warn("[EVENT][#{hook['post_class']}] #{model} errors: #{model.errors}")
53
+ end
54
+ else
55
+ render nothing: true
56
+ end
57
+ end
25
58
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_spy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.2
4
+ version: 1.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Douglas Camata