gibson 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NGNhNDQ5NjU2NDZjZTdmNTI3NWFlZWYwZWY1ZDBiZDJkMjJlYTU5NQ==
5
+ data.tar.gz: !binary |-
6
+ ZTI3N2FkN2M4NmYwMWYyYmVkNjFhMDk0Y2QzYmM3NDcxMDhlOWRhMA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ NDQ2YTdlOWZjZjQwZDFlYWQ5MWFkY2JhMzkxMWQzOWU1NmFmZTBkOWFhMDFj
10
+ NmE5MDRkNGUzOWU5MjJhMThkNjY2OTg0MzRiYmZlYzA0NTU1NmVjZmE3ZWI2
11
+ ZWVlNzlhZDE5MjUzODgzMTU3MjljYTlmZDU0NDc5ZTgyNjVkZGM=
12
+ data.tar.gz: !binary |-
13
+ ZmJiNmY3NWRkMWY4ZmE4N2JmY2M4ZmJhYTQyNWFmNjhjYjNlMGUyYzUxOTQ2
14
+ MjkxNTg1NGQ5NjFmMGZlMDhkN2JjOTA5MGRjMjEzOTM5YWZiZTZmZDk4NWZj
15
+ N2IyYjZkMzk1MjU1NzkzYzhlYzBhYWRkNjMwODYyODMyODQwZmY=
data/lib/gibson/gibson.rb CHANGED
@@ -14,22 +14,32 @@ end
14
14
 
15
15
  module Gibson
16
16
  class Client
17
- ##
18
17
  # Create a new Gibson::Client instance, the options are passed to
19
18
  # Gibson::Connection initialize method.
19
+ #
20
+ # ==== Examples:
21
+ #
22
+ # Gibson::Client.new # will create a connection to the default /var/run/gibson.sock UNIX socket.
23
+ # Gibson::Client.new :address => '127.0.0.1' # will connect to localhost:10128
24
+ #
25
+ # ==== Options:
26
+ #
27
+ # - :socket - The UNIX socket path, if this option is set a UNIX socket connection will be used. Default: /var/run/gibson.sock
28
+ # - :address - The ip address to connect to, if this option is set a TCP socket connection will be used. Default: nil
29
+ # - :port - The tcp port to connect to. Default: 10128
30
+ # - :timeout - The connection and I/O timeout in milliseconds. Default: 100
31
+ # - :keepalive - If a TCP connection will be used, set this to true to use the SO_KEEPALIVE flag on the socket. Default: false
20
32
  def initialize(opts = {})
21
33
  @connection = nil
22
34
  @options = opts
23
35
  end
24
36
 
25
- ##
26
37
  # Create the connection.
27
38
  def connect
28
39
  @connection = Connection.new( @options )
29
40
  @connection.connect
30
41
  end
31
42
 
32
- ##
33
43
  # Decode a REPL_VAL reply.
34
44
  def decode_val( encoding, size, io )
35
45
  # plain string
@@ -44,7 +54,6 @@ module Gibson
44
54
  end
45
55
  end
46
56
 
47
- ##
48
57
  # Decode a REPL_KVAL reply.
49
58
  def decode_kval( io, size )
50
59
  count = io.read_unpacked 4, 'L<'
@@ -62,7 +71,6 @@ module Gibson
62
71
  obj
63
72
  end
64
73
 
65
- ##
66
74
  # Reply decoding wrapper.
67
75
  def decode( code, encoding, size, io )
68
76
  if code == Protocol::REPLIES[:val]
@@ -82,7 +90,6 @@ module Gibson
82
90
  end
83
91
  end
84
92
 
85
- ##
86
93
  # Send a query to the server given its opcode and arguments payload.
87
94
  # Return the decoded data, or raise one of the RuntimeErrors defined
88
95
  # inside Gibson::Protocol.
@@ -100,18 +107,10 @@ module Gibson
100
107
  decode code, encoding, size, StringIO.new(data)
101
108
  end
102
109
 
103
- ##
104
- # This method will be called for every undefined method call
105
- # of Gibson::Client mapping the method to its opcode and creating
106
- # its argument payload.
107
- # For instance a call to:
108
- # client = Gibson::Client.new
109
- # client.set 0, 'foo', 'bar'
110
- # Will be executed as:
111
- # client.query Protocol::COMMANDS[:set], '0 foo bar'
112
- def method_missing(name, *arguments)
113
- if Protocol::COMMANDS.has_key? name
114
- query Protocol::COMMANDS[name], arguments.join(' ')
110
+ # Map every command => opcode to an instance method.
111
+ Protocol::COMMANDS.each do |name,opcode|
112
+ define_method(name) do |*args|
113
+ query opcode, args.join(' ')
115
114
  end
116
115
  end
117
116
 
@@ -50,13 +50,13 @@ module Gibson
50
50
  }
51
51
 
52
52
  # Error code to exception map.
53
- ERRORS = {
54
- 0 => GenericError,
55
- 1 => NotFoundError,
56
- 2 => NaNError,
57
- 3 => OutOfMemoryError,
58
- 4 => LockedError
59
- }
53
+ ERRORS = [
54
+ GenericError,
55
+ NotFoundError,
56
+ NaNError,
57
+ OutOfMemoryError,
58
+ LockedError
59
+ ]
60
60
 
61
61
  # Incoming data encodings.
62
62
  ENCODINGS = {
@@ -1,4 +1,4 @@
1
1
  module Gibson
2
- VERSION = '1.0.4'
2
+ VERSION = '1.0.5'
3
3
  end
4
4
 
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gibson
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
5
- prerelease:
4
+ version: 1.0.5
6
5
  platform: ruby
7
6
  authors:
8
7
  - Simone Margaritelli
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-08-14 00:00:00.000000000 Z
11
+ date: 2013-08-18 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: High performance Gibson client for Ruby
15
14
  email: evilsocket@gmail.com
@@ -17,11 +16,11 @@ executables: []
17
16
  extensions: []
18
17
  extra_rdoc_files: []
19
18
  files:
20
- - lib/gibson.rb
21
- - lib/gibson/protocol.rb
22
19
  - lib/gibson/connection.rb
23
20
  - lib/gibson/gibson.rb
21
+ - lib/gibson/protocol.rb
24
22
  - lib/gibson/version.rb
23
+ - lib/gibson.rb
25
24
  - LICENSE
26
25
  - README.md
27
26
  - Rakefile
@@ -30,27 +29,26 @@ files:
30
29
  homepage: http://gibson-db.in/
31
30
  licenses:
32
31
  - BSD
32
+ metadata: {}
33
33
  post_install_message:
34
34
  rdoc_options:
35
35
  - --charset=UTF-8
36
36
  require_paths:
37
37
  - lib
38
38
  required_ruby_version: !ruby/object:Gem::Requirement
39
- none: false
40
39
  requirements:
41
40
  - - ! '>='
42
41
  - !ruby/object:Gem::Version
43
42
  version: '0'
44
43
  required_rubygems_version: !ruby/object:Gem::Requirement
45
- none: false
46
44
  requirements:
47
45
  - - ! '>='
48
46
  - !ruby/object:Gem::Version
49
47
  version: '0'
50
48
  requirements: []
51
49
  rubyforge_project:
52
- rubygems_version: 1.8.23
50
+ rubygems_version: 2.0.6
53
51
  signing_key:
54
- specification_version: 3
52
+ specification_version: 4
55
53
  summary: High performance Gibson client for Ruby
56
54
  test_files: []