Class: Shapkeep
- Inherits:
-
Object
- Object
- Shapkeep
- Defined in:
- lib/shapkeep.rb,
lib/shapkeep/version.rb,
lib/shapkeep/wrapper.rb
Defined Under Namespace
Classes: Wrapper
Constant Summary collapse
- InvalidScriptNameError =
Class.new(StandardError)
- VERSION =
"0.0.1"
Instance Attribute Summary collapse
-
#sha_file ⇒ Object
readonly
Returns the value of attribute sha_file.
Instance Method Summary collapse
- #eval(redis, name, keys = [], args = []) ⇒ Object
-
#initialize(sha_file) ⇒ Shapkeep
constructor
A new instance of Shapkeep.
- #load_scripts!(redis) ⇒ Object
- #script_available?(name) ⇒ Boolean
- #script_store ⇒ Object
Constructor Details
#initialize(sha_file) ⇒ Shapkeep
Returns a new instance of Shapkeep.
9 10 11 |
# File 'lib/shapkeep.rb', line 9 def initialize(sha_file) @sha_file = sha_file end |
Instance Attribute Details
#sha_file ⇒ Object (readonly)
Returns the value of attribute sha_file.
7 8 9 |
# File 'lib/shapkeep.rb', line 7 def sha_file @sha_file end |
Instance Method Details
#eval(redis, name, keys = [], args = []) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/shapkeep.rb', line 13 def eval(redis, name, keys = [], args = []) begin invalid_script_name!(name) unless script_available?(name) redis.evalsha(sha_for_script(name), keys, args) rescue Redis::CommandError => boom raise boom unless boom..include?('NOSCRIPT') load_script(redis, name) retry end end |
#load_scripts!(redis) ⇒ Object
25 26 27 |
# File 'lib/shapkeep.rb', line 25 def load_scripts!(redis) script_store.keys.each { |name| load_script(redis, name) } end |
#script_available?(name) ⇒ Boolean
33 34 35 |
# File 'lib/shapkeep.rb', line 33 def script_available?(name) script_store.has_key?(name) end |
#script_store ⇒ Object
29 30 31 |
# File 'lib/shapkeep.rb', line 29 def script_store @script_store ||= YAML.load_file(sha_file) end |