active_spy 1.3.3 → 1.3.4

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: 9eddbc6ab774adc7bef8293f674e5edb6543a136
4
- data.tar.gz: 97362082bf6dcea5a8e019a659ad3431056404d2
3
+ metadata.gz: bd8af5ef2d2ca9a598b4e4281f4294a38ca06111
4
+ data.tar.gz: 18c1075f1a80d95a0b86f6fa14394568eed58d50
5
5
  SHA512:
6
- metadata.gz: d2887a5140377f86276206b62c0750aafbf13906ddfe1657c3a51dd6dc19a9b65d7895a015cc8536171b14bb92cbd7b8781ecd1b98fecd28bfa6d872af3b8a52
7
- data.tar.gz: 3c5ef3b2fdc8a046adfccfe11aa3104719a8fcb0d7e333be1957eb28fa4f55a02150198288a84805d6f61e3a0040c14fb08640b14abc74fe3659c60382ea03e1
6
+ metadata.gz: b5f1c15a7b3df2e3569a15171241fb15b03b24e3ee596143f9b2638f32039421eb5260d99ca3f8535f5b9ba524200689ff4e94981c53cccf554e9a49f8c328de
7
+ data.tar.gz: b993c8c2260dde7eb909e5b59f7fa1f77fb7fa01df36c235a837ba90d239efca7723e69bb2754a87eccfcf09b938144f68942e4aec981fcb8f8e298b79b50ceb
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.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.3 ruby lib
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.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"
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
- 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)
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
- def get_result(hook, params)
31
- listener = "#{hook['post_class']}Listener".constantize
32
- result = listener.new.handle(params['event'])
33
- end
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
- 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
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
- 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}")
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
- event_json = { event: get_request_params(method) }.to_json
45
- ActiveSpy::Rails::Validation::Event.new(event_json).validate! unless ActiveSpy::Configuration.skip_validations
46
- send_event_request(event_json) unless ActiveSpy::Configuration.development_mode
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(event_json)
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.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-14 00:00:00.000000000 Z
11
+ date: 2014-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport