Sha256: 42afcfc50eaf5e875553ffd7c34dfce5b352d81b9926d2ebf4ca36a30dfbc99e

Contents?: true

Size: 813 Bytes

Versions: 5

Compression:

Stored size: 813 Bytes

Contents

require 'uri'

module Bunnicula
  class Rabbit
    extend Bunnicula::DslBase
    #DSL
    dsl_attr :host, :default=>"localhost"
    dsl_attr :username, :password, :default=>"guest"
    dsl_attr :vhost, :default=>"/"
    dsl_attr :port, :default=>5672


    def initialize(constr=nil)
      return unless constr
      if (constr =~ /amqp:\/\//)
        uri = URI.parse(constr)
        host uri.host
        port uri.port || 5672
        username uri.user || "guest"
        password uri.password || "guest"
        vhost uri.path.strip.length < 1 ? "/" : uri.path
      else
        host(constr)
      end
    end

    def to_h
      {
              :host=>host,
              :port=>port,
              :username=>username,
              :password=>password,
              :vhost=>vhost
      }
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
bunnicula-0.2.2 lib/bunnicula/rabbit.rb
bunnicula-0.2.1 lib/bunnicula/rabbit.rb
bunnicula-0.2.0 lib/bunnicula/rabbit.rb
bunnicula-0.1.1 lib/bunnicula/rabbit.rb
bunnicula-0.1.0 lib/bunnicula/rabbit.rb