delivery_boy 0.1.5 → 0.2.0.beta1

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: fd80f951111ad29fdbf5ff8bbc02aef63b59d176
4
- data.tar.gz: b9c6b8209940ef36ce24e8aec5261483100726bf
3
+ metadata.gz: cbb2e9c4ceb1a7b4cac859fa21f33eb69d43b1ba
4
+ data.tar.gz: a8c55dc6eb604a71dbdf83a8f80334693e6ec144
5
5
  SHA512:
6
- metadata.gz: ddc0d55c7acb75817794d542c1ac132292c39d466f5d65ddc969f51c57815bd8e5951d9e12aa3391263c3bfc3312f4db86e814e13c905c8c790ef19155328070
7
- data.tar.gz: 0ae524907b55be94d29b2c2849c87ea8d81ba28b80d8f94d9e0ff12822258ced4a0f9581e40e803db5557058b4ab58cf0905a5a8b01cd83e4a9883bd3fa0d00f
6
+ metadata.gz: 6cd6a9bb4def19bcf1fe9bbba80bdc70e2a8f9df0211fb8f65b776fef784e1c914114159d3e13ecb837e61e25d51356edab0fdb62b7399fc2105c5f1c359b5a8
7
+ data.tar.gz: 06dc18208a20403c71d810a8b7488a15a4aae1ad7f14fd1ec18b2bffa3703d32fc6aef28c61b78a7f522d177795b38407eb6a26e47f70b3b1101ffced3369d23
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.require_paths = ["lib"]
22
22
 
23
23
  spec.add_runtime_dependency "ruby-kafka", "~> 0.4"
24
+ spec.add_runtime_dependency "king_konf", "~> 0.1.2"
24
25
 
25
26
  spec.add_development_dependency "bundler", "~> 1.15"
26
27
  spec.add_development_dependency "rake", "~> 10.0"
@@ -70,6 +70,8 @@ module DeliveryBoy
70
70
  # @return [DeliveryBoy::Config]
71
71
  def config
72
72
  @config ||= DeliveryBoy::Config.new(env: ENV)
73
+ rescue KingKonf::ConfigError => e
74
+ raise ConfigError, e.message
73
75
  end
74
76
 
75
77
  def test_mode!
@@ -1,100 +1,26 @@
1
- require "erb"
2
- require "yaml"
3
- require "delivery_boy/env_config_loader"
4
- require "delivery_boy/config_file_loader"
5
- require "delivery_boy/config_error"
1
+ require "king_konf"
6
2
 
7
3
  module DeliveryBoy
8
- class Config
9
- VARIABLES = %w[
10
- ack_timeout
11
- brokers
12
- client_id
13
- compression_codec
14
- compression_threshold
15
- connect_timeout
16
- delivery_interval
17
- delivery_threshold
18
- max_buffer_bytesize
19
- max_buffer_size
20
- max_queue_size
21
- max_retries
22
- required_acks
23
- retry_backoff
24
- socket_timeout
25
- ssl_ca_cert
26
- ssl_client_cert
27
- ssl_client_cert_key
28
- ]
29
-
30
- DEFAULTS = {
31
- ack_timeout: 5,
32
- brokers: ["localhost:9092"],
33
- client_id: "delivery_boy",
34
- compression_threshold: 1,
35
- connect_timeout: 10,
36
- max_buffer_bytesize: 10_000_000,
37
- max_buffer_size: 1000,
38
- max_retries: 2,
39
- required_acks: :all,
40
- retry_backoff: 1,
41
- socket_timeout: 30,
42
- delivery_interval: 10,
43
- delivery_threshold: 100,
44
- max_queue_size: 1000,
45
- }
46
-
47
- attr_accessor(*VARIABLES)
48
-
49
- def initialize(env: {})
50
- load_config(DEFAULTS)
51
- load_env(env)
52
- end
53
-
54
- def load_file(path, environment)
55
- loader = ConfigFileLoader.new(self)
56
- loader.load_file(path, environment)
57
- end
58
-
59
- def set(variable, value)
60
- unless VARIABLES.include?(variable.to_s)
61
- raise ConfigError, "unknown configuration variable #{variable}"
62
- end
63
-
64
- instance_variable_set("@#{variable}", value)
65
- end
66
-
67
- private
68
-
69
- def load_config(config)
70
- config.each do |variable, value|
71
- set(variable, value)
72
- end
73
- end
74
-
75
- def load_env(env)
76
- loader = EnvConfigLoader.new(env, self)
77
-
78
- loader.string :client_id
79
- loader.string_list :brokers
80
- loader.integer :ack_timeout
81
- loader.symbol :compression_codec
82
- loader.integer :compression_threshold
83
- loader.integer :connect_timeout
84
- loader.integer :delivery_interval
85
- loader.integer :delivery_threshold
86
- loader.integer :max_buffer_bytesize
87
- loader.integer :max_buffer_size
88
- loader.integer :max_queue_size
89
- loader.integer :max_retries
90
- loader.integer :required_acks
91
- loader.integer :retry_backoff
92
- loader.integer :socket_timeout
93
- loader.string :ssl_ca_cert
94
- loader.string :ssl_client_cert
95
- loader.string :ssl_client_cert_key
96
-
97
- loader.validate!
98
- end
4
+ class Config < KingKonf::Config
5
+ prefix :delivery_boy
6
+
7
+ integer :ack_timeout, default: 5
8
+ integer :compression_threshold, default: 1
9
+ integer :connect_timeout, default: 10
10
+ integer :delivery_interval, default: 10
11
+ integer :delivery_threshold, default: 100
12
+ integer :max_buffer_bytesize, default: 10_000_000
13
+ integer :max_buffer_size, default: 1000
14
+ integer :max_queue_size, default: 1000
15
+ integer :max_retries, default: 2
16
+ integer :required_acks, default: -1
17
+ integer :retry_backoff, default: 1
18
+ integer :socket_timeout, default: 30
19
+ string :client_id, default: "delivery_boy"
20
+ string :compression_codec, default: nil
21
+ string :ssl_ca_cert, default: nil
22
+ string :ssl_client_cert, default: nil
23
+ string :ssl_client_cert_key, default: nil
24
+ list :brokers, items: :string, sep: ",", default: ["localhost:9092"]
99
25
  end
100
26
  end
@@ -2,14 +2,14 @@ module DeliveryBoy
2
2
 
3
3
  # A fake implementation that is useful for testing.
4
4
  class Fake
5
- FakeMessage = Struct.new(:value, :key, :topic, :partition, :partition_key)
5
+ FakeMessage = Struct.new(:value, :topic, :key, :partition, :partition_key)
6
6
 
7
7
  def initialize
8
8
  @messages = Hash.new {|h, k| h[k] = [] }
9
9
  end
10
10
 
11
- def deliver(value, topic:, **options)
12
- message = FakeMessage.new(value: value, topic: topic, **options)
11
+ def deliver(value, topic:, key: nil, partition: nil, partition_key: nil)
12
+ message = FakeMessage.new(value, topic, key, partition, partition_key)
13
13
  @messages[topic] << message
14
14
 
15
15
  nil
@@ -1,3 +1,3 @@
1
1
  module DeliveryBoy
2
- VERSION = "0.1.5"
2
+ VERSION = "0.2.0.beta1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delivery_boy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Schierbeck
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-12 00:00:00.000000000 Z
11
+ date: 2017-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-kafka
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: king_konf
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.1.2
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -88,8 +102,6 @@ files:
88
102
  - lib/delivery_boy.rb
89
103
  - lib/delivery_boy/config.rb
90
104
  - lib/delivery_boy/config_error.rb
91
- - lib/delivery_boy/config_file_loader.rb
92
- - lib/delivery_boy/env_config_loader.rb
93
105
  - lib/delivery_boy/fake.rb
94
106
  - lib/delivery_boy/instance.rb
95
107
  - lib/delivery_boy/railtie.rb
@@ -111,9 +123,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
111
123
  version: '0'
112
124
  required_rubygems_version: !ruby/object:Gem::Requirement
113
125
  requirements:
114
- - - ">="
126
+ - - ">"
115
127
  - !ruby/object:Gem::Version
116
- version: '0'
128
+ version: 1.3.1
117
129
  requirements: []
118
130
  rubyforge_project:
119
131
  rubygems_version: 2.4.5.1
@@ -1,20 +0,0 @@
1
- module DeliveryBoy
2
- class ConfigFileLoader
3
- def initialize(config)
4
- @config = config
5
- end
6
-
7
- def load_file(path, environment)
8
- # First, load the ERB template from disk.
9
- template = ERB.new(File.new(path).read)
10
-
11
- # The last argument to `safe_load` allows us to use aliasing to share
12
- # configuration between environments.
13
- processed = YAML.safe_load(template.result(binding), [], [], true)
14
-
15
- processed.fetch(environment).each do |variable, value|
16
- @config.set(variable, value)
17
- end
18
- end
19
- end
20
- end
@@ -1,57 +0,0 @@
1
- require "delivery_boy/config_error"
2
-
3
- module DeliveryBoy
4
- class EnvConfigLoader
5
- KEY_PREFIX = "DELIVERY_BOY"
6
-
7
- def initialize(env, config)
8
- @env = env
9
- @config = config
10
- @loaded_keys = []
11
- end
12
-
13
- def string(name)
14
- set(name) {|value| value }
15
- end
16
-
17
- def symbol(name)
18
- set(name) {|value| value.to_sym }
19
- end
20
-
21
- def integer(name)
22
- set(name) do |value|
23
- begin
24
- Integer(value)
25
- rescue ArgumentError
26
- raise ConfigError, "#{value.inspect} is not an integer"
27
- end
28
- end
29
- end
30
-
31
- def string_list(name)
32
- set(name) {|value| value.split(",") }
33
- end
34
-
35
- def validate!
36
- # Make sure the user hasn't made a typo and added a key we don't know
37
- # about.
38
- @env.keys.grep(/^#{KEY_PREFIX}_/).each do |key|
39
- unless @loaded_keys.include?(key)
40
- raise ConfigError, "unknown config variable #{key}"
41
- end
42
- end
43
- end
44
-
45
- private
46
-
47
- def set(name)
48
- key = "#{KEY_PREFIX}_#{name.upcase}"
49
-
50
- if @env.key?(key)
51
- value = yield @env.fetch(key)
52
- @config.set(name, value)
53
- @loaded_keys << key
54
- end
55
- end
56
- end
57
- end