Sha256: bfa5a68c5f87f401d0af488f85096b8131402142fb694a063cc323fa0accb5ae

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

require 'redis'

require 'wolverine/version'
require 'wolverine/configuration'
require 'wolverine/script'

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 
  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
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wolverine-0.0.4 lib/wolverine.rb