- 環境がおかしいのか起動でこけちゃう
- gem と ruby のバージョンをいろいろ試してもドツボにはまる一方
- サンプル見て説明見てその通り書いても動かない
で半ば放置してたんだけど。
GoRuCo 2010 - Alex MacCaw - Bowline: Ruby Desktop Applications from Gotham Ruby Conference on Vimeo.
開発者のデモを見(パクリ)ながら最低限の動作が確認できた。
binder を呼び出して model を作成

パラメータは javascript から ruby のオブジェクトに変換されて渡される。
Bowline.invoke("TweetsBinder", "sing" , "aaaa"); Bowline.invoke("TweetsBinder", "sing" , ["aaaa" , "bbb" , "cccc"]); Bowline.invoke("TweetsBinder", "sing" , {a:"A" , b:"B" , c:"C"});
↓
class TweetsBinder < Bowline::Binders::Collection bind Tweet class << self def initial #[{:body => "Hello Tweet"}] klass.all end def sing(param) tweet = Tweet.new tweet.body = "sing #{param.class}" + param.to_s tweet.save end end end
手順
以下、自作サンプル(git://github.com/basyura/bowline-test.git) を動かす場合の手順。
ruby のバージョン
$ ruby -v
ruby 1.9.1p378 (2010-01-10 revision 26273) [i386-darwin10.4.0]
bowline の最新版をインストール
$ git clone git://github.com/maccman/bowline.git
$ cd bowline
$ gem build hoge.gemspec
$ gem install -l foo.gem
テストリポジトリ作成
$ git clone git://github.com/basyura/bowline-test.git
$ cd bowline-test
$ bowline-bundle
メソッドが変更されているので直す
vendor/gems/ruby/1.9.1/gems/bowline-0.9.3/lib/bowline/initializer.rb
def set_autoload_paths
ActiveSupport::Dependencies.load_paths = configuration.autoload_paths.uniq
ActiveSupport::Dependencies.load_once_paths = configuration.autoload_once_paths.uniq
end
↓
def set_autoload_paths
ActiveSupport::Dependencies.load_paths = configuration.autoload_paths.uniq
ActiveSupport::Dependencies.load_once_paths = configuration.autoload_once_paths.uniq
end
起動
$ ruby script/run
<< 初期データ >>
config/initializers/tweets.rb
tweet = Tweet.new
tweet.body = "Hello World"
tweet.save
<< model 連携 >>
index.html
Bowline.invoke("TweetsBinder", "sing" , "aaaa");
Bowline.invoke("TweetsBinder", "sing" , ["aaaa" , "bbb" , "cccc"]);
Bowline.invoke("TweetsBinder", "sing" , {a:"A" , b:"B" , c:"C"});
tweets_binder.rb
class TweetsBinder < Bowline::Binders::Collection
bind Tweet
class << self
def initial
#[{:body => "Hello Tweet"}]
klass.all
end
def sing(param)
tweet = Tweet.new
tweet.body = "sing #{param.class}" + param.to_s
tweet.save
end
end
end
<< コンソールへのログ出力 >>
Bowline.log(users);
<< デバッグログの出力 @index.html >>
Bowline.trace = true;一番引っかかるのが binder を呼び出すところ。
Bowline.invoke("TweetsBinder", "sing" , {a:"A" , b:"B" , c:"C"});もっと簡単な呼び出し方あるはずなんだけどなぁ。サンプルでは
$("tweets").invoke("sing")
みたいな感じでやってんだけど。
