ivory_tower 0.0.1
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 +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/Guardfile +10 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/ivory_tower.gemspec +27 -0
- data/lib/ivory_tower.rb +10 -0
- data/lib/ivory_tower/bunny_factory.rb +9 -0
- data/lib/ivory_tower/consumer.rb +9 -0
- data/lib/ivory_tower/producer.rb +7 -0
- data/lib/ivory_tower/queue.rb +38 -0
- data/lib/ivory_tower/queueable.rb +12 -0
- data/lib/ivory_tower/version.rb +3 -0
- data/spec/integration/sending_a_message_spec.rb +37 -0
- data/spec/spec_helper.rb +5 -0
- data/spec/unit/bunny_factory_spec.rb +21 -0
- data/spec/unit/consumer_spec.rb +27 -0
- data/spec/unit/producer_spec.rb +19 -0
- data/spec/unit/queue_spec.rb +31 -0
- metadata +144 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 23db91d1e2d13ff02e2723c5ff4f8422b9bd7c40
|
4
|
+
data.tar.gz: e2ebc2651a9f7205aa881d031bc41d8763edf25d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 18eacee1a37f5d7f478405ade3bffdb208410b5a4141d44c9c7f1d78eb2e298aa497d3537ab33f76ac8a1ab87721a1e63ece863d84d41b83a0fecd9ad3d5fd8a
|
7
|
+
data.tar.gz: 28ad824d6a3d907b791dfd53b03df67fc315c9b328c6da972c3a4d60cb282d1589370898fdcecfe48d9a42c82d726c2e3d8520f93a09c1ddcf02c97b2943592f
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ivory-tower
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.0.0-p247
|
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard :rspec do
|
5
|
+
watch(%r{^spec/.+_spec\.rb$}) { "spec" }
|
6
|
+
watch(%r{^lib/ivory_tower/(.+)\.rb}) { |m| "spec/unit/#{m[1]}_spec.rb" }
|
7
|
+
watch(%r{^lib/ivory_tower/(.+)\.rb}) { |m| "spec/integration/*_spec.rb" }
|
8
|
+
watch('spec/spec_helper.rb') { "spec" }
|
9
|
+
end
|
10
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 ecuageo
|
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,29 @@
|
|
1
|
+
# IvoryTower
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'ivory_tower'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install ivory_tower
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/ivory_tower.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ivory_tower/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ivory_tower"
|
8
|
+
spec.version = IvoryTower::VERSION
|
9
|
+
spec.authors = ["ecuageo", "padwasabimasala"]
|
10
|
+
spec.email = ["ecuageo@gmail.com"]
|
11
|
+
spec.description = %q{Easy abstraction for working with rabbitmq}
|
12
|
+
spec.summary = %q{rabbitmq abstractions}
|
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.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_development_dependency "guard-rspec"
|
25
|
+
|
26
|
+
spec.add_dependency "bunny"
|
27
|
+
end
|
data/lib/ivory_tower.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'json'
|
2
|
+
class IvoryTower::Queue
|
3
|
+
attr_reader :name
|
4
|
+
|
5
|
+
def initialize(name)
|
6
|
+
@bunny_queue = IvoryTower::BunnyFactory.queue name
|
7
|
+
end
|
8
|
+
|
9
|
+
def consume(&block)
|
10
|
+
bunny_queue.subscribe manual_ack: true do |delivery_info, properties, body|
|
11
|
+
message = JSON.parse body
|
12
|
+
block.call(message)
|
13
|
+
channel.ack delivery_info.delivery_tag
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def produce(message)
|
18
|
+
bunny_queue.publish(message.to_json)
|
19
|
+
end
|
20
|
+
|
21
|
+
def size
|
22
|
+
bunny_queue.message_count
|
23
|
+
end
|
24
|
+
|
25
|
+
def empty!
|
26
|
+
bunny_queue.purge
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def bunny_queue
|
32
|
+
@bunny_queue
|
33
|
+
end
|
34
|
+
|
35
|
+
def channel
|
36
|
+
@bunny_queue.channel
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class AdditionProducer
|
4
|
+
include IvoryTower::Producer
|
5
|
+
|
6
|
+
end
|
7
|
+
|
8
|
+
$starting_value = 0
|
9
|
+
|
10
|
+
class AdditionConsumer
|
11
|
+
include IvoryTower::Consumer
|
12
|
+
|
13
|
+
def consume(message)
|
14
|
+
$starting_value = message["addends"].first + message["addends"].last
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'Sending a message' do
|
19
|
+
let(:addition_consumer) { AdditionConsumer.new }
|
20
|
+
|
21
|
+
it 'pushes a message onto the queue' do
|
22
|
+
p = AdditionProducer.new
|
23
|
+
queue = IvoryTower::Queue.new "Addition"
|
24
|
+
expect {
|
25
|
+
p.produce(addends: [1,3])
|
26
|
+
}.to change { queue.size }.by(1)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'changing global through the queue' do
|
30
|
+
addition_consumer.run
|
31
|
+
|
32
|
+
p = AdditionProducer.new
|
33
|
+
p.produce(addends: [1,3])
|
34
|
+
|
35
|
+
expect($starting_value).to eq 4
|
36
|
+
end
|
37
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe IvoryTower::BunnyFactory do
|
4
|
+
let(:mock_bunny) { double(:bunny) }
|
5
|
+
let(:mock_channel) { double(:channel) }
|
6
|
+
let(:mock_queue) { double(:queue) }
|
7
|
+
|
8
|
+
before :each do
|
9
|
+
expect(Bunny).to receive(:new).and_return(mock_bunny)
|
10
|
+
expect(mock_bunny).to receive(:start)
|
11
|
+
expect(mock_bunny).to receive(:create_channel).and_return(mock_channel)
|
12
|
+
expect(mock_channel).to receive(:queue).with('Modulus').and_return(mock_queue)
|
13
|
+
end
|
14
|
+
|
15
|
+
describe ".queue" do
|
16
|
+
it "queue grabs a bunny queue" do
|
17
|
+
queue = IvoryTower::BunnyFactory.queue "Modulus"
|
18
|
+
expect(queue).to eq mock_queue
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
$multiply_result = nil
|
4
|
+
|
5
|
+
class MultiplyConsumer
|
6
|
+
include IvoryTower::Consumer
|
7
|
+
|
8
|
+
def consume(message)
|
9
|
+
$multiply_result = message[:factors].first * message[:factors].last
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe IvoryTower::Consumer do
|
14
|
+
describe "#run" do
|
15
|
+
it "subscribles to the 'mulitply' queue" do
|
16
|
+
mult = MultiplyConsumer.new
|
17
|
+
|
18
|
+
mock_queue = double(:queue)
|
19
|
+
expect(IvoryTower::Queue).to receive(:new).with("Multiply").and_return(mock_queue)
|
20
|
+
expect(mock_queue).to receive(:consume).and_yield({factors: [2,4]})
|
21
|
+
|
22
|
+
mult.run
|
23
|
+
|
24
|
+
expect($multiply_result).to eq 8
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class SubtractionProducer
|
4
|
+
include IvoryTower::Producer
|
5
|
+
end
|
6
|
+
|
7
|
+
describe IvoryTower::Producer do
|
8
|
+
describe "#produce" do
|
9
|
+
it "produces to the correct queue" do
|
10
|
+
sub = SubtractionProducer.new
|
11
|
+
|
12
|
+
mock_queue = double(:queue)
|
13
|
+
expect(IvoryTower::Queue).to receive(:new).with("Subtraction").and_return(mock_queue)
|
14
|
+
expect(mock_queue).to receive(:produce).with(:message)
|
15
|
+
|
16
|
+
sub.produce(:message)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe IvoryTower::Queue do
|
4
|
+
let(:mock_queue) { double(:queue) }
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
expect(IvoryTower::BunnyFactory).to receive(:queue).and_return(mock_queue)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#consume" do
|
11
|
+
it "consume wraps rabbit subscribe" do
|
12
|
+
queue = IvoryTower::Queue.new "Modulus"
|
13
|
+
|
14
|
+
expect(mock_queue).to receive(:subscribe)
|
15
|
+
|
16
|
+
queue.consume do |message|
|
17
|
+
expect(message).to eq nil
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#publish" do
|
23
|
+
it "delegates to the rabbit queue" do
|
24
|
+
message = {operands: [4, 2]}
|
25
|
+
expect(mock_queue).to receive(:publish).with(message.to_json)
|
26
|
+
|
27
|
+
queue = IvoryTower::Queue.new "Modulus"
|
28
|
+
queue.produce(message)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ivory_tower
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ecuageo
|
8
|
+
- padwasabimasala
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-07-09 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ~>
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.3'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.3'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rspec
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: guard-rspec
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: bunny
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :runtime
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
description: Easy abstraction for working with rabbitmq
|
85
|
+
email:
|
86
|
+
- ecuageo@gmail.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- .gitignore
|
92
|
+
- .rspec
|
93
|
+
- .ruby-gemset
|
94
|
+
- .ruby-version
|
95
|
+
- Gemfile
|
96
|
+
- Guardfile
|
97
|
+
- LICENSE.txt
|
98
|
+
- README.md
|
99
|
+
- Rakefile
|
100
|
+
- ivory_tower.gemspec
|
101
|
+
- lib/ivory_tower.rb
|
102
|
+
- lib/ivory_tower/bunny_factory.rb
|
103
|
+
- lib/ivory_tower/consumer.rb
|
104
|
+
- lib/ivory_tower/producer.rb
|
105
|
+
- lib/ivory_tower/queue.rb
|
106
|
+
- lib/ivory_tower/queueable.rb
|
107
|
+
- lib/ivory_tower/version.rb
|
108
|
+
- spec/integration/sending_a_message_spec.rb
|
109
|
+
- spec/spec_helper.rb
|
110
|
+
- spec/unit/bunny_factory_spec.rb
|
111
|
+
- spec/unit/consumer_spec.rb
|
112
|
+
- spec/unit/producer_spec.rb
|
113
|
+
- spec/unit/queue_spec.rb
|
114
|
+
homepage: ''
|
115
|
+
licenses:
|
116
|
+
- MIT
|
117
|
+
metadata: {}
|
118
|
+
post_install_message:
|
119
|
+
rdoc_options: []
|
120
|
+
require_paths:
|
121
|
+
- lib
|
122
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - '>='
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
requirements: []
|
133
|
+
rubyforge_project:
|
134
|
+
rubygems_version: 2.1.10
|
135
|
+
signing_key:
|
136
|
+
specification_version: 4
|
137
|
+
summary: rabbitmq abstractions
|
138
|
+
test_files:
|
139
|
+
- spec/integration/sending_a_message_spec.rb
|
140
|
+
- spec/spec_helper.rb
|
141
|
+
- spec/unit/bunny_factory_spec.rb
|
142
|
+
- spec/unit/consumer_spec.rb
|
143
|
+
- spec/unit/producer_spec.rb
|
144
|
+
- spec/unit/queue_spec.rb
|