carnivore 0.2.16 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +3 -2
- data/carnivore.gemspec +1 -1
- data/lib/carnivore.rb +2 -3
- data/lib/carnivore/callback.rb +1 -1
- data/lib/carnivore/runner.rb +19 -0
- data/lib/carnivore/utils/smash.rb +2 -135
- data/lib/carnivore/version.rb +1 -1
- metadata +3 -4
- data/lib/carnivore/config.rb +0 -92
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95abd8e88a4967ca0085fbd0c14a5a768d0df98f
|
4
|
+
data.tar.gz: 5a34e744105ff3d482d8d98d5c2c1bba8c70a5f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f281d3203d532de93c3ff8164fd9ee25f390b82263759b6ca59a20a75c70a8ecd3a0c43aea349c3b6bfb1cb4a9b913b65aeddfff653439a8c250fda4062c8b37
|
7
|
+
data.tar.gz: c0a8cd07562ce92166f985007c6b3a053d73e10ad5055784971648d2689ffbefbb376aab6b878220ec82a5e52c1d21fa46dec34468ce20422642710b846d09bb
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -16,8 +16,9 @@ stuff gets done. Super simple!
|
|
16
16
|
3. Profit!
|
17
17
|
|
18
18
|
```ruby
|
19
|
+
require 'carnivore'
|
19
20
|
Carnivore.configure do
|
20
|
-
src = Source.build(:type => :test, :args => {})
|
21
|
+
src = Carnivore::Source.build(:type => :test, :args => {})
|
21
22
|
src.add_callback(:print_message) do |msg|
|
22
23
|
puts "Received message: #{msg}"
|
23
24
|
end
|
@@ -111,4 +112,4 @@ end.start!
|
|
111
112
|
## Info
|
112
113
|
|
113
114
|
* Repository: https://github.com/carnivore-rb/carnivore
|
114
|
-
* IRC: Freenode @ #carnivore
|
115
|
+
* IRC: Freenode @ #carnivore
|
data/carnivore.gemspec
CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.license = 'Apache 2.0'
|
12
12
|
s.require_path = 'lib'
|
13
13
|
s.add_dependency 'celluloid'
|
14
|
-
s.add_dependency '
|
14
|
+
s.add_dependency 'bogo-config'
|
15
15
|
s.add_dependency 'multi_json'
|
16
16
|
s.add_dependency 'hashie'
|
17
17
|
s.files = Dir['lib/**/*'] + %w(carnivore.gemspec README.md CHANGELOG.md)
|
data/lib/carnivore.rb
CHANGED
@@ -2,12 +2,13 @@
|
|
2
2
|
autoload :Celluloid, 'celluloid'
|
3
3
|
autoload :MultiJson, 'multi_json'
|
4
4
|
|
5
|
+
require 'bogo-cli'
|
6
|
+
require 'bogo-config'
|
5
7
|
require 'carnivore/runner'
|
6
8
|
require 'carnivore/version'
|
7
9
|
|
8
10
|
# Message consumer and processor
|
9
11
|
module Carnivore
|
10
|
-
autoload :Config, 'carnivore/config'
|
11
12
|
autoload :Callback, 'carnivore/callback'
|
12
13
|
autoload :Container, 'carnivore/container'
|
13
14
|
autoload :Error, 'carnivore/errors'
|
@@ -17,5 +18,3 @@ module Carnivore
|
|
17
18
|
autoload :Utils, 'carnivore/utils'
|
18
19
|
autoload :Version, 'carnivore/version'
|
19
20
|
end
|
20
|
-
|
21
|
-
autoload :Smash, 'carnivore/utils/smash'
|
data/lib/carnivore/callback.rb
CHANGED
@@ -70,7 +70,7 @@ module Carnivore
|
|
70
70
|
debug "Invalid message for this callback #{message})"
|
71
71
|
end
|
72
72
|
rescue => e
|
73
|
-
error "[callback: #{self}, source: #{message[:source]}, message: #{message
|
73
|
+
error "[callback: #{self}, source: #{message[:source]}, message: #{message}]: #{e.class} - #{e}"
|
74
74
|
debug "#{e.class}: #{e}\n#{e.backtrace.join("\n")}"
|
75
75
|
nil
|
76
76
|
end
|
data/lib/carnivore/runner.rb
CHANGED
@@ -3,6 +3,24 @@ require 'carnivore'
|
|
3
3
|
module Carnivore
|
4
4
|
class << self
|
5
5
|
|
6
|
+
# Sets the global configuration
|
7
|
+
#
|
8
|
+
# @param path [String] configuration file or directory
|
9
|
+
# @return [Bogo::Config]
|
10
|
+
def configure!(*args)
|
11
|
+
if(defined?(Carnivore::Config))
|
12
|
+
if(!args.include?(:verify) && !args.include?(:force))
|
13
|
+
raise 'Global configuration has already been set!'
|
14
|
+
end
|
15
|
+
if(args.include?(:force))
|
16
|
+
Carnivore.send(:remove_const, :Config)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
unless(defined?(Carnivore::Config))
|
20
|
+
Carnivore.const_set(:Config, Bogo::Config.new(args.first))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
6
24
|
# Add configuration to Carnivore
|
7
25
|
#
|
8
26
|
# @yield block of configuration
|
@@ -18,6 +36,7 @@ module Carnivore
|
|
18
36
|
supervisor = nil
|
19
37
|
begin
|
20
38
|
require 'carnivore/supervisor'
|
39
|
+
configure!(:verify)
|
21
40
|
supervisor = Carnivore::Supervisor.build!
|
22
41
|
Celluloid::Logger.info 'Initializing all registered sources.'
|
23
42
|
[].tap do |register|
|
@@ -1,136 +1,3 @@
|
|
1
|
-
require '
|
1
|
+
require 'carnivore'
|
2
2
|
|
3
|
-
|
4
|
-
module Utils
|
5
|
-
|
6
|
-
# Customized Hash
|
7
|
-
class Smash < Hash
|
8
|
-
include Hashie::Extensions::IndifferentAccess
|
9
|
-
include Hashie::Extensions::MergeInitializer
|
10
|
-
include Hashie::Extensions::DeepMerge
|
11
|
-
include Hashie::Extensions::Coercion
|
12
|
-
|
13
|
-
coerce_value Hash, Smash
|
14
|
-
|
15
|
-
# Create new instance
|
16
|
-
#
|
17
|
-
# @param args [Object] argument list
|
18
|
-
def initialize(*args)
|
19
|
-
base = nil
|
20
|
-
if(args.first.is_a?(::Hash))
|
21
|
-
base = args.shift
|
22
|
-
end
|
23
|
-
super *args
|
24
|
-
if(base)
|
25
|
-
self.replace(base.to_smash)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def merge!(hash)
|
30
|
-
hash = hash.to_smash unless hash.is_a?(::Smash)
|
31
|
-
super(hash)
|
32
|
-
end
|
33
|
-
|
34
|
-
# Get value at given path
|
35
|
-
#
|
36
|
-
# @param args [String, Symbol] key path to walk
|
37
|
-
# @return [Object, NilClass]
|
38
|
-
def retrieve(*args)
|
39
|
-
args.inject(self) do |memo, key|
|
40
|
-
if(memo.is_a?(Hash))
|
41
|
-
memo.to_smash[key]
|
42
|
-
else
|
43
|
-
nil
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
alias_method :get, :retrieve
|
48
|
-
|
49
|
-
# Fetch value at given path or return a default value
|
50
|
-
#
|
51
|
-
# @param args [String, Symbol, Object] key path to walk. last value default to return
|
52
|
-
# @return [Object] value at key or default value
|
53
|
-
def fetch(*args)
|
54
|
-
default_value = args.pop
|
55
|
-
retrieve(*args) || default_value
|
56
|
-
end
|
57
|
-
|
58
|
-
# Set value at given path
|
59
|
-
#
|
60
|
-
# @param args [String, Symbol, Object] key path to walk. set last value to given path
|
61
|
-
# @return [Object] value set
|
62
|
-
def set(*args)
|
63
|
-
unless(args.size > 1)
|
64
|
-
raise ArgumentError.new 'Set requires at least one key and a value'
|
65
|
-
end
|
66
|
-
value = args.pop
|
67
|
-
set_key = args.pop
|
68
|
-
leaf = args.inject(self) do |memo, key|
|
69
|
-
unless(memo[key].is_a?(Hash))
|
70
|
-
memo[key] = Smash.new
|
71
|
-
end
|
72
|
-
memo[key]
|
73
|
-
end
|
74
|
-
leaf[set_key] = value
|
75
|
-
value
|
76
|
-
end
|
77
|
-
|
78
|
-
# Convert to Hash
|
79
|
-
#
|
80
|
-
# @return [Hash]
|
81
|
-
def to_hash
|
82
|
-
self.to_type_converter(::Hash, :to_hash)
|
83
|
-
end
|
84
|
-
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
end
|
89
|
-
|
90
|
-
# Hook helper into toplevel `Hash`
|
91
|
-
class Hash
|
92
|
-
|
93
|
-
# Convert to Smash
|
94
|
-
#
|
95
|
-
# @return [Smash]
|
96
|
-
def to_smash
|
97
|
-
self.to_type_converter(::Smash, :to_smash)
|
98
|
-
end
|
99
|
-
alias_method :hulk_smash, :to_smash
|
100
|
-
|
101
|
-
protected
|
102
|
-
|
103
|
-
# Convert to type
|
104
|
-
#
|
105
|
-
# @param type [Class] hash type
|
106
|
-
# @param convert_call [Symbol] builtin hash convert
|
107
|
-
# @return [Smash]
|
108
|
-
def to_type_converter(type, convert_call)
|
109
|
-
type.new.tap do |smash|
|
110
|
-
self.each do |k,v|
|
111
|
-
smash[k.is_a?(Symbol) ? k.to_s : k] = smash_conversion(v, convert_call)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
# Convert object to smash if applicable
|
117
|
-
#
|
118
|
-
# @param obj [Object]
|
119
|
-
# @param convert_call [Symbol] builtin hash convert
|
120
|
-
# @return [Smash, Object]
|
121
|
-
def smash_conversion(obj, convert_call)
|
122
|
-
case obj
|
123
|
-
when Hash
|
124
|
-
obj.send(convert_call)
|
125
|
-
when Array
|
126
|
-
obj.map do |i|
|
127
|
-
smash_conversion(i, convert_call)
|
128
|
-
end
|
129
|
-
else
|
130
|
-
obj
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
end
|
135
|
-
|
136
|
-
Smash = Carnivore::Utils::Smash
|
3
|
+
Carnivore::Utils::Smash = Bogo::Smash
|
data/lib/carnivore/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: carnivore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Roberts
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: celluloid
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: bogo-config
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
@@ -77,7 +77,6 @@ files:
|
|
77
77
|
- carnivore.gemspec
|
78
78
|
- lib/carnivore.rb
|
79
79
|
- lib/carnivore/callback.rb
|
80
|
-
- lib/carnivore/config.rb
|
81
80
|
- lib/carnivore/container.rb
|
82
81
|
- lib/carnivore/errors.rb
|
83
82
|
- lib/carnivore/message.rb
|
data/lib/carnivore/config.rb
DELETED
@@ -1,92 +0,0 @@
|
|
1
|
-
require 'mixlib/config'
|
2
|
-
require 'carnivore'
|
3
|
-
|
4
|
-
module Carnivore
|
5
|
-
# Configuration helper
|
6
|
-
class Config
|
7
|
-
|
8
|
-
extend Mixlib::Config
|
9
|
-
|
10
|
-
class << self
|
11
|
-
|
12
|
-
# Set/get automatic symbolization of hash keys
|
13
|
-
#
|
14
|
-
# @param v [Object] truthy or falsey value
|
15
|
-
# @return [TrueClass, FalseClass]
|
16
|
-
# v:: Boolean value
|
17
|
-
def auto_symbolize(v=nil)
|
18
|
-
unless(v.nil?)
|
19
|
-
@hash_symbolizer = !!v
|
20
|
-
end
|
21
|
-
@hash_symbolizer.nil? ? true : @hash_symbolizer
|
22
|
-
end
|
23
|
-
|
24
|
-
# Merge provided args into configuration
|
25
|
-
#
|
26
|
-
# @param args [Hash]
|
27
|
-
# @return [self]
|
28
|
-
def configure(args)
|
29
|
-
build(args[:config_path]) if args[:config_path]
|
30
|
-
self.merge!(args)
|
31
|
-
self
|
32
|
-
end
|
33
|
-
|
34
|
-
# Populates the configuration
|
35
|
-
#
|
36
|
-
# @param path_or_hash [String, Hash] Path to JSON file or configuration hash
|
37
|
-
# @return [self]
|
38
|
-
def build(path_or_hash)
|
39
|
-
if(path_or_hash.is_a?(Hash))
|
40
|
-
conf = path_or_hash
|
41
|
-
else
|
42
|
-
if(File.directory?(path_or_hash.to_s))
|
43
|
-
files = Dir.new(path_or_hash.to_s).find_all do |f|
|
44
|
-
File.extname(f) == '.json'
|
45
|
-
end.sort
|
46
|
-
conf = files.inject(Smash.new) do |memo, path|
|
47
|
-
memo.deep_merge!(
|
48
|
-
MultiJson.load(
|
49
|
-
File.read(
|
50
|
-
File.join(
|
51
|
-
path_or_hash.to_s, path
|
52
|
-
)
|
53
|
-
)
|
54
|
-
).to_smash
|
55
|
-
)
|
56
|
-
end
|
57
|
-
self.config_path = path_or_hash
|
58
|
-
elsif(File.exists?(path_or_hash.to_s))
|
59
|
-
conf = MultiJson.load(File.read(path_or_hash))
|
60
|
-
self.config_path = path_or_hash
|
61
|
-
else
|
62
|
-
raise "Failed to load configuration file: #{path_or_hash}"
|
63
|
-
end
|
64
|
-
end
|
65
|
-
conf.each do |k,v|
|
66
|
-
self.send(k, v)
|
67
|
-
end
|
68
|
-
self
|
69
|
-
end
|
70
|
-
|
71
|
-
# Fetch value from configuration
|
72
|
-
#
|
73
|
-
# @param ary [String, Symbol] list of strings or symbols as hash path
|
74
|
-
# @return [Object] return value or nil
|
75
|
-
# @example
|
76
|
-
# Config.build(:my_app => {:port => 30})
|
77
|
-
# Config.get(:my_app, :port) => 30
|
78
|
-
# Config.get(:my_app, :host) => nil
|
79
|
-
# Config.get(:other_app, :port) => nil
|
80
|
-
# Config.get(:my_app, :mail, :server) => nil
|
81
|
-
def get(*ary)
|
82
|
-
value = Carnivore::Utils.retrieve(self, *ary)
|
83
|
-
if(value.is_a?(Hash) && auto_symbolize)
|
84
|
-
Smash.new(value)
|
85
|
-
else
|
86
|
-
value
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|