led 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/led.rb +76 -0
- metadata +57 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a835298da09aecfffb3bc9271c2752534a867a01
|
4
|
+
data.tar.gz: a44ca0714ffad3787af67b713773fa3ab1139b35
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 079d2e18f98cdcfba30a92d63edcb020da1c2d179734eedfae983fc57fddd47fac78961c9ecc66825cb6f0ac0779e84c6a989d7f13c5d9cbbc2996e95c5c55ae
|
7
|
+
data.tar.gz: 6af9b36d1f9dd26815d6dea97551492027e511be31d4f05349d343ce8c600f25635c3495d8511bd82f6d0a9adc63ece05ca4608ff537856b901c69b532f04271
|
data/lib/led.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
|
4
|
+
require 'hiredis'
|
5
|
+
require 'redis'
|
6
|
+
|
7
|
+
module Led
|
8
|
+
def self.conn= (conn)
|
9
|
+
@conn = conn
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.conn
|
13
|
+
@conn ||= Redis.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.add_script(name, script)
|
17
|
+
@shas ||= {}
|
18
|
+
@scripts ||= {}
|
19
|
+
|
20
|
+
script = preprocess(script)
|
21
|
+
|
22
|
+
@shas[name.to_sym] = conn.script('load', script)
|
23
|
+
@scripts[name.to_sym] = script
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.method_missing(m, *args)
|
27
|
+
unless @shas && @shas[m]
|
28
|
+
@script_dir ? load_script(m) : super
|
29
|
+
end
|
30
|
+
|
31
|
+
run_script(m, *args)
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.run_script(m, *args)
|
35
|
+
conn.evalsha(@shas[m], [], args)
|
36
|
+
rescue Redis::CommandError => e
|
37
|
+
# detect if script needs to be reloaded
|
38
|
+
if e.message =~ /NOSCRIPT/
|
39
|
+
@shas[m] = conn.script('load', @scripts[m])
|
40
|
+
conn.evalsha(@shas[m], [], args)
|
41
|
+
else
|
42
|
+
raise e
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.preprocess(script)
|
47
|
+
script.
|
48
|
+
# redis.call shorthand
|
49
|
+
gsub(/([A-Z]+)\(/) {"redis.call('#{$1}',"}.
|
50
|
+
# string interpolation
|
51
|
+
gsub(/\#\{([^\}]+)\}/) {"\" .. #{$1} .. \""}.
|
52
|
+
# remove empty string concatenation
|
53
|
+
gsub(/\s\.\.\s''/, ' ').
|
54
|
+
gsub(/[^\\]''\s\.\.\s/, ' ').
|
55
|
+
gsub(/\__include '([^\s]+)'/) {process_include($1)}
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.process_include(file)
|
59
|
+
raise "Script directory not specified" unless @script_dir
|
60
|
+
|
61
|
+
IO.read(File.join(@script_dir, "#{file}.lua"))
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.script_dir=(dir)
|
65
|
+
@script_dir = dir
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.script_dir
|
69
|
+
@script_dir
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.load_script(name)
|
73
|
+
script = IO.read(File.join(script_dir, "#{name}.lua"))
|
74
|
+
add_script(name, script)
|
75
|
+
end
|
76
|
+
end
|
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: led
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sharon Rosner
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-04-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: redis
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.0.0
|
27
|
+
description: Easy Lua scripting for Redis
|
28
|
+
email: ciconia@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- lib/led.rb
|
34
|
+
homepage: http://github.com/ciconia/led
|
35
|
+
licenses: []
|
36
|
+
metadata: {}
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options: []
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
requirements: []
|
52
|
+
rubyforge_project:
|
53
|
+
rubygems_version: 2.0.3
|
54
|
+
signing_key:
|
55
|
+
specification_version: 4
|
56
|
+
summary: Redis script preprocessor
|
57
|
+
test_files: []
|