hutch 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +16 -1
- data/lib/hutch/cli.rb +11 -2
- data/lib/hutch/config.rb +9 -0
- data/lib/hutch/logging.rb +1 -1
- data/lib/hutch/version.rb +1 -1
- data/spec/hutch/cli_spec.rb +32 -0
- data/spec/hutch/config_spec.rb +31 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7796c2e714b41d75ba0dac9b55b51e2aa45e2c44
|
4
|
+
data.tar.gz: 53e10daaf146ea25c39b374249040e0a2eb3281b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 864361f79c19d277caaa6fada23e6a9b8dd750b7731e279a6ffc95d06f2bacd239e8cdffb62cb7e3dbb8caf3e1c0f06df2bf72da91b8a33cf1d29af6dd0e74df
|
7
|
+
data.tar.gz: 5b00698982dfb82b7a837d7207c79e9afd84fdfdceca3804cd60b0d9a7e231186d12ef5a8c0a4a5d42582902eebc40956105a37aff8fe51742c5401aa0824377
|
data/README.md
CHANGED
@@ -102,6 +102,8 @@ usage: hutch [options]
|
|
102
102
|
--mq-api-host HOST Set the RabbitMQ API host
|
103
103
|
--mq-api-port PORT Set the RabbitMQ API port
|
104
104
|
--mq-api-ssl Use SSL for the RabbitMQ API
|
105
|
+
--config FILE Load Hutch configuration from a file
|
106
|
+
|
105
107
|
--require PATH Require a Rails app or path
|
106
108
|
-q, --quiet Quiet logging
|
107
109
|
-v, --verbose Verbose logging
|
@@ -110,7 +112,20 @@ usage: hutch [options]
|
|
110
112
|
```
|
111
113
|
|
112
114
|
The first three are for configuring which RabbitMQ instance to connect to.
|
113
|
-
`--require` is covered in the next section.
|
115
|
+
`--require` is covered in the next section. Configurations can also be
|
116
|
+
specified in a YAML file for convenience by passing the file location
|
117
|
+
to the --config option. The file should look like:
|
118
|
+
|
119
|
+
```yaml
|
120
|
+
mq_username: peter
|
121
|
+
mq_password: rabbit
|
122
|
+
mq_host: broker.yourhost.com
|
123
|
+
```
|
124
|
+
|
125
|
+
Passing a setting as a command-line option will overwrite what's specified
|
126
|
+
in the config file, allowing for easy customization.
|
127
|
+
|
128
|
+
|
114
129
|
|
115
130
|
### Loading Consumers
|
116
131
|
|
data/lib/hutch/cli.rb
CHANGED
@@ -2,6 +2,7 @@ require 'optparse'
|
|
2
2
|
|
3
3
|
require 'hutch/logging'
|
4
4
|
require 'hutch/exceptions'
|
5
|
+
require 'hutch/config'
|
5
6
|
|
6
7
|
module Hutch
|
7
8
|
class CLI
|
@@ -84,7 +85,7 @@ module Hutch
|
|
84
85
|
:error
|
85
86
|
end
|
86
87
|
|
87
|
-
def parse_options
|
88
|
+
def parse_options(args = ARGV)
|
88
89
|
OptionParser.new do |opts|
|
89
90
|
opts.banner = 'usage: hutch [options]'
|
90
91
|
|
@@ -131,6 +132,14 @@ module Hutch
|
|
131
132
|
Hutch::Config.mq_api_ssl = api_ssl
|
132
133
|
end
|
133
134
|
|
135
|
+
opts.on('--config FILE', 'Load Hutch configuration from a file') do |file|
|
136
|
+
begin
|
137
|
+
File.open(file) { |fp| Hutch::Config.load_from_file(fp) }
|
138
|
+
rescue Errno::ENOENT
|
139
|
+
abort "Config file '#{file}' not found"
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
134
143
|
opts.on('--require PATH', 'Require a Rails app or path') do |path|
|
135
144
|
Hutch::Config.require_paths << path
|
136
145
|
end
|
@@ -156,7 +165,7 @@ module Hutch
|
|
156
165
|
puts opts
|
157
166
|
exit 0
|
158
167
|
end
|
159
|
-
end.parse!
|
168
|
+
end.parse!(args)
|
160
169
|
end
|
161
170
|
end
|
162
171
|
end
|
data/lib/hutch/config.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
|
+
require 'hutch/error_handlers/logger'
|
1
2
|
require 'logger'
|
2
3
|
|
3
4
|
module Hutch
|
4
5
|
class UnknownAttributeError < StandardError; end
|
5
6
|
|
6
7
|
module Config
|
8
|
+
require 'yaml'
|
9
|
+
|
7
10
|
def self.initialize
|
8
11
|
@config = {
|
9
12
|
mq_host: 'localhost',
|
@@ -49,6 +52,12 @@ module Hutch
|
|
49
52
|
@config
|
50
53
|
end
|
51
54
|
|
55
|
+
def self.load_from_file(file)
|
56
|
+
YAML.load(file).each do |attr, value|
|
57
|
+
Hutch::Config.send("#{attr}=", value)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
52
61
|
def self.method_missing(method, *args, &block)
|
53
62
|
attr = method.to_s.sub(/=$/, '').to_sym
|
54
63
|
return super unless user_config.key?(attr)
|
data/lib/hutch/logging.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'logger'
|
2
2
|
require 'time'
|
3
|
-
require 'hutch/config'
|
4
3
|
|
5
4
|
module Hutch
|
6
5
|
module Logging
|
@@ -11,6 +10,7 @@ module Hutch
|
|
11
10
|
end
|
12
11
|
|
13
12
|
def self.setup_logger(target = $stdout)
|
13
|
+
require 'hutch/config'
|
14
14
|
@logger = Logger.new(target)
|
15
15
|
@logger.level = Hutch::Config.log_level
|
16
16
|
@logger.formatter = HutchFormatter.new
|
data/lib/hutch/version.rb
CHANGED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'hutch/cli'
|
2
|
+
require 'tempfile'
|
3
|
+
|
4
|
+
describe Hutch::CLI do
|
5
|
+
let(:cli) { Hutch::CLI.new }
|
6
|
+
|
7
|
+
describe "#parse_options" do
|
8
|
+
context "--config" do
|
9
|
+
context "when the config file does not exist" do
|
10
|
+
let(:file) { "/path/to/nonexistant/file" }
|
11
|
+
before { STDERR.stub(:write) }
|
12
|
+
|
13
|
+
it "bails" do
|
14
|
+
expect {
|
15
|
+
cli.parse_options(["--config=#{file}"])
|
16
|
+
}.to raise_error SystemExit
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "when the config file exists" do
|
21
|
+
let(:file) do
|
22
|
+
Tempfile.new("hutch-test-config.yaml").to_path
|
23
|
+
end
|
24
|
+
|
25
|
+
it "parses the config" do
|
26
|
+
Hutch::Config.should_receive(:load_from_file)
|
27
|
+
cli.parse_options(["--config=#{file}"])
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/spec/hutch/config_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'hutch/config'
|
2
|
+
require 'tempfile'
|
2
3
|
|
3
4
|
describe Hutch::Config do
|
4
5
|
let(:new_value) { 'not-localhost' }
|
@@ -66,4 +67,34 @@ describe Hutch::Config do
|
|
66
67
|
specify { invalid_setter.should raise_error NoMethodError }
|
67
68
|
end
|
68
69
|
end
|
70
|
+
|
71
|
+
describe '.load_from_file' do
|
72
|
+
let(:host) { 'broker.yourhost.com' }
|
73
|
+
let(:username) { 'calvin' }
|
74
|
+
let(:file) do
|
75
|
+
Tempfile.new('configs.yaml').tap do |t|
|
76
|
+
t.write(YAML.dump(config_data))
|
77
|
+
t.rewind
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context 'when an attribute is invalid' do
|
82
|
+
let(:config_data) { { random_attribute: 'socks' } }
|
83
|
+
it 'raises an error' do
|
84
|
+
expect {
|
85
|
+
Hutch::Config.load_from_file(file)
|
86
|
+
}.to raise_error(NoMethodError)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context 'when attributes are valid' do
|
91
|
+
let(:config_data) { { mq_host: host, mq_username: username } }
|
92
|
+
|
93
|
+
it 'loads in the config data' do
|
94
|
+
Hutch::Config.load_from_file(file)
|
95
|
+
Hutch::Config.mq_host.should eq host
|
96
|
+
Hutch::Config.mq_username.should eq username
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
69
100
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hutch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Harry Marr
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-09
|
11
|
+
date: 2013-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bunny
|
@@ -100,6 +100,7 @@ files:
|
|
100
100
|
- lib/hutch/version.rb
|
101
101
|
- lib/hutch/worker.rb
|
102
102
|
- spec/hutch/broker_spec.rb
|
103
|
+
- spec/hutch/cli_spec.rb
|
103
104
|
- spec/hutch/config_spec.rb
|
104
105
|
- spec/hutch/consumer_spec.rb
|
105
106
|
- spec/hutch/error_handlers/logger_spec.rb
|
@@ -135,6 +136,7 @@ specification_version: 4
|
|
135
136
|
summary: Easy inter-service communication using RabbitMQ.
|
136
137
|
test_files:
|
137
138
|
- spec/hutch/broker_spec.rb
|
139
|
+
- spec/hutch/cli_spec.rb
|
138
140
|
- spec/hutch/config_spec.rb
|
139
141
|
- spec/hutch/consumer_spec.rb
|
140
142
|
- spec/hutch/error_handlers/logger_spec.rb
|