作業メモ

まだリレーションのテストは確認していないけど一応テストは動くようになったので,ここまでの作業メモ。まずはプリフィクスを付けるプラグインは以下のようにして,environment.rbの中でset_prefixでプレフィクスを設定。

# Prefixed
module ActiveRecord
  class Base
    class <<Base
      alias :original_table_name :table_name

      def set_base_name(basename)
        @base_name = basename
      end
      
      def set_prefix(prefix)
        @@nucleus_prefix = prefix
      end
      
      def table_name
        if @base_name 
           @@nucleus_prefix + @base_name.to_s
        else
           original_table_name
        end
      end
     end 
  end
end

後は,各クラスではset_base_nameでベースネームを設定(これってアクセサにすべきだった? ちょっとかっこ悪いけどまあいいや)。
テストの方は モデルクラス_test.rb の中でfixtureとしてプリフィクス付きのテーブル名を指定。あわせてfixturesの中のYAMLのファイル名もテーブル名と同じものに変更。さらにYAMLの中でidとなっているところは,実際のID(inumberなど)に修正。

今日はここまで(受験の神様風,笑)



27 Oct, 2007 | General | | Andy
« Prev item - Next Item »
---------------------------------------------

Comments


No comments yet. You can be the first!


Leave comment

© 2007 yoursite.com | Designed by DesignsByDarren
Ported to Nucleus CMS: Suvoroff