Module: Fraggle

Includes:
Response::Err
Defined in:
lib/fraggle.rb,
lib/fraggle/client.rb,
lib/fraggle/msg.pb.rb,
lib/fraggle/version.rb,
lib/fraggle/response.rb,
lib/fraggle/connection.rb

Defined Under Namespace

Modules: Connection Classes: Client, Request, Response

Constant Summary collapse

Clobber =
Client::MaxInt64
DEFAULT_URI =
"doozer:?" + [
  "ca=127.0.0.1:8046",
  "ca=127.0.0.1:8041",
  "ca=127.0.0.1:8042",
  "ca=127.0.0.1:8043"
].join("&")
VERSION =
"4.0.1.1"

Constants included from Response::Err

Response::Err::BAD_PATH, Response::Err::ISDIR, Response::Err::MISSING_ARG, Response::Err::NOENT, Response::Err::NOTDIR, Response::Err::OTHER, Response::Err::RANGE, Response::Err::READONLY, Response::Err::REV_MISMATCH, Response::Err::TAG_IN_USE, Response::Err::TOO_LATE, Response::Err::UNKNOWN_VERB

Class Method Summary collapse

Class Method Details

.connect(uri = nil, &blk) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/fraggle.rb', line 15

def self.connect(uri=nil, &blk)
  uri = uri || ENV["DOOZER_URI"] || DEFAULT_URI

  addrs, sk = uri(uri)

  if addrs.length == 0
    raise ArgumentError, "there were no addrs supplied in the uri (#{uri.inspect})"
  end

  addr = addrs.shift
  host, port = addr.split(":")

  cn = EM.connect(host, port, Connection, addr)
  c  = Client.new(cn, addrs)
  c.access(sk) do |_, err|
    if err
      blk.call(nil, err)
    else
      blk.call(c, nil)
    end
  end
end

.uri(u) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/fraggle.rb', line 38

def self.uri(u)
  addrs, sk = [], ""

  if u =~ /^doozer:\?(.*)$/
    parts = $1.split("&")
    parts.each do |pt|
      k, v = pt.split("=")
      case k
      when "ca"
        addrs << v
      when "sk"
        sk = v
      end
    end
  else
    raise ArgumentError, "invalid doozer uri"
  end

  [addrs, sk]
end