redic-dsl 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2646b0b106e1866dad8b0fca94aefda6c2d2bbd4
4
+ data.tar.gz: 2ddba272b33b26b626cbbd7df2e8206ee5c642f0
5
+ SHA512:
6
+ metadata.gz: 09033f88cb446a940f35a0a1e48367482af01a66983195b461d5fa9c9c90a58f99523a7a206a32d77fa9c1f630ed7150f4322dcd450557e0fdd2c5a18a64c17a
7
+ data.tar.gz: bb343a495a84adf8c12c31f3e0b4276af61e3e3d8b0beebee957a6cd54aaaddda64b35117da3c1bf87d2c70a139d782704b424f002249b5d1b49bf0d9052105a
data/.gems ADDED
@@ -0,0 +1,2 @@
1
+ redic -v 1.2.0
2
+ cutest -v 1.2.2
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ /.gs
2
+ *.gem
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2015 Joaquín Vicente
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # redic-dsl
2
+
3
+ DSL wrapper for Redic
4
+
5
+ ## Description
6
+
7
+ Add some DSL around [redic][redic], a lightweight [Redis][redis] client.
8
+
9
+ [redic]: https://github.com/amakawa/redic
10
+ [redis]: http://redis.io/documentation
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ $ gem install redic-dsl
16
+ ```
17
+
18
+ ## Usage
19
+
20
+ ```ruby
21
+ require "redic/dsl"
22
+
23
+ redis = Redic::Dsl.new("redis://localhost:6379")
24
+
25
+ redis.set "foo", "bar"
26
+ # => "OK"
27
+ redis.get "foo"
28
+ # => "bar"
29
+
30
+ redis.pipelined do |r|
31
+ r.set "baz", 1
32
+ r.incr "baz"
33
+ r.get "baz"
34
+ end
35
+ # => ["OK", 2, "2"]
36
+ ```
data/lib/redic/dsl.rb ADDED
@@ -0,0 +1,42 @@
1
+ require "redic"
2
+
3
+ class Redic::Dsl < Redic
4
+
5
+ class Queue
6
+
7
+ def initialize connection
8
+ @connection = connection
9
+ end
10
+
11
+ def method_missing name, *arguments, &block
12
+ command = name.to_s
13
+ self.class.send(:define_method, name) do |*args|
14
+ @connection.queue command, *args
15
+ end
16
+ send name, *arguments
17
+ end
18
+
19
+ end
20
+
21
+ alias_method :connection, :client
22
+ undef :client
23
+
24
+ def method_missing name, *arguments, &block
25
+ command = name.to_s
26
+ response = call command, *arguments
27
+
28
+ unless response.is_a? RuntimeError
29
+ self.class.send(:define_method, name) do |*args|
30
+ call command, *args
31
+ end
32
+ end
33
+
34
+ response
35
+ end
36
+
37
+ def pipelined(&block)
38
+ yield Redic::Dsl::Queue.new(self)
39
+ commit
40
+ end
41
+
42
+ end
data/redic-dsl.gemspec ADDED
@@ -0,0 +1,17 @@
1
+ # encoding: utf-8
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "redic-dsl"
5
+ s.version = "0.0.1"
6
+ s.summary = "DSL wrapper for Redic"
7
+ s.description = "Add some DSL around redic, a lightweight Redis client"
8
+ s.author = "Joaquín Vicente"
9
+ s.email = "joakin@gmail.com"
10
+ s.homepage = "https://github.com/wacko/redic-dsl"
11
+ s.license = "MIT"
12
+
13
+ s.files = `git ls-files`.split("\n")
14
+
15
+ s.add_dependency "redic", '~> 0'
16
+ s.add_development_dependency "cutest", '~> 0'
17
+ end
data/test/dsl_test.rb ADDED
@@ -0,0 +1,27 @@
1
+ require "cutest"
2
+ require_relative "../lib/redic/dsl"
3
+
4
+ setup do
5
+ Redic::Dsl.new("redis://localhost:6379")
6
+ end
7
+
8
+ test "DSL usage" do |r|
9
+ r.set("foo", "bar")
10
+ assert_equal "bar", r.get("foo")
11
+ r.set("foo", "baz")
12
+ assert_equal "baz", r.get("foo")
13
+ end
14
+
15
+ test "DSL define_method" do |r|
16
+ r.set("foo", "bar")
17
+ assert r.respond_to?(:set)
18
+ end
19
+
20
+ test "Pipeline usage" do |redis|
21
+ response = redis.pipelined do |r|
22
+ r.set "baz", 1
23
+ r.incr "baz"
24
+ r.get "baz"
25
+ end
26
+ assert_equal ["OK", 2, "2"], response
27
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: redic-dsl
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Joaquín Vicente
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: redic
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: cutest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Add some DSL around redic, a lightweight Redis client
42
+ email: joakin@gmail.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - ".gems"
48
+ - ".gitignore"
49
+ - LICENSE
50
+ - README.md
51
+ - lib/redic/dsl.rb
52
+ - redic-dsl.gemspec
53
+ - test/dsl_test.rb
54
+ homepage: https://github.com/wacko/redic-dsl
55
+ licenses:
56
+ - MIT
57
+ metadata: {}
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubyforge_project:
74
+ rubygems_version: 2.4.5
75
+ signing_key:
76
+ specification_version: 4
77
+ summary: DSL wrapper for Redic
78
+ test_files: []