DataMapperでSetterメソッドを上書きして、プロパティの設定をコントロールするには、以下のようにします。

   1    def uri=(uri)
   2      attribute_set :uri, ::URI.parse(uri).normalize.to_s
   3    end

posted by Png genki on Sun 5 Apr 2009 at 06:56

度々忘れるのでメモしておきます。

   1  Merb::ControllerExceptions.constants.sort #=> ["Accepted", "ActionNotFound", "BadGateway", "BadRequest", "Base", "ClientError", "Conflict", "Continue", "Created", "ExpectationFailed", "Forbidden", "GatewayTimeout", "Gone", "HTTPVersionNotSupported", "Informational", "InternalServerError", "LayoutNotFound", "LengthRequired", "MethodNotAllowed", "MovedPermanently", "MovedTemporarily", "MultiPartParseError", "MultipleChoices", "NoContent", "NonAuthoritativeInformation", "NotAcceptable", "NotFound", "NotImplemented", "NotModified", "OK", "PartialContent", "PaymentRequired", "PreconditionFailed", "ProxyAuthenticationRequired", "Redirection", "RequestEntityTooLarge", "RequestRangeNotSatisfiable", "RequestTimeout", "RequestURITooLarge", "ResetContent", "STATUS_CODES", "SeeOther", "ServerError", "ServiceUnavailable", "Successful", "SwitchingProtocols", "TemplateNotFound", "TemporaryRedirect", "Unauthorized", "UnsupportedMediaType", "UseProxy"]

posted by Png genki on Sat 4 Apr 2009 at 22:58

Merb/DataMapper/CouchDBの環境で rspec を使う場合には、 spec_helper.rb で以下のように設定すると良いようです。

   1    config.before(:all) do
   2      DataMapper::AutoMigrator.auto_migrate(nil,
   3        *(DataMapper::Resource.descendants - [Merb::DataMapperSessionStore]))
   4    end

セッションストアを使っている場合は、 Merb::DataMapperSessionStore用のrepositoryを 別途指定すると良いと思います。

posted by Png genki on Sat 4 Apr 2009 at 22:11

DataMapper#auto_migrate!を実行すると、以下のようなコードが実行される。

   1  self.auto_migrate!(repository_name = nil)
   2    AutoMigrator.auto_migrate(repository_name)
   3  end

AutoMigrator#auto_migrateは以下のようになっている。

   1  def self.auto_migrate(repository_name = nil, *descendants)
   2    auto_migrate_down(repository_name, *descendants)
   3    auto_migrate_up(repository_name, *descendants)
   4  end

第二引数以降でDMのクラスリストを指定できる。 省略すると、DataMapper::Resource.decendantsが指定されたものとして動作する。 特定のリソースだけまとめてauto_migrateするには便利そうだ。

posted by Png genki on Sat 4 Apr 2009 at 21:58

今週末の4/5(日)にMerbJogを開催いたします。 Merb/Rubyなど、プログラミングに関する会話をしながら皇居の周りを走ります。 詳細・参加登録は以下のページをご覧ください。

http://atnd.org/events/510

開催時刻は多少変動する可能性があります。 雨天、悪天候の場合は延期となります。 ご了承ください。

posted by Png genki on Fri 3 Apr 2009 at 16:34

急遽大門駅付近で開催されることになったCouchDB勉強会のレポートです。

参加者: @maiha, @yugui, @yamaz, @takiuchi

そもそもCouchDBは何かというと、 Apacheのプロジェクト で、分散、耐障害性、スキーマフリー、ドキュメント指向なデータベスで、 RESTfulなAPIを使って制御します。

結構前から存在していたのですが、取りかかるきっかけがなくてスルーしていました。 しかし、dm-couchdb-adapterを使ってMerb/DataMapperで利用可能という事が分かり、にわかに盛り上がってきました。

早速、couchdbをインストールします。 いまのところ、ソースからcouchdb-0.9.0をインストールするのが一番良いようです。 macportsのcouchdb-0.9.0aでは動作が微妙に異なっているようでうまく動きませんでした。

dm-couchdb-adapterは、dm-moreにバンドルされているのですが、 そのままでは一部機能が利用できなかったので、 問題の分析を行いながら、 @maihaさんが改良を加えていきました。 改良版はこちらにあります。 使ってみたい場合は、maiha/dm-moreをcloneしてきて、

   1  % cd adapters/dm-couchdb-adapter
   2  % sudo rake install

すればOKです。 基本的な使い方は上記GitHubリポジトリのREADMEを読めば分かります。

結論として、普通にMerbアプリを作れるようになりました。 試しに作りかけの社内ツール的なものをMerb/DM/CouchDBの構成にしてみました。

http://watch.s21g.com

Future Worksとしては、

  • read_manyでのorderの指定。emitの第一引数を使う。逆順をどうするか。
  • count以外のaggregate (max, min, sum, avg) のサポート

などがありますね。

posted by Png genki on Fri 3 Apr 2009 at 14:46

ubuntuにcouchdbをソースから入れる手順をメモしておきます。

posted by Png genki on Fri 3 Apr 2009 at 03:46

データベースのメンテナンスのために、明日(2009/4/3)の早朝04:30ごろから30分程度、弊社のサービスに繋がりにくくなる時間が発生する見込みです。

ご迷惑をおかけいたしますが、よろしくお願いいたします。

Update

メンテナンスは無事に終了いたしました。

posted by Png genki on Thu 2 Apr 2009 at 13:58

いろいろあって、いまはこんな感じになってます。

   1  [alias]
   2    co = checkout
   3    ci = commit -a
   4    st = status
   5    up = pull --rebase
   6    a  = add
   7    b  = branch
   8    c  = commit
   9    d  = diff

posted by Png genki on Thu 2 Apr 2009 at 12:43 with 2 comments

Formula は、数式を簡単にブログに貼付けて共有できるサービスです。 このたび、FormulaをRails-2.3.2に対応させました。

また、対応作業の過程で、Rails用のpaginationライブラリである、 pagination_scopeのバージョン0.1.2をリリースいたしました。

:groupオプションを含むnamed scopeのpaginationに対応いたしました。

posted by Png genki on Thu 2 Apr 2009 at 01:35