class RedisEval::ScriptSet

Constants

SCRIPT_SUFFIX

Attributes

path[R]
redis[W]

Public Class Methods

new(target_path, conn = nil) click to toggle source
# File lib/redis_eval/script_set.rb, line 7
def initialize(target_path, conn = nil)
  @path = pathname(target_path)
  @redis = conn
end

Public Instance Methods

load(name) click to toggle source
# File lib/redis_eval/script_set.rb, line 12
def load(name)
  source = ERB.new(script_path(name).read).result(__binding__)
  loaded_scripts[name.to_s] ||= RedisEval::Script.build_from_parent(source, self)
end
load_all() click to toggle source
# 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
redis() click to toggle source
# File lib/redis_eval/script_set.rb, line 22
def redis
  @redis || Redis.current
end

Private Instance Methods

loaded_scripts() click to toggle source
# File lib/redis_eval/script_set.rb, line 34
def loaded_scripts
  @loaded_scripts ||= {}
end
method_missing(name, *args, &block) click to toggle source
Calls superclass method
# File lib/redis_eval/script_set.rb, line 42
def method_missing(name, *args, &block)
  super unless respond_to?(name)

  self.load(name)
  define_singleton_method(name) { |*_a| loaded_scripts[name.to_s] }
  send(name, *args, &block)
end
pathname(path) click to toggle source
# File lib/redis_eval/script_set.rb, line 30
def pathname(path)
  path.is_a?(Pathname) ? path : Pathname.new(path)
end
respond_to_missing?(name, include_private = false) click to toggle source
Calls superclass method
# File lib/redis_eval/script_set.rb, line 50
def respond_to_missing?(name, include_private = false)
  loaded_scripts.has_key?(name.to_s) || script_path(name).exist? || super
end
script_path(name) click to toggle source
# File lib/redis_eval/script_set.rb, line 38
def script_path(name)
  path.join(name.to_s).sub_ext(SCRIPT_SUFFIX)
end