Class: Shapkeep

Inherits:
Object
  • Object
show all
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.2.0'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sha_file) ⇒ Shapkeep

Returns a new instance of Shapkeep.



10
11
12
13
# File 'lib/shapkeep.rb', line 10

def initialize(sha_file)
  @sha_file = sha_file
  @lua_root = script_store.delete(:lua_root) { Dir.pwd }
end

Instance Attribute Details

#lua_rootObject

Returns the value of attribute lua_root.



7
8
9
# File 'lib/shapkeep.rb', line 7

def lua_root
  @lua_root
end

#sha_fileObject (readonly)

Returns the value of attribute sha_file.



8
9
10
# File 'lib/shapkeep.rb', line 8

def sha_file
  @sha_file
end

Instance Method Details

#eval(redis, name, keys = [], args = []) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/shapkeep.rb', line 15

def eval(redis, name, keys = [], args = [])
  begin
    invalid_script_name!(name) unless script_available?(name)
    redis.evalsha(sha_for_script_name(name), keys, args)
  rescue Redis::CommandError => boom
    raise boom unless boom.message.include?('NOSCRIPT')

    load_script(redis, name)
    retry
  end
end

#load_scripts!(redis) ⇒ Object



27
28
29
# File 'lib/shapkeep.rb', line 27

def load_scripts!(redis)
  script_store.keys.each { |name| load_script(redis, name) }
end

#script_available?(name) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/shapkeep.rb', line 35

def script_available?(name)
  script_store.has_key?(name)
end

#script_storeObject



31
32
33
# File 'lib/shapkeep.rb', line 31

def script_store
  @script_store ||= YAML.load_file(sha_file)
end