ruby-openidをRails-2.3.2で使う時の注意点
Rails-2.3からRackに対応した事と関連が深いと思うのですが、
ruby-openi
1 @@logger = Logger.new(STDERR)
STDERRを使うようになっているのですが、これがRackと相性が悪いようです。
以下のように、config/ini
1 OpenID::Util::logger = Logger.new(File.join(Rails.root, %w(log openid.log)))
Rails-2.3からRackに対応した事と関連が深いと思うのですが、
ruby-openi
1 @@logger = Logger.new(STDERR)
STDERRを使うようになっているのですが、これがRackと相性が悪いようです。
以下のように、config/ini
1 OpenID::Util::logger = Logger.new(File.join(Rails.root, %w(log openid.log)))
YAMLのノードには3種類(kind)がある:
それぞれのkindはいくつかのstyleで出力できる。
1 Lorem ipsum dolor sit amet, consectetur adipiscing elit.
1 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. '
1 "Lorem ipsum dolor sit amet, consectetur adipiscing elit. "
1 --- | 2 Lorem ipsum dolor sit amet, 3 consectetur adipiscing elit. 4 Pellentesq ue tincidunt molestie est. 5 Vestibulum ante odio, euismod ac, 6 sagittis et, tempus ut, lorem. 7 Praesent consectetu r tempor ipsum. 8 Nulla facilisi.
1 --- > 2 Lorem ipsum dolor sit amet, 3 consectetur adipiscing elit. 4 Pellentesq ue tincidunt molestie est. 5 Vestibulum ante odio, euismod ac, 6 sagittis et, tempus ut, lorem. 7 Praesent consectetu r tempor ipsum. 8 Nulla facilisi.
1 - one 2 - two 3 - three
1 [1, 2, 3]
1 height: 170 2 weight: 60
1 { height: 170, weight: 60}
YAML::dumpto_yaml_stをオブジェクトに定義すればよい、という裏技(非ドキュメントメソッド)を紹介したい。このメソッドの返り値がそのオブジェクトのstyleになる。
例えば:
1 class String 2 def to_yaml_style 3 return :quote2 4 end 5 end
Rubyでのスタイルは以下:
1 :plain # クオートなし 2 :quote1 # シングルクオート 3 :quote2 # ダブルクオート 4 :literal # Block Literal 5 :fold # Block Folding 6 :inline # Inline (Sequence, Mapping) 7 nil # デフォルト (Sequence, Mapping)
ちなみに、これを調べた切っ掛けはHashをYAML::dump
1 name: "鈴木" 2 height: 170 3 weight: 60
1 name: "鈴木" 2 height: "170" 3 weight: "60"
monkeypatc
1 class Hash 2 def to_yaml_with_quoted_ strings(*args) 3 class << self 4 unless method_def ined?(:each_with_ quoted_str ings) 5 def each_with_ quoted_str ings 6 each_with_ normal_str ings do |k,v| 7 if String === v && !v.frozen? 8 def v.to_yaml_ style; return :quote2; end 9 end 10 yield k, v 11 end 12 end 13 alias_meth od :each_with_ normal_str ings, :each 14 alias_meth od :each, :each_with_ quoted_str ings 15 end 16 end 17 return to_yaml_wi th_normal_ strings(*args) 18 end 19 alias_meth od :to_yaml_wi th_normal_ strings, :to_yaml 20 alias_meth od :to_yaml, :to_yaml_wi th_quoted_ strings 21 end
polymorphi
1 def build_named_route_ca ll(records, namespace, inflection , options = {}) 2 unless records.is_a?(Array) 3 record = extract_re cord(records) 4 route = '' 5 else 6 record = records.pop 7 route = records.inject("") do |string, parent| 8 if parent.is_a?(Symbol) || parent.is_a?(String) 9 string << "#{parent}_" 10 else 11 string << "#{RecordIden tifier.__send__("plural_cla ss_name", parent 12 )}".singulariz e 13 string << "_" 14 end 15 end 16 end 17 18 if record.is_a?(Symbol) || record.is_a?(String) 19 route << "#{record}_" 20 else 21 route << "#{RecordIden tifier.__send__("plural_cla ss_name", record)}" 22 route = route.singulariz e if inflection == :singular 23 route << "_" 24 end 25 26 action_pre fix(options) + namespace + route + routing_ty pe(options).to_s 27 end
Railsでモデルのバージョン管理を行うというと、
acts_as_ve
rdocのデフォルトのテンプレートが非常にダサくて、なかなか使いづらい。mislavのhannaを使えば、こんなにスタイリッシュになる:

おまけとして、簡単なメソッド検索もできます。また、テンプレート自体はhamlで書いていて、なかなか読みやすい。「スケールできる」ことが売りらしいけど、まぁ意味不明な自慢だよね。
1 sudo gem install rdoc -v 2.3 2 <<-- 3 2. githubをgemのsourceに追加 4 shell-unix-generic>> 5 gem source add http://gem s.github.c om
1 gem install mislav-hanna
1 hanna --gems
.gemrcに以下の一行を追加する
1 rdoc: --inline-source --line-num bers --format=h tml --template =hanna
ちなみに、今使っている.gemrcはこんな感じ:
1 --- 2 :benchmark: false 3 :update_sources: true 4 :sources: 5 - http://gem s.rubyforg e.org/ 6 - http://gem s.github.c om 7 :bulk_thres hold: 1000 8 :backtrace: false 9 :verbose: true 10 rdoc: --inline-sou rce --line-num bers --format=h tml --template =hanna
railsapiで使っているsdocというやつもある。これの検索機能がなかなかすばらしい。ただし、今のところは単体のプロジェクトでしか使えなくて、gemからtemplateとして指定することができないみたい。また、githubへのリンクもgithubを使っていないプロジェクトにとってはちょっと魅力が薄れる。にもかかわらず、とても魅力的だな。
1 gem install voloko-sdoc --source http://gem s.github.c om
1 gem install rdoc -v 2.4
1 cd <project> 2 sdoc -N .

あのAsakusa.rb
dm-paginat
最近の改善が取り込まれています。
dm-paginat
See Also
VirtualBox
何がスゴイって、ゲストOSの仮想ディスクの作成のところにGentooが!!

だいたいどんな仮想ソフトウェアでも、こういうので選択できるLinuxはRedHat、Debian、SUSEあたりのメジャーどころで、他はOtherとかでひとくくりにされているのですが・・・
やのに、VirtualBox
開発者の1人が「何でGentoo入ってないんだよ!」とか言うたのかなぁとか色々と考えていると夜が明けてしまったので、今日からしばらく使ってみてからレビューしたいと思います。
もちろん、ゲストOSはGentooで。
何回か忘れたので、記憶を定着させるためにメモしておきます。 rubyでLOAD_PATHに特定のディレクトリを追加したい場合、以下のように RUBYLIB環境変数が利用できます。
1 export RUBYLIB=/usr/lib/sit e_ruby:$RUBYLIB
s21gブログをRails-2.2.
Rails-2.2.
1 % rake rails:update
を行うと便利ですが、これを実行すると、以下のようなファイルが影響を受けます。
1 # Changed but not updated: 2 # (use "git add/rm <file>..." to update what will be committed) 3 # 4 # deleted: app/controllers/appl ication.rb 5 # modified: config/boo t.rb 6 # modified: config/env ironment.r b 7 # modified: public/jav ascripts/c ontrols.js 8 # modified: public/jav ascripts/d ragdrop.js 9 # modified: public/jav ascripts/e ffects.js 10 # modified: public/jav ascripts/p rototype.j s 11 # 12 # Untracked files: 13 # (use "git add <file>..." to include in what will be committed) 14 # 15 # app/contro llers/appl ication_co ntroller.r b 16 no changes added to commit (use "git add" and/or "git commit -a")
Applicatio