famoseagle-carrot 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/carrot.rb ADDED
@@ -0,0 +1,64 @@
1
+ $:.unshift File.expand_path(File.dirname(File.expand_path(__FILE__)))
2
+ require 'amqp/spec'
3
+ require 'amqp/buffer'
4
+ require 'amqp/exchange'
5
+ require 'amqp/frame'
6
+ require 'amqp/header'
7
+ require 'amqp/queue'
8
+ require 'amqp/server'
9
+ require 'amqp/protocol'
10
+
11
+ class Carrot
12
+ @logging = false
13
+ class << self
14
+ attr_accessor :logging
15
+ end
16
+ def self.logging?
17
+ @logging
18
+ end
19
+ class Error < StandardError; end
20
+
21
+ def self.queue(name, opts = {})
22
+ instance(opts).queue(name, opts)
23
+ end
24
+
25
+ def self.stop
26
+ instance.stop
27
+ end
28
+
29
+ def self.instance(opts = {})
30
+ @instance ||= new(opts)
31
+ end
32
+
33
+ def initialize(opts = {})
34
+ @server = AMQP::Server.new(opts)
35
+ end
36
+
37
+ def queue(name, opts = {})
38
+ queues[name] ||= AMQP::Queue.new(@server, name, opts)
39
+ end
40
+
41
+ def stop
42
+ @server.close
43
+ end
44
+
45
+ def queues
46
+ @queues ||= {}
47
+ end
48
+
49
+ def send_data(data)
50
+ @server.send_data(data)
51
+ end
52
+
53
+ def send_command(cmd)
54
+ @server.send_command(cmd)
55
+ end
56
+
57
+ private
58
+
59
+ def log(*args)
60
+ return unless Carrot.logging?
61
+ pp args
62
+ puts
63
+ end
64
+ end
@@ -0,0 +1,13 @@
1
+ require File.dirname(File.expand_path(__FILE__)) + '/../carrot'
2
+
3
+ #Carrot.logging = true
4
+ q = Carrot.queue('carrot', :durable => true)
5
+ 100.times do
6
+ q.publish('foo', :persistent => true)
7
+ end
8
+ puts "count: #{q.message_count}"
9
+ while msg = q.pop(:ack => true)
10
+ puts msg
11
+ q.ack
12
+ end
13
+ Carrot.stop
@@ -0,0 +1,8 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class CarrotTest < Test::Unit::TestCase
4
+
5
+ test "simple server connection" do
6
+ c = Carrot.new
7
+ end
8
+ end
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ #require 'shoulda'
4
+ require 'mocha'
5
+ require File.dirname(__FILE__) + '/../lib/carrot'
6
+
7
+ class << Test::Unit::TestCase
8
+ def test(name, &block)
9
+ test_name = "test_#{name.gsub(/[\s\W]/,'_')}"
10
+ raise ArgumentError, "#{test_name} is already defined" if self.instance_methods.include? test_name
11
+ define_method test_name, &block
12
+ end
13
+
14
+ def xtest(name, &block)
15
+ # no-op, an empty test method is defined to prevent "no tests in testcase" errors when all tests are disabled
16
+ define_method(:test_disabled) { assert true }
17
+ end
18
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: famoseagle-carrot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Amos Elliston
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-04-08 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: TODO
17
+ email: amos@geni.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - README.markdown
26
+ - VERSION.yml
27
+ - lib/amqp
28
+ - lib/amqp/buffer.rb
29
+ - lib/amqp/exchange.rb
30
+ - lib/amqp/frame.rb
31
+ - lib/amqp/header.rb
32
+ - lib/amqp/protocol.rb
33
+ - lib/amqp/queue.rb
34
+ - lib/amqp/server.rb
35
+ - lib/amqp/spec.rb
36
+ - lib/carrot.rb
37
+ - lib/examples
38
+ - lib/examples/simple_pop.rb
39
+ - test/carrot_test.rb
40
+ - test/test_helper.rb
41
+ has_rdoc: true
42
+ homepage: http://github.com/famoseagle/carrot
43
+ post_install_message:
44
+ rdoc_options:
45
+ - --inline-source
46
+ - --charset=UTF-8
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: "0"
60
+ version:
61
+ requirements: []
62
+
63
+ rubyforge_project:
64
+ rubygems_version: 1.2.0
65
+ signing_key:
66
+ specification_version: 2
67
+ summary: TODO
68
+ test_files: []
69
+