gio-redis 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 52f7795d1fcb334f1b765925b960e4d9915fe462
4
+ data.tar.gz: 4a8086109f8c8a89a4f932693d4004eb9c0c7376
5
+ SHA512:
6
+ metadata.gz: 8f62e8485ca8ea1e3c464f3e013830bf583e32bf3e75236abbb8615fc3d5893b1cab14ee3f7e94df727bc7b30175dd3cc0964d41c1d7dbc4e38be1178e9b87ca
7
+ data.tar.gz: 84180211093a88517bbd2cdc12d3abef2c03b18a058f4cba4965b912ee4662f4971220c8bb1c57424b5aa7043cbb6ce54c66dd3fdce181e0abe7d1aec219e1d2
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gio-redis.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,23 @@
1
+ Copyright (c) 2013 Geoff Youngs
2
+
3
+
4
+ MIT License
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining
7
+ a copy of this software and associated documentation files (the
8
+ "Software"), to deal in the Software without restriction, including
9
+ without limitation the rights to use, copy, modify, merge, publish,
10
+ distribute, sublicense, and/or sell copies of the Software, and to
11
+ permit persons to whom the Software is furnished to do so, subject to
12
+ the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be
15
+ included in all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # Gio::Redis
2
+
3
+ Simple library for using Redis pub/sub from the a Gtk application
4
+ with mainloop integration.
5
+
6
+ Uses the gio2 library for transport/event loop integration and the
7
+ hiredis library for message parsing.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'gio-redis'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install gio-redis
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Contributing
28
+
29
+ 1. Fork it
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
32
+ 4. Push to the branch (`git push origin my-new-feature`)
33
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/gio-redis.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gio/redis/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gio-redis"
8
+ spec.version = Gio::Redis::VERSION
9
+ spec.authors = ["Geoff Youngs\n"]
10
+ spec.email = ["git@intersect-uk.co.uk"]
11
+ spec.description = %q{Minimal Redis message client for use with the Ruby-GNOME2 gio2 bindings.}
12
+ spec.summary = %q{gio2 based redis pub/sub listener}
13
+ spec.homepage = "http://github.com/geoffyoungs/gio-redis"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'hiredis'
22
+ spec.add_dependency 'gio2'
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "gtk2"
26
+ end
@@ -0,0 +1,5 @@
1
+ module Gio
2
+ class Redis
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
data/lib/gio/redis.rb ADDED
@@ -0,0 +1,85 @@
1
+ require "gio/redis/version"
2
+ require 'gio2'
3
+ require 'hiredis/reader'
4
+
5
+ module Gio
6
+ class Redis
7
+ # Your code goes here...
8
+ def initialize(host = '127.0.0.1', port = 6379, mainloop = nil)
9
+
10
+ @addr = Gio::InetSocketAddress.new(Gio::InetAddress.new_from_string(host), port)
11
+ @sock = Gio::Socket.new(:ipv4, :stream, :tcp)
12
+
13
+ @sock.connect(@addr)
14
+ @sock.set_blocking(false)
15
+
16
+ @reader = Hiredis::Reader.new
17
+
18
+ @source = @sock.create_source(GLib::IOCondition::IN, &method(:read_response))
19
+ @source.attach
20
+ @pong = false
21
+ @callbacks = {}
22
+ call_command 'PING'
23
+ end
24
+
25
+ def pong?
26
+ @pong
27
+ end
28
+
29
+ def subscribe(channel, &block)
30
+ (@callbacks[channel] ||= []) << block
31
+ call_command("SUBSCRIBE", channel)
32
+ end
33
+
34
+ def unsubscribe(channel)
35
+ @callbacks.delete(channel)
36
+ call_command("UNSUBSCRIBE", channel)
37
+ end
38
+
39
+ def poll
40
+ read_response
41
+ end
42
+
43
+ private
44
+ def call_command(*args)
45
+ command = "*#{args.size}\r\n"
46
+ args.each { |a|
47
+ command << "$#{a.to_s.size}\r\n"
48
+ command << a.to_s
49
+ command << "\r\n"
50
+ }
51
+ @sock.send command
52
+ end
53
+
54
+ def read_response(source=nil, condition=nil)
55
+ while data = read(4096)
56
+ @reader.feed(data)
57
+
58
+ while response = @reader.gets
59
+ case response
60
+ when 'PONG'
61
+ @pong = true
62
+ when Array
63
+ case response[0]
64
+ when 'subscribe', 'unsubscribe'
65
+ when 'message'
66
+ type, channel, data = *response
67
+ for cb in (@callbacks[channel]||[])
68
+ cb.call(data)
69
+ end
70
+ else
71
+ STDERR.puts "Unexpected response: #{response.inspect}"
72
+ end
73
+ end
74
+ end
75
+ end
76
+ true
77
+ end
78
+
79
+ def read(n)
80
+ @sock.receive(n)
81
+ rescue Gio::IO::WouldBlockError => e
82
+ nil
83
+ end
84
+ end
85
+ end
data/lib/gio-redis.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'gio/redis'
2
+
3
+ GioRedis = Gio::Redis
4
+
@@ -0,0 +1,26 @@
1
+
2
+ $: << File.dirname(__FILE__)+'/../lib'
3
+ require 'test/unit'
4
+ require 'redis'
5
+ require 'gio/redis'
6
+
7
+ class GioTest < Test::Unit::TestCase
8
+ def test_connect
9
+ g = Gio::Redis.new
10
+ sleep 0.2
11
+ g.poll
12
+ assert g.pong?, "Response received"
13
+ end
14
+
15
+ def test_message
16
+ g = Gio::Redis.new
17
+ r = ::Redis.new
18
+ response = nil
19
+ g.subscribe('gio-redis-test') { |_| response = _ }
20
+ r.publish('gio-redis-test', 'All clear')
21
+ sleep 0.2
22
+ g.poll
23
+ assert_equal "All clear", response, "Response received"
24
+ end
25
+ end
26
+
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gio-redis
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - |
8
+ Geoff Youngs
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-06-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: hiredis
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '>='
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '>='
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: gio2
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: bundler
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ~>
47
+ - !ruby/object:Gem::Version
48
+ version: '1.3'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: '1.3'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rake
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: gtk2
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ description: Minimal Redis message client for use with the Ruby-GNOME2 gio2 bindings.
85
+ email:
86
+ - git@intersect-uk.co.uk
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - .gitignore
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - gio-redis.gemspec
97
+ - lib/gio-redis.rb
98
+ - lib/gio/redis.rb
99
+ - lib/gio/redis/version.rb
100
+ - test/test_gioredis.rb
101
+ homepage: http://github.com/geoffyoungs/gio-redis
102
+ licenses:
103
+ - MIT
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.0.0.rc.2
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: gio2 based redis pub/sub listener
125
+ test_files:
126
+ - test/test_gioredis.rb