watership 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5c575cdc499debb9ad8296a96c3ee511fdf23a6c
4
+ data.tar.gz: 2453b523d5da8d128fcc633a80f6c676ad9b9630
5
+ SHA512:
6
+ metadata.gz: 3d3e2a74ff9d30d48b6bd258d57a9eac5791e6262b9db943e7f9d2cc43d13cb91c27f5f731cf66ff4c6503005ec585f2c9dd2e8164580c5f6e473f3b3c5adcda
7
+ data.tar.gz: d01b0387d2b83d53b3b4e3289e3b25db78e6760c9fe930e4be63dc9d2b083091c5de0142c04f6a3f619a28043597827738fb148799a31c114ca618ba277c0e34
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in watership.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Ben Scofield
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # Watership
2
+
3
+ Watership is a wrapper around Bunny. It attempts to catch connection issues to the RabbitMQ server and provide a fake backend, switching back to the real backend when it becomes available.
4
+
5
+ **You shouldn't use it. It's dumb.**
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'watership'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install watership
20
+
21
+ ## Usage
22
+
23
+ This is meant for our specific use case, but if you want to give it a go....
24
+
25
+ Watership gives you channels. Instead of
26
+
27
+ client = Bunny.new([options])
28
+ channel = client.create_channel
29
+
30
+ You just do
31
+
32
+ channel = Watership::Inle.connect([options])
33
+
34
+ Watership doesn't automatically try to reconnect, but it does provide a couple of "helpful" methods:
35
+
36
+ * `Watership::Inle.ensure_connection` looks to see if you have a connection (that says it's connected), and if not will try to build one (pace some throttling). Note that the included fake client always reports that it's not connected.
37
+ * `Watership::Inle.reconnect([boolean])` calls connect with the options originally provided, but allows you to pass `true` to force a connection to the fake.
38
+
39
+ ## Naming
40
+
41
+ Inlé is the Grim Reaper of rabbits in *Watership Down*.
42
+
43
+ I always hear "rabbit" when someone refers to Welsh rarebit, so I think of it as a fake rabbit.
44
+
45
+ ## Contributing
46
+
47
+ 1. Fork it ( http://github.com/bscofield/watership/fork )
48
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
49
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
50
+ 4. Push to the branch (`git push origin my-new-feature`)
51
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,44 @@
1
+ require 'logger'
2
+ require 'bunny'
3
+
4
+ module Watership
5
+ class Inle
6
+ @connection_options = {}
7
+ @connection = nil
8
+ @channel = nil
9
+ @last_connection_attempt = nil
10
+ @retry_timer = 10
11
+
12
+ def self.connect(options = {}, fake = false)
13
+ @connection_options.merge!(options)
14
+ @last_connection_attempt = Time.now
15
+
16
+ @connection = begin
17
+ Bunny.new @connection_options
18
+ rescue Bunny::TCPConnectionFailed, Bunny::NetworkFailure
19
+ fake = true
20
+ end unless fake
21
+
22
+ @connection = Watership::Rarebit.new if fake
23
+
24
+ @connection.start
25
+ @channel = @connection.create_channel
26
+ end
27
+
28
+ def self.reconnect(fake = false)
29
+ connect({}, fake)
30
+ end
31
+
32
+ def self.ensure_connection
33
+ if !(@connection && @connection.connected?) && time_to_try_again?
34
+ connect
35
+ end
36
+
37
+ @channel
38
+ end
39
+
40
+ def self.time_to_try_again?
41
+ @last_connection_attempt.nil? || Time.now > @last_connection_attempt + @retry_timer
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,13 @@
1
+ module Watership
2
+ class Rarebit
3
+ def start; end
4
+
5
+ def connected?
6
+ false
7
+ end
8
+
9
+ def create_channel
10
+ Watership::RarebitChannel.new
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ module Watership
2
+ class RarebitChannel < Hash
3
+ def queue(*args)
4
+ self[args.first] = Watership::RarebitQueue.new
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ module Watership
2
+ class RarebitQueue < Array
3
+ def publish(payload)
4
+ self << payload
5
+ end
6
+
7
+ def pop
8
+ payload = super
9
+ return nil, {}, payload
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module Watership
2
+ VERSION = "0.0.1"
3
+ end
data/lib/watership.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "watership/version"
2
+ require "watership/rarebit_queue"
3
+ require "watership/rarebit_channel"
4
+ require "watership/rarebit"
5
+ require "watership/inle"
data/watership.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'watership/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "watership"
8
+ spec.version = Watership::VERSION
9
+ spec.authors = ["Ben Scofield"]
10
+ spec.email = ["git@turrean.com"]
11
+ spec.summary = %q{Wrapper around Bunny to better handle connection issues}
12
+ spec.description = %q{Wrapper around Bunny to better handle connection issues}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_dependency 'bunny'
25
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: watership
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ben Scofield
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bunny
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Wrapper around Bunny to better handle connection issues
56
+ email:
57
+ - git@turrean.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/watership.rb
68
+ - lib/watership/inle.rb
69
+ - lib/watership/rarebit.rb
70
+ - lib/watership/rarebit_channel.rb
71
+ - lib/watership/rarebit_queue.rb
72
+ - lib/watership/version.rb
73
+ - watership.gemspec
74
+ homepage: ''
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.2.0
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Wrapper around Bunny to better handle connection issues
98
+ test_files: []