From 0d97d0ffaab213a6328c3d24e92257707d2e8867 Mon Sep 17 00:00:00 2001 From: Sho Hashimoto Date: Sun, 4 Jul 2010 23:05:36 +0900 Subject: [PATCH] set rake task name --- lib/shinagawaseaside.rb | 17 +++++++++++++---- samples/set_taskname/Rakefile | 14 ++++++++++++++ samples/simple/Rakefile | 4 ++-- samples/with_yaml/Rakefile | 2 +- 4 files changed, 30 insertions(+), 7 deletions(-) create mode 100644 samples/set_taskname/Rakefile diff --git a/lib/shinagawaseaside.rb b/lib/shinagawaseaside.rb index d0cca83..054de5c 100644 --- a/lib/shinagawaseaside.rb +++ b/lib/shinagawaseaside.rb @@ -2,9 +2,18 @@ $:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__))) module ShinagawaSeaside - VERSION = '0.0.2' + VERSION = '0.0.3' def ShinagawaSeaside::set_tasks(ttdb, opts) + tasks = { + :start => 'ttstart', + :stop => 'ttstop', + :restart => 'ttrestart' + } + tasks[:start] = opts[:start].to_s if opts[:start] + tasks[:stop] = opts[:stop].to_s if opts[:stop] + tasks[:restart] = opts[:restart].to_s if opts[:restart] + ttdb = ttdb.map{|db| h = Hash.new db.keys.each{|k| @@ -26,7 +35,7 @@ module ShinagawaSeaside } desc 'start TokyoTyrant server' - task 'ttstart' do + task tasks[:start] do puts 'starting TokyoTyrant servers..' for tt in ttdb do Dir.mkdir(tt[:basedir]) if !File.exists?(tt[:basedir]) @@ -43,7 +52,7 @@ module ShinagawaSeaside end desc 'stop TokyoTyrant server' - task 'ttstop' do + task tasks[:stop] do puts 'stopping TokyoTyrant servers..' for tt in ttdb do if File.exists?(tt[:pidfile]) @@ -70,7 +79,7 @@ module ShinagawaSeaside end desc 'restart TokyoTyrant server' - task 'ttrestart' => ['ttstop', 'ttstart'] + task tasks[:restart] => [tasks[:stop], tasks[:start]] end diff --git a/samples/set_taskname/Rakefile b/samples/set_taskname/Rakefile new file mode 100644 index 0000000..6d7c7df --- /dev/null +++ b/samples/set_taskname/Rakefile @@ -0,0 +1,14 @@ +require 'rubygems' +#require 'shinagawaseaside' +require '../../lib/shinagawaseaside' + +ttdb = [ { :name => 'users', :port => 20020}, + { :name => 'videos',:port => 20021}, + { :name => 'comments', :port => 20022} ] + +ShinagawaSeaside::set_tasks(ttdb, + :basedir => File.dirname(__FILE__)+'/ttdb', + :start => 'start', # set task name + :stop => 'stop', + :restart => 'restart' + ) diff --git a/samples/simple/Rakefile b/samples/simple/Rakefile index 547ed94..bace83b 100644 --- a/samples/simple/Rakefile +++ b/samples/simple/Rakefile @@ -1,6 +1,6 @@ require 'rubygems' -require 'shinagawaseaside' -#require '../../lib/shinagawaseaside' +#require 'shinagawaseaside' +require '../../lib/shinagawaseaside' ttdb = [ { :name => 'users', :port => 20010}, { :name => 'videos',:port => 20011}, diff --git a/samples/with_yaml/Rakefile b/samples/with_yaml/Rakefile index bc5836b..42e88eb 100644 --- a/samples/with_yaml/Rakefile +++ b/samples/with_yaml/Rakefile @@ -1,7 +1,7 @@ require 'rubygems' require 'yaml' #require 'shinagawaseaside' -require '../..//lib/shinagawaseaside' +require '../../lib/shinagawaseaside' begin conf = YAML::load open(File.dirname(__FILE__)+'/config.yaml') -- 1.6.3