Class: RedisEval::ScriptSet

Inherits:
Object
  • Object
show all
Defined in:
lib/redis_eval/script_set.rb

Constant Summary collapse

SCRIPT_SUFFIX =
".lua"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target_path, conn = nil) ⇒ ScriptSet

Returns a new instance of ScriptSet.



7
8
9
10
# File 'lib/redis_eval/script_set.rb', line 7

def initialize(target_path, conn = nil)
  @path  = pathname(target_path)
  @redis = conn
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object (private)



44
45
46
47
48
49
50
# File 'lib/redis_eval/script_set.rb', line 44

def method_missing(name, *args, &block)
  super unless respond_to?(name)

  self.load(name)
  define_singleton_method(name) { |*a, &b| loaded_scripts[name.to_s] }
  send(name, *args, &block)
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/redis_eval/script_set.rb', line 3

def path
  @path
end

Instance Method Details

#load(name) ⇒ Object



12
13
14
15
# File 'lib/redis_eval/script_set.rb', line 12

def load(name)
  source = ERB.new(script_path(name).read).result
  loaded_scripts[name.to_s] ||= RedisEval::Script.build_from_parent(source, self)
end

#load_allObject



17
18
19
20
# File 'lib/redis_eval/script_set.rb', line 17

def load_all
  path.children(false).each { |child| self.load(child.basename(SCRIPT_SUFFIX).to_s) }
  true
end

#redisObject



22
23
24
# File 'lib/redis_eval/script_set.rb', line 22

def redis
  @redis || Redis.current
end

#redis=(conn) ⇒ Object



26
27
28
# File 'lib/redis_eval/script_set.rb', line 26

def redis=(conn)
  @redis = conn
end