• 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
 

dm-is-remixable は、Commentなどの複数のリソースにまたがって共用されるがちなリソースをDRYにするためのDataMapperプラグインです。

しかし、Validationのためのコードを記述しても、正常に動作しないという問題がありました。これは、以下のようにすれば解決できます。

   1  module Commentable
   2    include DataMapper::Resource
   3    is :remixable, :suffix => "comment"
   4  
   5    (..snip..)
   6  
   7    def self.included(base)
   8      base.class_eval do
   9        validates_present :message
  10      end
  11    end
  12  end

See Also

posted by Png genki on Mon 4 May 2009 at 17:56

Hello, Merbists!

Today, I explain how to develop Merb apps that runs on GAE/J environment by using dm-datastore-adapter.

First of all, here is whole source code of an example app. Please check it out.

After checking it out, you must edit appengine-web.xml file. Open it by editor and change the application name to yours. And then you should make war directory by typing this command.

   1  MERB_ROOT% jruby -S warble war

It generates files under tmp/war.

So far, you are ready to deploy this app to GAE/J Of course, you need an account of GAE/J to do it. Please get it in advance :-)

Let us go to deploy by this command.

   1  MERB_ROOT% appcfg.sh update -e {youraccount@gmail.com} tmp/war  

This process takes a time for the first time. If the log didn't say any errors, you got success!

Now your first Merb app on GAE/J is here at http://{your app name}.appspot.com/

Congrats!

Further improvement is your home work :-p

APPENDIX

All required gems are being packed into jar file located at lib/merb.jar. This enables you to pass the limit of which you can upload only 1000 files to GAE. If you add more gems to the jar file, you can do it like this

  • unpacking it
  • add gems
  • and repack it

Enjoy!

posted by Png takiuchi on Thu 23 Apr 2009 at 23:32 with 2 comments

Merbでconfig/router.rbの中で、リソースのカスタムアクションを追加する方法のメモ。

   1  resource :users,
   2    :collection => {:active => :get},
   3    :member => {:password => :get}

:collectionで指定したアクションは、resource(:users, :active) などのように参照できて、"/users/active" のような感じになります。

:memberで指定したアクションは、resource(@user, :password) などのように参照できて、"/users/1/password" のようなスタイルになります。

posted by Png genki on Mon 20 Apr 2009 at 14:57

GAEを使う上での大きな制限として、ファイル数1000までというのがあります。 これを乗り越えるために、unpackしたGemの中から不要なファイルを掃除したりする必要があったのですが、 関連するGem群をjarファイルにまとめる事でこの問題を乗り越えられます。

上記のファイルをlibの下に配置して、config/init.rb あたりでrequire_fixを読み込みます。 これはjarファイルの中のrbファイルの読み込みに関するバグを 回避するためのものです。

実際に以下のサイトでmerb.jarを使って運用しています。

これによって、事実上ファイル数制限に左右されずにアプリケーションを開発する事が出来るようになります。 ただ、1ファイルのサイズ制限(10MB)が存在するので、jarファイルが大きくなりすぎた場合は分割する必要があります。

posted by Png genki on Sun 19 Apr 2009 at 08:46

I shipped new dm-datastore-adapter today.

This update is a long jump from previous version. It includes following functions

  • Transaction. It utilizes the DataStore's Transaction API
  • OR conditions
       1  Post.all(:id => [1,2])
    
  • NOT conditions
       1  Post.all(:id.not => 4)
    

So now we can use most of functions defined in DM by using this adapter.

Enjoy!

posted by Png takiuchi on Fri 17 Apr 2009 at 17:25

非常にシンプルなのですが、毎回GlobalHelpersに書くのが面倒なので、 Merbから GRAVATAR のアイコンを表示するための merb_gravatarプラグインを作りました。

http://github.com/genki/merb_gravatar/tree/master

インストール方法

   1  % sudo gem install merb_gravatar

使用法

dependencyでmerb_gravatarを指定して、viewで以下のように使います。

   1  <%= gravatar @user.mail, 16 %>

第二引数はアイコンのサイズを1~80で指定します。省略すると80が選ばれます。

ss1

GAE/Jでも使えます(See http://watch-me.appspot.com/people)

posted by Png genki on Tue 14 Apr 2009 at 11:11

Today I shipped a new DataMapper plugin that enables us to easily develop Merb-apps been worked with GAE/J.

By using this plugin, you can seamlessly develop your Merb-apps between local and GAE/J environment.

For example, this site is powered by Merb/DM with the dm-datastore-adapter and running on the GAE/J

(This service is under construction :-p)

As a matter of fact, because it is still being alpha status, you must treat various issues regarding gem dependencies yet. I appreciate any kind of feedback and of course patches :-)

Enjoy!

posted by Png takiuchi on Mon 13 Apr 2009 at 15:01 with 11 comments

Bumble はGoogle App Engine for JavaのDateSoreを利用するためのライブラリですが、Railsで利用する前提で作られているので、 Merbで利用する場合には、以下のような修正を加えると良いようです。

bumble.rb

   1  module Bumble
   2    (..snip..) 
   3    def self.included(base)
   4      base.send :include, InstanceMethods
   5      base.send :extend, ClassMethods
   6      Merb::Router.root_behavior = 
   7        Merb::Router.root_behavior.identify(Bumble => :key)
   8    end

これによって、resource(@person) #=> /people/5 のようにidentifyしてくれるようになります。

posted by Png genki on Sun 12 Apr 2009 at 02:23

2日前ぐらいからいろいろ頑張ってたのですが、ようやくGAEjの本番環境でMerbアプリを動かせました。

http://jmerbist.appspot.com/

ss

使っているgemをfreezeする仕組みがあるフレームワークであれば、どれでも以外と簡単に動きそうな感じがします。

いやー、これは色々面白い事が出来そうですね!

posted by Png genki on Thu 9 Apr 2009 at 17:23

以前、Merb用のaliasの設定をご紹介しましたが、今度はjruby版です。

   1  alias jm='PATH=./bin:$PATH jruby -S merb'
   2  alias jmi='jm -i'
   3  alias jmg='PATH=./bin:$PATH jruby -S merb-gen'

rubyとjrubyを両方使ってると、

   1  % jruby -S merb

のように書く事が多いので、aliasを設定しておくと便利ですね。

posted by Png genki on Thu 9 Apr 2009 at 01:48