maxlapshin-carrot 0.6.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.
@@ -0,0 +1,91 @@
1
+ class Carrot
2
+ module AMQP
3
+ HEADER = "AMQP".freeze
4
+ VERSION_MAJOR = 8
5
+ VERSION_MINOR = 0
6
+ PORT = 5672
7
+ end
8
+ end
9
+
10
+ $:.unshift File.expand_path(File.dirname(File.expand_path(__FILE__)))
11
+ require 'amqp/spec'
12
+ require 'amqp/buffer'
13
+ require 'amqp/exchange'
14
+ require 'amqp/frame'
15
+ require 'amqp/header'
16
+ require 'amqp/queue'
17
+ require 'amqp/server'
18
+ require 'amqp/protocol'
19
+
20
+ class Carrot
21
+ @logging = false
22
+ class << self
23
+ attr_accessor :logging
24
+ end
25
+ def self.logging?
26
+ @logging
27
+ end
28
+ class Error < StandardError; end
29
+
30
+ attr_accessor :server
31
+
32
+ def initialize(opts = {})
33
+ @server = AMQP::Server.new(opts)
34
+ end
35
+
36
+ def queue(name, opts = {})
37
+ queues[name] ||= AMQP::Queue.new(self, name, opts)
38
+ end
39
+
40
+ def stop
41
+ server.close
42
+ end
43
+
44
+ def queues
45
+ @queues ||= {}
46
+ end
47
+
48
+ def direct(name = 'amq.direct', opts = {})
49
+ exchanges[name] ||= AMQP::Exchange.new(self, :direct, name, opts)
50
+ end
51
+
52
+ def topic(name = 'amq.topic', opts = {})
53
+ exchanges[name] ||= AMQP::Exchange.new(self, :topic, name, opts)
54
+ end
55
+
56
+ def fanout(name = 'amq.fanout', opts = {})
57
+ exchanges[name] ||= AMQP::Exchange.new(self, :fanout, name, opts)
58
+ end
59
+
60
+ def headers(name = 'amq.match', opts = {})
61
+ exchanges[name] ||= AMQP::Exchange.new(self, :headers, name, opts)
62
+ end
63
+
64
+ def exchanges
65
+ @exchanges ||= {}
66
+ end
67
+
68
+ private
69
+
70
+ def log(*args)
71
+ return unless Carrot.logging?
72
+ pp args
73
+ puts
74
+ end
75
+ end
76
+
77
+ #-- convenience wrapper (read: HACK) for thread-local Carrot object
78
+
79
+ class Carrot
80
+ def Carrot.default
81
+ #-- XXX clear this when connection is closed
82
+ Thread.current[:carrot] ||= Carrot.new
83
+ end
84
+
85
+ # Allows for calls to all Carrot instance methods. This implicitly calls
86
+ # Carrot.new so that a new channel is allocated for subsequent operations.
87
+ def Carrot.method_missing(meth, *args, &blk)
88
+ Carrot.default.__send__(meth, *args, &blk)
89
+ end
90
+
91
+ 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: maxlapshin-carrot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.0
5
+ platform: ruby
6
+ authors:
7
+ - Amos Elliston
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-04-22 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
+