生年月日
が近い人とはうまがあいやすい。
が近い人とはうまがあいやすい。
class Pathname
def self.home
new(ENV["HOME"])
end
endENV["HOME"] って大文字ばっかりでつかれる。
http://vim.sourceforge.net/scripts/script.php?script_id=73
ちょっと使ってみたのだけど、ときどきすごく重くなったり、挙動不審だったりして微妙……便利なんだけどなぁ……SELECT モードから戻らなかったりする。
使い続けるかもう少し様子見
http://lab.lowreal.net/gems/
scp で特定のディレクトリに投げつける Raketask を書いて ( http://coderepos.org/share/changeset/427 )、更新された gem の rdoc を生成して gem index を更新するスクリプトを叩く。
#!/usr/bin/env ruby
puts "Content-Type: text/plain"
puts
$stderr = $stdout
require "pp"
require "pathname"
require "rubygems"
require "rubygems/doc_manager"
begin
class Gem::Format
def extract_to(dir)
dir = Pathname.new(dir)
self.file_entries.each do |info,content|
path = Pathname.new(info["path"])
if path.absolute?
raise "Damedayo"
end
f = dir + path
f.parent.mkpath
f.open("wb") do |o|
o.write content
end
end
end
end
Gem::DocManager.configured_args = ["--template", "/Users/cho45/coderepos/lang/ruby/rdoc/generators/template/html/resh/resh.rb"]
Gem::DocManager.configured_args = ["--template", "resh", "--line-numbers"]
load "/usr/bin/index_gem_repository.rb"
path = Pathname.new("/srv/www/lab.lowreal.net/public/gems")
options = {
:directory => path.to_s,
:verbose => true,
:quick => true,
}
prev = (path + "quick/index").read.split(/¥n/) rescue []
#prev = []
indexer = Indexer.new(options)
indexer.build_index
diff = (path + "quick/index").read.split(/¥n/) - prev
diff.each do |gem|
puts gem
g = path + "gems/#{gem}.gem"
gem = Gem::Format.from_file_by_path(g.to_s)
dir = path+"gems/#{gem.spec.full_name}"
dir.rmtree rescue nil
gem.extract_to(dir)
#gem.spec.loaded_from = "docs"
spec = gem.spec
spec.instance_eval { @path = path }
def spec.installation_path
@path.to_s
end
p spec.full_gem_path
doc_manager = Gem::DocManager.new(gem.spec)
doc_manager.generate_rdoc
end
rescue Exception => e
puts e
puts e.backtrace
endブラウザでアクセスしたときに表示されるインデックスはてきとうに gem spec よんで表示してるだけ
なんかなにをしようとしていたか忘れた……ねむくなってきた。ついでにお腹痛い。Win 環境でもシームレスにつかえるようにするにはどうしたらいいのかなぁ。URI::File.path(path) を定義して URI 化とかかなぁ。でもあんま意味ない気がしてきた。
require "uri"
require "pathname"
# file scheme syntax:
# file://<host>/<path>
class URI::FILE < URI::Generic
DEFAULT_PORT = nil
COMPONENT = [:scheme, :host, :path].freeze
def self.build(args)
tmp = Util::make_components_hash(self, args)
super(tmp)
end
def initialize(*args)
super(*args)
@pathname = Pathname.new(@path)
# delegate
(@pathname.methods - self.methods).each do |m|
instance_eval <<-EOS
def #{m}(*args, &block)
r = @pathname.__send__(:#{m}, *args, &block)
if r.class == Pathname
@path = r.to_s
self
else
r
end
end
EOS
end
end
def to_s
"#{scheme}://#{host}#{path}"
end
alias :to_str :to_s
def set_path=(s)
@pathname = Pathname.new(s)
@path = s
end
def set_host(s)
@host = s
if !s.nil? && !s.empty?
raise NotImplementedError, "Host is not supported"
else
@host = nil
end
end
def check_host(s)
if s.empty? || HOST =~ s
true
else
raise InvalidComponentError, "bad component(expected host component): #{v}"
end
end
@@schemes['FILE'] = URI::FILE
end
if $0 == __FILE__
require "test/unit"
class TC_URI_FILE < Test::Unit::TestCase
def setup
end
def test_windows
uri = URI("file:///c:/Windows")
assert_equal nil, uri.host
assert_equal nil, uri.port
assert_equal "/c:/Windows", uri.path
assert_equal "file", uri.scheme
assert_equal "file:///c:/Windows", uri.to_s
uri = URI("file:///c:")
assert_equal nil, uri.host
assert_equal nil, uri.port
assert_equal "/c:", uri.path
assert_equal "file", uri.scheme
assert_equal "file:///c:", uri.to_s
uri = URI("file:///c:/Documents%20and%20Settings/")
assert_equal nil, uri.host
assert_equal nil, uri.port
assert_equal "/c:/Documents%20and%20Settings/", uri.path
assert_equal "file", uri.scheme
assert_equal "file:///c:/Documents%20and%20Settings/", uri.to_s
end
def test_delegate
uri = URI("file:///Users/cho45")
assert_equal URI("file:///Users"), uri.parent
assert_equal false, uri.root?
uri = URI("file:///c:/Documents%20and%20Settings/cho45")
assert_equal URI("file:///c:/Documents%20and%20Settings"), uri.parent
end
def test_inteface
assert_equal URI("file:///path/to"), URI::FILE.build(["", "/path/to"])
uri = URI("file:///Users/cho45")
uri.path = "/hoge/hoge"
assert_equal URI("file:///hoge/hoge"), uri
uri = URI("file:///Users/cho45/tmp/")
assert_equal URI("file:///Users/cho45/tmp/test"), uri + "test"
end
def test_with_host
assert_raise(NotImplementedError) do
URI::FILE.build(["host", "/path/to"])
end
assert_raise(NotImplementedError) do
uri = URI("file://host/Users/cho45")
end
end
end
end