「継承可能な設定」の編集履歴(バックアップ)一覧はこちら

継承可能な設定」(2008/12/29 (月) 08:59:17) の最新版変更点

追加された行は緑色になります。

削除された行は赤色になります。

http://www.rubywaves.com/configurations Inheritable Configurations Waves では, Configurations は属性をセットしたり得たりする単なるメソッドのあるクラスです。これは設定した属性値の継承やオーバーライドすることを許し、他のクラスと同様に扱えることを意味します。もう一度いうと、Configurations は決して instantiated されず、 その点において典型的な Ruby クラスとは異なって扱われます。 構成を定義するのはかなり簡単です。:単に Waves::Configurations::Base か (もし合理的な規定値が欲しいなら) Waves::Configurations::Default から継承してください。 class MyConfiguration < Waves::Configurations::Base attributes( :host, :port, :server ) def self.foo( val ) self['application'] = val # also do something else unusual end host '0.0.0.0' port 4000 server Waves::Servers::Mongrel foo 'bar' end このシンプルな構成が行っていることは、ホスト・ポート・サーバの getter と setter メソッドを定義することです。また「カスタム」属性 foo も定義し、ほんの少しのロジックを setter に追加します。そしてこれらの属性を設定します。 Requiring them to be declared first avoids the insidious problem of subtly mispelling an attribute and then wondering why it isn’t set correctly. (Configuration attributes in Waves are a little unusual in that the setter methods actually re-define the getters to return whatever value was just set, as opposed to storing them in a Hash. The idea here was to squeeze a little extra speed out of accessing configuration values, but it add just enough unexpected weirdness that we will likely use normal class attributes in a future release.) いずれにせよ、Default 構成から継承でき、いくつかの既定の設定に伴う事前定義された属性を与えます。これらを含んでください。: ・server, host, と port. The only mystery here is the server attribute which specifies which server you want to use. Waves provides several built-in servers and we will continue to add more, since they are simply wrappers around Rack::Handlers to provide them with a more uniform interface. ・log. Allows you to configure the Waves logger, which is based on the built-in Ruby Logger, using a simple options Hash. log :level => :info, :output => $stderr log :level => :error, :output => ( “log.#{$$}” ), :rotation => :weekly ・reloadable。 Waves.reload が呼び出されるとき、Waves がどのモジュールを再読み込みするか決定します。通常、これらのモジュールは自動でコード再読み込みするために AutoCode(いくつかの Foundations で自動的に行われます) を mixin されています。 ・resource。 アプリケーションリソースクラスを設定します。これはしばしば、アプリケーションで扱われるリソースを割り当てるために委譲する単なるプロキシです。 ・database。 もしあなたが ORM (必須ではなく)を使用しているなら、ORM(接続文字列・オプションHash・など)へ属性と値として初期化オブジェクトを渡したくなるでしょう。 ・debug。 デバッグモードを実行しているなら true をセットしてください。この値は、あなたのアプリケーションにアクセスしやすく、同期レベルを決定し、自動的にコード再読み込みされるかを行います。 ・cache。 主な Waves cache(Waves.cache でアクセスできる) をセットします。あなたが使いたい主なキャッシュオブジェクト(Waves はシンプルなオプションを提供します。) ・application. あなたの Rack アプリケーションを定義します。デフォルトではこうです:: use ::Rack::ShowExceptions use Rack::Session::Cookie, :key => 'rack.session', :path => '/', :expire_after => 2592000, :secret => 'Change it' run ::Waves::Dispatchers::Default.new 継承可能な設定を利用する一般的な方法は、基本設定を共通で提供することで、少なくとも2つのサブクラス(Development と Production)が提供されます。また、これらには、テスト・演出・カスタム開発などの変化に対応するサブクラスがあるかもしれません。あなたは「データベース設定を変更する」といったとき、すべてのアプリケーションを更新するために Default 設定を再利用する Layer を作るかもしれません。(?)

表示オプション

横に並べて表示:
変化行の前後のみ表示:
記事メニュー
目安箱バナー