capistranoはwebアプリケーションをデプロイするための非常に便利なツールですが、出力のログがちょっと読みにくく、どのタスクが実行されたのかが分かりにくいな、と感じていました。 そこで、 capistrano_colors というGemを使って、capistranoの出力を色づけしてみる事にしました。 これを使うと、以下のように分かりやすい感じになります。

ss

設定方法ですが、まずはGemをインストールします。

   1  % sudo gem install capistrano_colors

続いて、config/deploy.rb (いわゆるレシピファイル)の中か、 ~/.caprcの中で、以下の一行を追加します。

   1  require 'capistrano_colors'

これでOKです。あとは、普通にcapコマンドを使えば、 色づけされた出力が得られます。

posted by Png genki on Sun 18 Jan 2009 at 02:30

#githubで質問したら、この記事を紹介してくれたので読んでみました。

Gem Rebuilds only on Version Bump

We recently changed the system so that only gemspec pushes that contain a bumped version will be built. This will prevent accidental gem clobbering and we can now guarantee that when you release a specific gem version, that version will never change.

昔はgemspecファイルがちょっとでも編集されていれば良かったのですが、 1/13の時点で、GitHub上でGemを再生成するためには、バージョン番号を増やさないと駄目になっているようです。

僕は、コメント欄でhalorgiumさんが言っているように、 "next-to-be-released"アプローチを支持したいのですが、どうなりますかね。 Merbや最近のRailsのように、ライブラリが全てpackage化されたGemの形で提供される事が想定されている場合、 いままではGitHubでEdgeGemを作ってそれを使っていたのですが、 これからはバージョン番号を上げない限り、それが出来なくなってしまいます。

とりあえずは、4番目のリビジョン番号を機械的にインクリメントする事で対応しようかなと考えていますが、もっと良い方法はないものかな。

他に気になった話題として、technomancyさんがコメントで書いている事によると、次のバージョンのRubygemsからは、"1.1.0.RC1"のような プリリリースバージョンである事を示す文字列を認識するようになるそうです。 確かにこうすれば"next-to-be-released"的な使い方も出来るので良いかな。 しかし、version文字列が数字とドットだけであるという想定に依存してるソフトウェアが、しばらくエラーを出すようになる気もしますね。

posted by Png genki on Sun 18 Jan 2009 at 00:20

I am using merb with passenger on our production server. The passenger is going well in most of cases. But if dependent gems have been updated, it becomes acting up when it got restarted. After I encountered such situations several times, I decided to begin investigation about the issue.

Detail of the issue is as follows.

  • My merb app becomes causing errors after restarting of passenger by "touch tmp/restart.txt" if dependency gems were updated and they have no compatibility.
  • Even if the gems were compatible, my merb app kept using old gems until apache is reloaded.
  • pids were changing successfully while restarting.
  • /etc/init.d/apache reload can refresh everything as expected.
  • "touch tmp/restart.txt" can't.

I wonder there is the master of master processes which keeps LOAD_PATH and it is refusing to use new gems. I am thinking I should investigate the Rack.

Update

Finally, the issue was solved!

The solution is found here

posted by Png takiuchi on Sat 17 Jan 2009 at 22:42

Mattettiさんから連絡があって、 forkして開発していたmerb_babel本家に取り込んでもらいました。 以下のような機能を追加しています。

  • Merb::Requestからの国コード判別機能
  • YAMLを利用した階層化ローカライゼーション
  • 時刻のローカライゼーション

将来的には、merb-sliceの形にして、ローカライズファイルの オンライン編集が出来るようにしたい。

posted by Png genki on Sat 17 Jan 2009 at 04:54

Merbのプラグインを作る場合、merb-gen plugin plugin-name でひな形が生成されますが、現状では生成されるspecがほとんど空っぽなので、 ちゃんとしたspecを書くための足場の作り方を紹介します。

まずは、spec/spec_helper.rb を以下のような感じに準備します (これはdm-has-versionsの例です)

   1  $:.push File.join(File.dirname(__FILE__), '..', 'lib')
   2  
   3  require 'rubygems'
   4  require 'merb-core'
   5  require 'dm-core'
   6  require "spec"
   7  require 'dm-has-versions/has/versions'
   8  require 'dm-aggregates'
   9  
  10  DataMapper::Model.append_extensions DataMapper::Has::Versions
  11  Merb.disable(:initfile)
  12  Merb.start_environment(
  13    :testing      => true,
  14    :adapter      => 'runner',
  15    :environment  => ENV['MERB_ENV'] || 'test',
  16    :merb_root    => File.dirname(__FILE__) / 'fixture',
  17    :log_file     => File.dirname(__FILE__) / "merb_test.log"
  18  )
  19  DataMapper.setup(:default, "sqlite3::memory:")
  20  
  21  Spec::Runner.configure do |config|
  22    config.include(Merb::Test::ViewHelper)
  23    config.include(Merb::Test::RouteHelper)
  24    config.include(Merb::Test::ControllerHelper)
  25  
  26    DataMapper.auto_migrate!
  27  end

この例では、DataMapperを使う事を前提としています。 "sqlite3::memory:" を指定することで、テストのための データベースファイルなどを用意する必要がないので楽です。

テストで利用されるクラス群は、spec/fixture 以下に、 通常のMerbアプリケーションと同様のディレクトリ階層で用意します。

   1  % tree spec/fixture [~/project/dm-has-versions:master]
   2  spec/fixture
   3  `-- app
   4      `-- models
   5          |-- comment.rb
   6          `-- story.rb

posted by Png genki on Fri 16 Jan 2009 at 13:35

DataMapper用のバージョン管理プラグイン、 dm-has-versions をリリースしました。

dm-is-versionedというライブラリが既にあるのですが、Railsで慣れ親しんだacts_as_versionedと微妙に挙動が違うのと、revert_toやversion=ができないなど、細かいところが足りない感じがしたので作りました。

USAGE:

以下のコードをご覧の通りです。

   1  class Story
   2    include DataMapper::Resource
   3          
   4    property :id, Integer, :serial => true
   5    property :title, String
   6    property :updated_at, DateTime
   7  
   8    has_versions :ignore => [:updated_at]
   9  end
  10  
  11  Story.auto_upgrade!
  12  
  13  story = Story.create(:title => 'hello')
  14  story.version #=> 0
  15  story.update_attributes :title => 'good night'
  16  story.version #=> 1
  17  story.title #=> 'good night'
  18  story.version = 0
  19  story.title #=> 'hello'

auto_upgrade!は最初に一回だけ必要です。

posted by Png genki on Fri 16 Jan 2009 at 03:42

諸々の事情があり、最近Windowsを使うはめになってるのですが、TeX環境がまったくインストールされていなかったので、環境整備しています。

そこで、せっかくなので OMakeを使って継続ビルド をしたいと思います。

Windowsを良く使ってる人の参考になれば。この時期は卒論頑張ってる人が多いと思うので。

(Windowsを普段あまり使わない僕がいうのもなんですが・・・)

参考

身長が5cm伸びて、念願の170cm超えです!

用意するもの

手順

インストールする

The OMake build systemからダウンロードしてきたインストーラを使ってインストールします。

何も考えずにOKとかNextみたいなボタンをクリックすれば大丈夫です。

使ってみる

上に挙げた hayamizさんの記事の手順そのまま実行していきます。

OMakefileとOmakerootの作成

まず、コマンドプロンプトを開いて、作業ディレクトリで omake --install とします。

   1  C:\・・・\作業ディレクトリ>omake --install
   2  *** omake: creating OMakeroot
   3  *** omake: creating OMakefile
   4  *** omake: project files OMakefile and OMakeroot have been installed
   5  *** omake: you should edit these files before continuing
これで、OMakefileとOMakerootが作業ディレクトリに作成されます。

OMakefileの編集

ファイルの内容を消して、まるまるコピペしてください。

   1  LATEX = platex
   2  
   3  LaTeXDocument(main, main)
   4  
   5  .DEFAULT: main.dvi

これで、TeXファイルを保存するたびに、ビルドされ、DVIファイルが作成されます。

ついでにPDFも作成したいときは、

   1  LATEX = platex
   2  DVIPDFM = dvipdfmx
   3  
   4  LaTeXDocument(main, main)
   5  
   6  .DEFAULT: main.pdf main.dvi
としてください。

OMake起動!

コマンドプロンプトで omake コマンドを実行します。

   1  C:\・・・\作業ディレクトリ>omake -P --verbose
   2  *** omake: reading OMakefiles
   3  --- Checking for latex... (found c:\usr\local\bin\latex.exe)
   4  --- Checking for uname... (found c:\Program Files\Git\bin\uname.exe)
   5  --- Checking LaTeX capabilities... (tetex2 mode enabled)
   6  *** omake: finished reading OMakefiles (4.14 sec)
   7  - scan . scan-latex-main.tex
   8  + <compute 1 value dependencies>
   9  - scan . scan-latex-main.tex
  10  + Shell.echo()
  11       | Shell.run-latex(stdout-to-stderr platex -file-line-error '-output-comment
  12  =LaTeX Output (built with OMake)' -recorder main.tex)
  13  This is pTeXk, Version 3.141592-p3.1.4 (sjis) (Web2C 7.5.3)
  14  
  15   ・
  16   ・
  17   ・
  18  

起動すれば、あとはTeXファイルを編集し、保存するだけです。

これで、編集→保存→ビルド→編集→保存→ビルド→・・・というわずらわしいビルドの手間が省けます。

ちなみに・・・

   1  --- Checking for uname... (found c:\Program Files\Git\bin\uname.exe)
とか出ているので、もしかしたら、 uname.exe が必要なのかもしれません。 僕の環境では、Gitをインストールしたついでに入っていたみたいです。

これは、ついでにバージョン管理もしろってことですね!

まとめ

  • OMakeすばらしい!
  • Linuxと違って、Windowsはインストールがめんどくさい
  • 複数ファイルのときのビルドは、今後の課題
posted by Png y_tsuda on Thu 15 Jan 2009 at 14:21 with 1 comment

Merbの主要な開発者の一人であるwycats氏のgithub上のリポジトリに、 Rails3の元となるかもしれないコードがコミットされているようです。

ss

見慣れないciというディレクトリは、Continuous Integrationではないか(maiha談)とのこと。

Update

ActiveORM なるものを見つけました。これは予想通り、AR, DM, Sequelなどの共通基底となる何かでしょうか?

   1  module ActiveORM
   2    autoload :VERSION, 'active_orm/version'
   3    autoload :Core, 'active_orm/core'
   4    
   5    module Proxies
   6      autoload :AbstractProxy, 'active_orm/proxies/abstract_proxy'
   7      autoload :DataMapperProxy, 'active_orm/proxies/active_record_proxy'
   8      autoload :DataMapperProxy, 'active_orm/proxies/datamapper_proxy'
   9      autoload :SequelProxy, 'active_orm/proxies/sequel_proxy'
  10    end
  11    
  12    class << self
  13      include Core::ClassMethods
  14    end
  15  end

これはBINGOっぽい。

See Also

posted by Png genki on Thu 15 Jan 2009 at 09:54

Recently, I've been making web sites by using Merb. It was like a battle lacking logistics.

I made and released dm-pagination on github. http://github.com/genki/dm-pagination/tree/master

Yes, I know dm-is-paginated-0.0.1, but its spec files was not working. The dm-pagination is able to be used with arbitrary collections which include scoped_query.

You can easily paginate, like this:

   1  class Posts
   2    def index
   3      @posts = Post.paginate(:page => params[:page])
   4    end

Links will be drawn by calling simple helper method.

   1  <ul>
   2  <% @posts.each do |post| %>
   3    <li><%= h(post.body) %></li>
   4  <% end %>
   5  </ul>
   6  <%= paginate @posts %>

merb_slice-gen is also available in order to provide useful generators for slices of which it has namespace but doesn't have subdirectories.

You can generate controller, resource and resource_controller in slice project, like this

   1  % slice-gen controller top

it generates controller files enclosed by SliceName module without any subdirectories.

In addition, there are other gems I made.

posted by Png takiuchi on Thu 15 Jan 2009 at 03:05

dm-is-paginated-0.0.1は、specが走らない状態だったので、 Railsの pagination_scope風味のDataMapper用Paginationライブラリとして、 dm-pagination を作りました。

   1  class Posts
   2    def index
   3      @posts = Post.paginate(:page => params[:page])
   4    end

上記のようにコントローラでpaginationオブジェクトを作成し、 Viewから以下のように参照します。

   1  <ul>
   2  <% @posts.each do |post| %>
   3    <li><%= h(post.body) %></li>
   4  <% end %>
   5  </ul>
   6  <%= paginate @posts %>

posted by Png genki on Thu 15 Jan 2009 at 00:41