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)



48
49
50
51
52
53
54
# File 'lib/redis_eval/script_set.rb', line 48

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 = script_path(name).read
  loaded_scripts[name.to_s] ||= RedisEval::Script.build_from_parent(source, self)
end

#load_allObject



17
18
19
20
21
22
23
24
# File 'lib/redis_eval/script_set.rb', line 17

def load_all
  path.children(false).each do |child|
    name   = child.basename(SCRIPT_SUFFIX).to_s
    source = script_path(name).read
    loaded_scripts[name] ||= RedisEval::Script.build_from_parent(source, self)
  end
  true
end

#redisObject



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

def redis
  @redis || Redis.current
end

#redis=(conn) ⇒ Object



30
31
32
# File 'lib/redis_eval/script_set.rb', line 30

def redis=(conn)
  @redis = conn
end