Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 153 lines (120 sloc) 3.662 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
require 'rubygems'
require 'rake/gempackagetask'
require 'rake/testtask'

$:.unshift File.join(File.dirname(__FILE__), 'lib')
require 'redis'

GEM = 'redis'
GEM_NAME = 'redis'
GEM_VERSION = Redis::VERSION
AUTHORS = ['Ezra Zygmuntowicz', 'Taylor Weibley', 'Matthew Clark', 'Brian McKinney', 'Salvatore Sanfilippo', 'Luca Guidi', 'Michel Martens', 'Damian Janowski']
EMAIL = "ez@engineyard.com"
HOMEPAGE = "http://github.com/ezmobius/redis-rb"
SUMMARY = "Ruby client library for Redis, the key value storage server"

spec = Gem::Specification.new do |s|
  s.name = GEM
  s.version = GEM_VERSION
  s.platform = Gem::Platform::RUBY
  s.has_rdoc = true
  s.extra_rdoc_files = ["LICENSE"]
  s.summary = SUMMARY
  s.description = s.summary
  s.authors = AUTHORS
  s.email = EMAIL
  s.homepage = HOMEPAGE
  s.require_path = 'lib'
  s.autorequire = GEM
  s.files = %w(LICENSE README.markdown Rakefile) + Dir.glob("{lib,tasks,spec}/**/*")
end

REDIS_DIR = File.expand_path(File.join("..", "test"), __FILE__)
REDIS_CNF = File.join(REDIS_DIR, "test.conf")
REDIS_PID = File.join(REDIS_DIR, "db", "redis.pid")

task :default => :run

desc "Run tests and manage server start/stop"
task :run => [:start, :test, :stop]

desc "Start the Redis server"
task :start do
  redis_running = \
    begin
      File.exists?(REDIS_PID) && Process.kill(0, File.read(REDIS_PID).to_i)
    rescue Errno::ESRCH
      FileUtils.rm REDIS_PID
      false
    end

  system "redis-server #{REDIS_CNF}" unless redis_running
end

desc "Stop the Redis server"
task :stop do
  if File.exists?(REDIS_PID)
    Process.kill "INT", File.read(REDIS_PID).to_i
    FileUtils.rm REDIS_PID
  end
end

Rake::TestTask.new(:test) do |t|
  t.pattern = "test/**/*_test.rb"
  t.ruby_opts << "-r rubygems"
end

Rake::GemPackageTask.new(spec) do |pkg|
  pkg.gem_spec = spec
end

desc "install the gem locally"
task :install => [:package] do
  sh %{gem install pkg/#{GEM}-#{GEM_VERSION}}
end

desc "create a gemspec file"
task :gemspec do
  File.open("#{GEM}.gemspec", "w") do |file|
    file.puts spec.to_ruby
  end
end

desc "Generate YARDoc"
task :yardoc do
  require "yard"

  opts = ["--title", "A Ruby client for Redis"]

  YARD::CLI::Yardoc.run(*opts)
end

namespace :commands do
  def redis_commands
    $redis_commands ||= begin
      require "open-uri"
      open("http://dimaion.com/redis/master").read.split
    end
  end

  task :doc do
    source = File.read("lib/redis.rb")

    redis_commands.each do |name, text|
      source.sub!(/(?:^ *#.*\n)*^( *)def #{name}(\(|$)/) do
        indent, extra_args = $1, $2
        comment = "#{indent}# #{text.strip}"

        IO.popen("par p#{2 + indent.size} 80", "r+") do |io|
          io.puts comment
          io.close_write
          comment = io.read
        end

        "#{comment}#{indent}def #{name}#{extra_args}"
      end
    end

    File.open("lib/redis.rb", "w") { |f| f.write(source) }
  end

  task :verify do
    require "redis"
    require "stringio"

    log = StringIO.new

    at_exit do
      redis = Redis.new

      report = ["Command", "\033[0mDefined?\033[0m", "\033[0mTested?\033[0m"]

      yes, no = "\033[1;32mYes\033[0m", "\033[1;31mNo\033[0m"

      redis_commands.sort.each do |name, _|
        defined, tested = redis.respond_to?(name), log.string[">> #{name.upcase}"]

        next if defined && tested

        report << name
        report << (defined ? yes : no)
        report << (tested ? yes : no)
      end

      IO.popen("rs 0 3", "w") do |io|
        io.puts report.join("\n")
      end
    end

    Dir["test/**/redis_test.rb"].each { |f| require "./#{f}" }

    RedisTest::OPTIONS[:logger] = Logger.new(log)
  end
end
Something went wrong with that request. Please try again.