Sha256: 8cf9c5052662317ef71afc1998112bc69952e6be8e23101d506e1a21862d2383
Contents?: true
Size: 1.12 KB
Versions: 7
Compression:
Stored size: 1.12 KB
Contents
module Wolverine class PathComponent class MissingTemplate < StandardError ; end def initialize path @path = path end def method_missing sym, *args create_method sym, *args send sym, *args end private def create_method sym, *args if directory?(path = @path + sym.to_s) define_directory_method path, sym elsif file?(path = @path + "#{sym}.lua") define_script_method path, sym, *args else raise MissingTemplate end end def directory?(path) File.directory?(path) end def file?(path) File.exists?(path) && !File.directory?(path) end def define_directory_method path, sym dir = PathComponent.new(path) define_metaclass_method(sym) { dir } end def define_script_method path, sym, *args script = Wolverine::Script.new(path) define_metaclass_method(sym) { |*args| script.call(Wolverine.redis, *args) } end def define_metaclass_method sym, &block metaclass = class << self; self; end metaclass.send(:define_method, sym, &block) end end end
Version data entries
7 entries across 7 versions & 1 rubygems