lib/wolverine.rb in wolverine-0.0.4 vs lib/wolverine.rb in wolverine-0.1.0

- old
+ new

@@ -1,54 +1,28 @@ require 'redis' +require 'pathname' require 'wolverine/version' require 'wolverine/configuration' require 'wolverine/script' +require 'wolverine/path_component' module Wolverine - - class Directory - class MissingTemplate < StandardError ; end - def initialize path - @path = path - end - - def method_missing sym, *args - resolve sym, *args - end - - def resolve sym, *args - if File.directory?(path = @path + sym.to_s) - Directory.new(path) - elsif File.exists?(path = @path + "#{sym}.lua") - Wolverine.call path, *args - else - raise MissingTemplate - end - end - end - def self.config @config ||= Configuration.new end def self.redis config.redis end - def self.method_missing sym, *args - Directory.new(config.script_path).resolve(sym, *args) - rescue Directory::MissingTemplate - super + def self.root_directory + @root_directory ||= PathComponent.new(config.script_path) end - def self.call(file, *args) - pathname = file.kind_of?(Pathname) ? file : full_path(file) - Script.new(pathname).call(redis, *args) - end - - def self.full_path(file) - file << ".lua" unless file =~ /\.lua$/ - config.script_path + file + def self.method_missing sym, *args + root_directory.send(sym, *args) + rescue PathComponent::MissingTemplate + super end end