jackal 0.3.0 → 0.3.2

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: 87d40ed9a2151a4e456b7a80a817e81856b471b5
4
- data.tar.gz: cfda4c42c5e359630c8d296c1f8be8f4fbb1956a
3
+ metadata.gz: aad960864456381c1973a63d0410dea7200be1fc
4
+ data.tar.gz: 43787842bebae529547b90613402f0f84f77eab0
5
5
  SHA512:
6
- metadata.gz: d3b2963e4f7f5ee5078665980843904fd17afd1edd04b1ff1865e6bbfa109826fb688f1a68645d0f11e8465c549337cd7450de81f578070ccd2e0477c021645b
7
- data.tar.gz: d2dc8f35b125bdf42beb18a30786d9396adcf5e67d1b17e7a059fa50a19310c8353c51555f1c30c639e7b6455e4b3f188262ff2f3b0dd27812683b55045ebb2d
6
+ metadata.gz: 3edc50f45995b3154e0c6726b85c44a41403ef3b4f7a020321a802a29a076c9ef5a7fee9af6596f15d2272fa92273d4057a9ab917ac3228720f03f270733b217
7
+ data.tar.gz: 46d2b9a99c0fac02cbd7bff500b840a778389b3484d867df4ee1d5fe3db9624a22f78c4a4baeeb422f446a3a7cbb261e982def6c3191252bc148b35fed109751
@@ -1,3 +1,6 @@
1
+ # v0.3.2
2
+ * Add support for `pre` and `post` formatters
3
+
1
4
  # v0.3.0
2
5
  * Force source looping on `Callback#completed`
3
6
  * Move HTTP hook configuration within jackal namespace
@@ -13,8 +13,10 @@ module Jackal
13
13
  include Bogo::Constants
14
14
  include Bogo::Memoization
15
15
 
16
- # @return [Array<Formatter>] formatters
16
+ # @return [Array<Formatter>] formatters applied on complete
17
17
  attr_reader :formatters
18
+ # @return [Array<Formatter>] formatters applied prior
19
+ attr_reader :pre_formatters
18
20
 
19
21
  # Create new instance
20
22
  #
@@ -22,9 +24,31 @@ module Jackal
22
24
  def initialize(*_)
23
25
  super
24
26
  if(service_config[:formatters])
25
- @formatters = service_config[:formatters].map do |klass_name|
27
+ setup_formatters
28
+ end
29
+ end
30
+
31
+ # Initialize any required formatters
32
+ #
33
+ # @return [TrueClass, FalseClass]
34
+ def setup_formatters
35
+ f_config = service_config[:formatters]
36
+ case f_config
37
+ when Hash
38
+ @formatters = f_config.fetch(:pre, []).map do |klass_name|
26
39
  constantize(klass_name).new(self)
27
40
  end
41
+ @pre_formatters = f_config.fetch(:post, []).map do |klass_name|
42
+ constantize(klass_name).new(self)
43
+ end
44
+ when Array
45
+ @formatters = f_config.map do |klass_name|
46
+ constantize(klass_name).new(self)
47
+ end
48
+ @pre_formatters = []
49
+ else
50
+ error "Formatters configuration error. Unable to process type `#{f_config.class}`."
51
+ false
28
52
  end
29
53
  end
30
54
 
@@ -137,7 +161,11 @@ module Jackal
137
161
  # @return [Smash]
138
162
  def apply_formatters!(payload)
139
163
  formatters.each do |formatter|
140
- formatter.format(payload)
164
+ begin
165
+ formatter.format(payload)
166
+ rescue => e
167
+ error "Formatter error encountered (<#{formatter}>): #{e.class} - #{e}"
168
+ end
141
169
  end
142
170
  end
143
171
 
@@ -26,7 +26,17 @@ module Jackal
26
26
  # @return [Smash]
27
27
  def unpack(message)
28
28
  msg = message[:message].to_smash
29
- msg.fetch(:payload, msg)
29
+ result = msg.fetch(:payload, msg)
30
+ if(respond_to?(:pre_formatters) && (pre_formatters && !pre_formatters.empty?))
31
+ pre_formatters.each do |formatter|
32
+ begin
33
+ formatter.format(result)
34
+ rescue => e
35
+ error "Formatter error encountered (<#{formatter}>): #{e.class} - #{e}"
36
+ end
37
+ end
38
+ end
39
+ result
30
40
  end
31
41
 
32
42
  end
@@ -1,7 +1,7 @@
1
1
  require 'multi_json'
2
2
  require 'carnivore/spec_helper'
3
3
 
4
- Celluloid.logger.level = 0 if ENV['DEBUG']
4
+ Celluloid.logger.level = ENV['DEBUG'] ? 0 : 4
5
5
 
6
6
  # Default source setup higher than base carivore default
7
7
  unless(ENV['CARNIVORE_SOURCE_SETUP'])
@@ -51,10 +51,15 @@ end
51
51
  # Configure using custom configuration JSON within config
52
52
  # directory of current test
53
53
  #
54
- # @param config [String, Symbol] name of configuration file without json extension
54
+ # @param config [String, Symbol] name of configuration file
55
55
  # @return [Thread] thread with running source
56
56
  def run_setup(config)
57
- path = File.join(Dir.pwd, 'test/specs/config', "#{config}.json")
57
+ config_dir = File.join(Dir.pwd, 'test', 'specs', 'config')
58
+ path = Dir.glob(File.join(config_dir, "#{config}*")).first
59
+
60
+ msg = "No file matching #{config} found in #{config_dir}"
61
+ raise msg unless path
62
+
58
63
  Thread.abort_on_exception = true
59
64
  runner = Thread.new do
60
65
  Jackal::Loader.run!(:config => path)
@@ -1,4 +1,4 @@
1
1
  module Jackal
2
2
  # Current library version
3
- VERSION = Gem::Version.new('0.3.0')
3
+ VERSION = Gem::Version.new('0.3.2')
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jackal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Roberts
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-26 00:00:00.000000000 Z
11
+ date: 2015-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: carnivore