Class: Bunnicula::VampireRabbit

Inherits:
Rabbit show all
Defined in:
lib/bunnicula/vampire_rabbit.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Rabbit

#to_h

Methods included from DslBase

#dsl_attr

Constructor Details

#initialize(host = nil) ⇒ VampireRabbit

Returns a new instance of VampireRabbit.



5
6
7
8
# File 'lib/bunnicula/vampire_rabbit.rb', line 5

def initialize(host=nil)
  super(host)
  @relays = []
end

Instance Attribute Details

#relaysObject (readonly)

Returns the value of attribute relays.



3
4
5
# File 'lib/bunnicula/vampire_rabbit.rb', line 3

def relays
  @relays
end

Instance Method Details

#relay(*args, &block) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/bunnicula/vampire_rabbit.rb', line 10

def relay(*args,&block)
  options = args.extract_options!
  args = [""] if args.length == 0 && block_given?
  args.each do |from_exchange_name|
    relay = Bunnicula::Relay.new
    relay.from(from_exchange_name,options.dup)
    if block_given?
      if (block.arity > 0)
        block.call(relay)
      else
        relay.instance_eval(&block)
      end
    end
    @relays << relay
  end
end

#suck(amq) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/bunnicula/vampire_rabbit.rb', line 27

def suck(amq)
  DaemonKit.logger.info "Setting up relays to #{host}:#{port}, vhost=#{vhost} as #{username}"
  @bunny = Bunnicula::BunnyFarm.breed(:host=>host, :port=>port, :vhost=>vhost, :user=>username, :pass=>password)
  @relays.each do |relay|
    relay.start(amq,@bunny)
  end
  DaemonKit.logger.info "Let the good times roll, #{host}"
end