jackal 0.1.2 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # v0.1.4
2
+ * Add HTTP point builder api util
3
+ * Fetch payload from message if available
4
+ * Add checks for defined error source prior to transmission
5
+
1
6
  # v0.1.2
2
7
  * Update configuration convention to require toplevel namespace
3
8
  * Clean up testing helper and setup
@@ -5,23 +5,9 @@ module Jackal
5
5
  class Callback < Carnivore::Callback
6
6
 
7
7
  include Utils::Payload
8
-
9
- # @return [Array] key path in configuration
10
- def config_path
11
- self.class.name.split('::')[0,2].map do |string|
12
- string.gsub(/(?<![A-Z])([A-Z])/, '_\1').sub(/^_/, '').downcase
13
- end
14
- end
15
-
16
- # @return [String] prefix of source for this callback
17
- def source_prefix
18
- config_path.join('_')
19
- end
20
-
21
- # @return [Hash] configuration
22
- def config
23
- Carnviore::Config.get(*config_path.push(:config)) || Smash.new
24
- end
8
+ include Utils::Config
9
+ # @!parse include Jackal::Utils::Payload
10
+ # @!parse include Jackal::Utils::Config
25
11
 
26
12
  # Validity of message
27
13
  #
@@ -58,8 +44,13 @@ module Jackal
58
44
  message.confirm!
59
45
  destination = "#{source_prefix}_error"
60
46
  source = Carnivore::Supervisor.supervisor[destination]
61
- error "Sending #{message} to error handler: #{source}"
62
- source.transmit(payload)
47
+ if(source)
48
+ error "Sending #{message} to error handler: #{source}"
49
+ source.transmit(payload)
50
+ else
51
+ error "No error source found for generated source path: #{destination}"
52
+ info "Processing of message #{message} has completed. Message now discarded."
53
+ end
63
54
  end
64
55
 
65
56
  # Mark payload complete and forward
@@ -84,7 +75,7 @@ module Jackal
84
75
  source.transmit(payload)
85
76
  else
86
77
  warn "No destination source found for generated source path: #{destination}"
87
- info "Processing of message #{message} has completed. Message now discarded."
78
+ info "Processing of message has completed. Message now discarded."
88
79
  end
89
80
  end
90
81
 
@@ -0,0 +1,34 @@
1
+ require 'jackal'
2
+
3
+ module Jackal
4
+ module Utils
5
+ module Config
6
+
7
+ # @return [Array] key path in configuration
8
+ def config_path(class_name = self.class.name)
9
+ class_name.split('::')[0,2].map do |string|
10
+ string.gsub(/(?<![A-Z])([A-Z])/, '_\1').sub(/^_/, '').downcase
11
+ end
12
+ end
13
+
14
+ # @return [String] prefix of source for this callback
15
+ def source_prefix
16
+ config_path.join('_')
17
+ end
18
+
19
+ # @return [Hash] configuration
20
+ def config
21
+ Carnivore::Config.get(*config_path.push(:config)) || Smash.new
22
+ end
23
+
24
+ # Generation destination key based on direction
25
+ #
26
+ # @param direction [Symbol, String]
27
+ # @return [Symbol]
28
+ def destination(direction = :output)
29
+ [source_prefix, direction].map(&:to_s).join('_').to_sym
30
+ end
31
+
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,26 @@
1
+ require 'jackal'
2
+
3
+ begin
4
+ require 'carnivore-http'
5
+ require 'carnivore-http/point_builder'
6
+ rescue LoadError
7
+ $stderr.puts 'The `carnivore-http` gem must be installed and available!'
8
+ raise
9
+ end
10
+
11
+ module Jackal
12
+ module Utils
13
+
14
+ # Customized point builder to provide jackal helpers
15
+ class HttpApi < Carnivore::Http::PointBuilder; end
16
+
17
+ end
18
+
19
+ end
20
+
21
+ class Carnivore::Http::PointBuilder::Endpoint
22
+ include Jackal::Utils::Payload
23
+ include Jackal::Utils::Config
24
+ # @!parse include Jackal::Utils::Payload
25
+ # @!parse include Jackal::Utils::Config
26
+ end
@@ -0,0 +1,34 @@
1
+ require 'jackal'
2
+
3
+ module Jackal
4
+ module Utils
5
+
6
+ # Payload helper utilities
7
+ module Payload
8
+
9
+ # Generate a new payload
10
+ #
11
+ # @param name [String]
12
+ # @param payload [Hash]
13
+ # @return [Smash]
14
+ def new_payload(name, payload)
15
+ Smash.new(
16
+ :name => name,
17
+ :id => Celluloid.uuid,
18
+ :data => payload
19
+ )
20
+ end
21
+
22
+ # Extract payload from message
23
+ #
24
+ # @param message [Carnivore::Message]
25
+ # @return [Smash]
26
+ def unpack(message)
27
+ msg = message[:message].to_smash
28
+ msg.fetch(:payload, msg)
29
+ end
30
+
31
+ end
32
+
33
+ end
34
+ end
data/lib/jackal/utils.rb CHANGED
@@ -5,32 +5,9 @@ module Jackal
5
5
  module Utils
6
6
 
7
7
  autoload :Spec, 'jackal/utils/spec'
8
-
9
- # Module utilities
10
- module Payload
11
-
12
- # Generate a new payload
13
- #
14
- # @param name [String]
15
- # @param payload [Hash]
16
- # @return [Smash]
17
- def new_payload(name, payload)
18
- Smash.new(
19
- :name => name,
20
- :id => Celluloid.uuid,
21
- :data => payload
22
- )
23
- end
24
-
25
- # Extract payload from message
26
- #
27
- # @param message [Carnivore::Message]
28
- # @return [Smash]
29
- def unpack(message)
30
- Smash.new(message[:message])
31
- end
32
-
33
- end
8
+ autoload :Payload, 'jackal/utils/payload'
9
+ autoload :Config, 'jackal/utils/config'
10
+ autoload :HttpApi, 'jackal/utils/http_api'
34
11
 
35
12
  extend Payload
36
13
 
@@ -1,5 +1,5 @@
1
1
  module Jackal
2
2
  class Version < Gem::Version
3
3
  end
4
- VERSION = Version.new('0.1.2')
4
+ VERSION = Version.new('0.1.4')
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jackal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-05-13 00:00:00.000000000 Z
12
+ date: 2014-06-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: carnivore
@@ -57,7 +57,10 @@ files:
57
57
  - lib/jackal/utils/spec/runner.rb
58
58
  - lib/jackal/utils/spec/helpers.rb
59
59
  - lib/jackal/utils/spec/loader.rb
60
+ - lib/jackal/utils/http_api.rb
60
61
  - lib/jackal/utils/spec.rb
62
+ - lib/jackal/utils/config.rb
63
+ - lib/jackal/utils/payload.rb
61
64
  - lib/jackal/cli.rb
62
65
  - lib/jackal/loader.rb
63
66
  - lib/jackal/error.rb