huck 0.2.1 → 0.2.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a79a3c9c263d302401491186d5ab0bd97a3ce51c
4
- data.tar.gz: 600ea4d99d5c905796abbe425060e27e43cba421
3
+ metadata.gz: ab41afdccbfa3acca2682260a3f767f81df16c98
4
+ data.tar.gz: 10c43b6f14370e182b92354ab802f564d292262b
5
5
  SHA512:
6
- metadata.gz: d96f236417d31c5af714c20814cf95f3a11a8b266b68f8f879464218af21df3957fd3af53dab536079ff2865d023da3e9f6489f5b1525064c63569e82bb69379
7
- data.tar.gz: ca82f5ca5ddd75d8c4a67e6cb45e9e059a01e9ad5055bcd4d562183889a81f02824e942c198f86e8de891a7c802fe53468c500450920c06e76a7e8bf76791533
6
+ metadata.gz: ae7aca31731c943519ec239dad61b262ee2ee7a4641a66b37b39748f544730a4fb3395bd83e008c200329a37fda09bd82420902a2bb2fd0e88770fec4efcb410
7
+ data.tar.gz: 461a94e2f90cb3ecd96594065d20bcbad9f96552fadbbb58fcc1e8ad28751ec663cfb95a69d67991ac29bd8e3612efd12ab8447be4676218fea2e08902c50894
data/bin/huck CHANGED
@@ -6,15 +6,15 @@ begin
6
6
  options = Hash.new
7
7
  OptionParser.new do |opts|
8
8
  opts.on '-c [path]' do |v|
9
- options[:config] = v
9
+ options[:config_file] = v
10
10
  end
11
11
  end.parse!
12
12
 
13
13
  case ARGV[0]
14
14
  when 'run'
15
- Huck.run :config => options[:config]
15
+ Huck.run :config_file => options[:config_file]
16
16
  when 'serve'
17
- Huck.serve :config => options[:config]
17
+ Huck.serve :config_file => options[:config_file]
18
18
  else
19
19
  puts <<EOF
20
20
  Usage: huck <run|serve>
data/lib/huck/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Huck
2
- Version = '0.2.1'
2
+ Version = '0.2.2'
3
3
  end
data/lib/huck.rb CHANGED
@@ -30,8 +30,11 @@ module Huck
30
30
  # The name of the sender to use
31
31
  #
32
32
  def self.run kwargs = {}
33
- conf_file = Huck::getarg kwargs, :config, nil
34
- config = Huck::config :path => conf_file
33
+ config = Huck::getarg kwargs, :config, nil
34
+ if config.nil?
35
+ conf_file = Huck::getarg kwargs, :config_file, nil
36
+ config = Huck::config :path => conf_file
37
+ end
35
38
 
36
39
  if config.has_key? 'generator'
37
40
  gen_name = config['generator']
@@ -50,15 +53,20 @@ module Huck
50
53
  s.send g.dump
51
54
  end
52
55
 
53
- # Main method to receive messages from a Huck client
56
+ # Main method to receive messages from a Huck client. If a block is given, the
57
+ # block will be used as the handler code. Otherwise, the configured handler
58
+ # or default handler will be used.
54
59
  #
55
60
  # == Parameters:
56
61
  # receiver::
57
62
  # The receiver to use (default=sqs)
58
63
  #
59
64
  def self.serve kwargs = {}
60
- conf_file = Huck::getarg kwargs, :config, nil
61
- config = Huck::config :path => conf_file
65
+ config = Huck::getarg kwargs, :config, nil
66
+ if config.nil?
67
+ conf_file = Huck::getarg kwargs, :config_file, nil
68
+ config = Huck::config :path => conf_file
69
+ end
62
70
 
63
71
  if config.has_key? 'handler'
64
72
  hand_name = config['handler']
@@ -76,9 +84,9 @@ module Huck
76
84
 
77
85
  begin
78
86
  r.receive do |msg|
79
- h.handle msg
87
+ block_given? ? yield(msg) : h.handle(msg)
80
88
  end
81
- rescue Interrupt, SystemExit
89
+ rescue Interrupt, SystemExit, IRB::Abort
82
90
  return
83
91
  end
84
92
  end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Huck Configuration' do
4
+ it 'should read the proper default config file' do
5
+ path = File.join Dir.home, 'huck.conf'
6
+ if !File.exist? path
7
+ f = File.open path, 'w'
8
+ f.write '{"test": "config"}'
9
+ f.close
10
+ end
11
+ expect(Huck.config).not_to be_empty
12
+ File.delete f.path if f
13
+ end
14
+
15
+ it 'should accept an alternate config file path' do
16
+ file = mktempfile "test: config\n"
17
+ expect(Huck.config :path => file).to eq({'test' => 'config'})
18
+ end
19
+ end
20
+
21
+ describe 'Module Loading' do
22
+ it 'should return true when module is loaded' do
23
+ expect(Huck::try_load 'yaml').to be true
24
+ end
25
+
26
+ it 'should return false when module cannot be loaded' do
27
+ expect(Huck::try_load 'nonexistent').to be false
28
+ end
29
+
30
+ it 'should not raise when module is loaded' do
31
+ expect{Huck::must_load 'yaml'}.not_to raise_error
32
+ end
33
+
34
+ it 'should raise a RuntimeError when module cannot be loaded' do
35
+ expect{Huck::must_load 'nonexistent'}.to raise_error(RuntimeError)
36
+ end
37
+ end
@@ -0,0 +1,17 @@
1
+ require 'simplecov'
2
+ require 'tempfile'
3
+ require 'tmpdir'
4
+
5
+ SimpleCov.formatter = SimpleCov::Formatter::HTMLFormatter
6
+ SimpleCov.start do
7
+ add_filter '/spec/'
8
+ end
9
+
10
+ require 'huck'
11
+
12
+ def mktempfile content
13
+ f = Tempfile.new 'huck'
14
+ f.write content
15
+ f.close
16
+ f.path
17
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: huck
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Uber
@@ -59,24 +59,25 @@ executables:
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
- - lib/huck/generators/ohai.rb
63
- - lib/huck/generators/facter.rb
62
+ - bin/huck
63
+ - lib/huck/generator.rb
64
64
  - lib/huck/generators/basic.rb
65
- - lib/huck/generators/yaml.rb
65
+ - lib/huck/generators/facter.rb
66
66
  - lib/huck/generators/json.rb
67
- - lib/huck/senders/sqs.rb
67
+ - lib/huck/generators/ohai.rb
68
+ - lib/huck/generators/yaml.rb
69
+ - lib/huck/handler.rb
70
+ - lib/huck/handlers/echo.rb
71
+ - lib/huck/handlers/exec.rb
68
72
  - lib/huck/receiver.rb
73
+ - lib/huck/receivers/sqs.rb
69
74
  - lib/huck/sender.rb
75
+ - lib/huck/senders/sqs.rb
70
76
  - lib/huck/util.rb
71
- - lib/huck/generator.rb
72
- - lib/huck/receivers/sqs.rb
73
- - lib/huck/handlers/exec.rb
74
- - lib/huck/handlers/echo.rb
75
77
  - lib/huck/version.rb
76
- - lib/huck/handler.rb
77
78
  - lib/huck.rb
78
- - bin/huck
79
- - spec/huck/huck_spec.rb
79
+ - spec/huck/util_spec.rb
80
+ - spec/spec_helper.rb
80
81
  homepage: https://github.com/ryanuber/huck
81
82
  licenses:
82
83
  - MIT
@@ -97,9 +98,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
98
  version: '0'
98
99
  requirements: []
99
100
  rubyforge_project:
100
- rubygems_version: 2.1.11
101
+ rubygems_version: 2.0.14
101
102
  signing_key:
102
103
  specification_version: 4
103
104
  summary: Information sharing framework
104
105
  test_files:
105
- - spec/huck/huck_spec.rb
106
+ - spec/huck/util_spec.rb
107
+ - spec/spec_helper.rb
@@ -1,9 +0,0 @@
1
- require 'huck'
2
- require 'aws-sdk'
3
- #AWS::Stub!
4
-
5
- describe 'Running Huck Client' do
6
- it 'should run the client without errors' do
7
- Huck.run
8
- end
9
- end