query: tag:plugin

Rails-2.3.11用のExceptionNotificationプラグインは以下にあるようです (via
@a_matsuda

基本的にはこれを script/plugin install -r 2-3-stable
すれば良いのですが、ConsiderLocalの実装にバグがあるので
直す必要があります。

具体的には、以下のファイルの self.included の場所をConsiderLocalモジュールの直下に移動します。

あとはREADME通りに設定して、ConsiderLocalをApplicationControllerからincludeすればok

posted by genki genki on Sat 11 Jun 2011 at 06:46 with 0 comments

GitリポジトリのRailsプラグインをインストールするときに、
標準では master ブランチがインストールされますが、
特定のブランチの内容をインストールしたい場合には、以下のように -r オプションを使用します。

sh>>
script/plugin install --force https://github.com/rails/exception_notification.git -r 2-3-stable
<<--

上記の例では 2-3-stable ブランチをインストールします。

posted by genki genki on Sat 11 Jun 2011 at 05:18 with 0 comments

ScalaのCLIな開発環境 sbt を使ってjava -jarでstandalone実行可能な
jarファイルを作る方法をメモしておきます。

sbtにはプラグイン機構が備わっていて、今回は
sbtプラグインのproguardというのを利用します。
sbtプラグインは、以下のファイルを記述することで導入可能です。

project/plugins/Plugins.scala

scala>>
import sbt._
class Plugins(info: ProjectInfo)
extends PluginDefinition(info)
{
val proguard = "org.scala-tools.sbt" % "sbt-proguard-plugin" % "0.0.5"
}
<<--

ついでにProjectファイルでProguardを使うように設定します。

project/build/FooBar.scala

scala>>
import sbt._

class FooBar(info: ProjectInfo)
extends DefaultProject(info)
with ProguardProject
{
override def mainClass = Some("main.scala.FooBar")
override def proguardOptions = List(
"-keepclasseswithmembers public class * " +
"{ public static void main(java.lang.String[]); }",
proguardKeepLimitedSerializability,
proguardKeepAllScala,
"-keep interface scala.ScalaObject")
override def proguardInJars =
Path.fromFile(scalaLibraryJar) +++ super.proguardInJars
}

<<--

あとは、sbtから

pre>>
sbt> reload
sbt> update
sbt> proguard
<<--

target/scala_x.x.x/foobar_x.x.x-x.min.jar
が生成されるので、これを java -jarすれば起動できます。

posted by genki genki on Wed 9 Mar 2011 at 22:11 with 0 comments

ちょっと前になりますが、Snow LeopardでTerminalCopyOnSelectが動かないというレポートを頂いておりました。
まだSnow Leopardへの移行ができていなくて放置状態だったのですが、
Nyahoさんがgithubでpull requestを送ってくれたのでmergeしてみました。

TerminalCopyOnSelect.bundle.zip

手元の環境では動作検証できていないのでSnow Leopardで動くかどうかは未確認ですが、環境をお持ちの方はお試しあれ。

See Also

posted by genki genki on Wed 23 Sep 2009 at 10:10 with 1 comment

最近Twitterクライアントとして
Termtter
を使っています。
適度に見づらいのが、かえって邪魔にならなくて良い感じです。

発言中のURLを開くときに、$ab のような識別子を指定して開くプラグインを作りました。

open.rb

pre>>
USAGE

open $dq
open 1st URI in $dq
open $dq 2
open 2nd URI in $dq
<<--

posted by genki genki on Sat 15 Aug 2009 at 03:53 with 4 comments

As I mentioned before, I am making small abstraction FW.
For giving the task a vista, I want to make a list of the requirements in advance.

  • Abstract Model (I hope the ActiveORM will be)
  • Basic HTML tag helpers (such as "tag", "url_for")
  • Starting up hook to modify others
  • Way to register helpers
  • Way to read/write configuration of plugin

In particular, abstract model is quite important.
There are already several efforts, but they all are probably not succeeding.
I think the reason of the failure is what most of them had been concentrating to make abstraction of models for models.
It must be designed for agnostic plugins.

Suppose you are an application developer and you are writing some code.
Obviously, the FW and ORM have already been chosen.
So you have no need to treat various ORMs for making the app.
Only agnostic plugins need the abstract model.

What is the requirements of the plugins?

  • read_many with options for specifying :limit and :offset
  • read_one, create, destroy, update
  • read/write access to attributes
  • counting, searching, association and so on.

Is it the DataMapper?
Yeah, it is nearly equals to. But it must have more flexibility.

In conclusion, we should not make an abstraction of models but an abstraction of plugin's requirements to FW.

posted by genki genki on Thu 23 Jul 2009 at 20:41 with 0 comments

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

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

ruby>>
module Commentable
include DataMapper::Resource
is :remixable, :suffix => "comment"

(..snip..)

def self.included(base)
base.class_eval do
validates_present :message
end
end
end
<<--

See Also

posted by genki genki on Tue 5 May 2009 at 01:54 with 0 comments

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

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

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

posted by genki genki on Thu 2 Apr 2009 at 01:31 with 0 comments

Railsでモデルのバージョン管理を行うというと、
acts_as_versionedを使うのが一般的でしたが、
しばらくメンテナンスされていないのと、githubでforkがカオス状態になっていて、公式ドキュメントと実装が一致しなくなっているなど、ちょっと使いにくい状況になっているようなので、それ以外の選択肢を調べてみました。

  • version_fu
    かなりシンプルな作り。ソースは100行程度。そのぶん、Versionedテーブルの作成などは自動でやってくれない。
  • SimplyVersioned こちらもシンプル路線。Versionedテーブルを使わずに、1つのテーブルでhas_manyアソシエーションを使って管理するタイプ。validates_uniqueness_ofとかを使っていないならこれでも良いかな。
  • acts_as_versioned_association
    aavでassociationを含むモデルのバージョニングが出来なかった問題を解決したものらしい。
posted by genki genki on Wed 1 Apr 2009 at 11:39 with 0 comments

あのAsakusa.rbから、dm-paginationバージョン0.3.2がリリースされました。

dm-pagination-0.3.2 is out from Asakusa.rb

最近の改善が取り込まれています。
dm-paginationはMerb with DataMapper用のpaginationを提供するプラグインです。
Rails用の
pagination_scope
の姉妹プラグインです。

See Also

posted by genki genki on Tue 31 Mar 2009 at 10:32 with 0 comments

Merbのプラグインの多くは、Merb以外の場所でも使えるように設計されています。
また、いくつかのRailsプラグインも、Merbや他のプラットフォームで利用できたり、単体でも利用可能になっていたりします。

これらのプラグインは、Agnosticなプラグインと呼ばれています。
従来のプラグイン機構が、特定のフレームワークの機能を拡張する役割にとどまっていたのに対して、Agnosticなプラグインは、複数のプラットフォームを股に掛けて活躍します。

fig

このような動きは、従来のフレームワークとプラグインの関係を改めるものとして注目に値するものだと思います。
フレームワーク間で共通に必要となるようなプラグインの重要性が高まり、
今まで分散していたプラグイン開発リソースが、統合されることによって効率化がはかられたと見る事も出来ます。

これからは、フレームワークの知識だけでなく、
主要なAgnosticプラグインの利用法に習熟する事が
生産性の向上のために必要になってくるかもしれません。

posted by genki genki on Wed 11 Mar 2009 at 07:48 with 0 comments

ちまたで話題のCanonical URLですが、既存のRailsアプリケーションを
Canonical URLに対応させるためのプラグインを紹介します。

config/environment.rbの中で、以下の行を追加します。

ruby>>
config.gem 'mbleigh-canonical-url',
:lib => 'canonical_url',
:source => 'http://gems.github.com'
<<--

続いて、sudo rake gems:install
でGemをインストールします。
次に、ViewのHEADの中に以下の一行を追加します。

html>>
<%= canonical_link_tag %>
<<--

最後に、Controllerのshowアクションの中で、
respond_toやrenderの呼び出しより上に以下の一行を追加します。

ruby>>
canonical_url article_path(@article)
<<--

これはarticlesというリソースの例ですが、
実際のアプリケーションで使っているリソース名に置き換えてください。

これで完了。
Slagを使っていたりする場合に、Permalinkをcanonical urlとして指定したりするのが典型的な使い方になるのかな。

See Also

posted by genki genki on Sat 14 Feb 2009 at 22:40 with 0 comments

I made a simple plugin to explain a concept of render-filters.

merb_render_filter

In your controller,

ruby>>
class Posts < Application
before_render :set_title1, :only => :show
before :set_title2, :only => :show

def show(id)
@post = Post.get(id)
display @post
end

private
def set_title1
@title = @post.title # <= you can access to @post here
end

def set_title2
@title = @post.title #=> @post is nil!
end
end
<<--

Without this plugin, you couldn't access to instance variables from before-filters.
Of course you can prepare @post in the first before-filter so that you can access from other before-filters.
But why Merb has the action-args?
They are ignored in such case.
This was the problem I wanted to solve by the plugin.

posted by takiuchi takiuchi on Sun 1 Feb 2009 at 10:08 with 0 comments

Merbを使ってWebアプリケーションを開発している or
しようと考えている方の為に、
お勧めのプラグイン/Slice情報を共有するサービス
Merbist Plugins
をテスト公開いたします。

ss

デザインもScaffoldに毛が生えた程度で、
この手のサービスには欠かせないRatingなどの基本機能が無い状態なのですが、
そもそもMerbのプラグイン情報を共有する場所が無いので、
無いよりはちょっとましかなという事で公開しておきます。

merb_rating, dm-has-rating のようなプラグインを見つけたら、
あるいは作ったら、Rating出来るようになると思います。

ちなみに、新着プラグインのFeedも配信しています。

よろしくお願いします。

posted by genki genki on Sat 24 Jan 2009 at 02:38 with 0 comments

I released the merb_full_url plugin that provides URL which has origin (scheme, host and port)

You can install this gem like this;

pre>>
% sudo gem install merb_full_url --source http://merbi.st
<<--

And you get full URLs by calling full_url/full_resource methods instead of url/resource.

But I think, it is better for merb to become providing such methods in advance :-)

posted by takiuchi takiuchi on Sat 24 Jan 2009 at 02:24 with 0 comments

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

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

ruby>>
$:.push File.join(File.dirname(FILE), '..', 'lib')

require 'rubygems'
require 'merb-core'
require 'dm-core'
require "spec"
require 'dm-has-versions/has/versions'
require 'dm-aggregates'

DataMapper::Model.append_extensions DataMapper::Has::Versions
Merb.disable(:initfile)
Merb.start_environment(
:testing => true,
:adapter => 'runner',
:environment => ENV['MERB_ENV'] || 'test',
:merb_root => File.dirname(FILE) / 'fixture',
:log_file => File.dirname(FILE) / "merb_test.log"
)
DataMapper.setup(:default, "sqlite3::memory:")

Spec::Runner.configure do |config|
config.include(Merb::Test::ViewHelper)
config.include(Merb::Test::RouteHelper)
config.include(Merb::Test::ControllerHelper)

DataMapper.auto_migrate!
end
<<--

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

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

pre>>
% tree spec/fixture [~/project/dm-has-versions:master]
spec/fixture
-- app -- models
|-- comment.rb
`-- story.rb
<<--

posted by genki genki on Fri 16 Jan 2009 at 12:16 with 0 comments

Merbでタイムゾーンを選択するためのプラグインを作りました。

USAGE:

Gem(genki-merb_timezone_select)をインストールして、dependencyを設定し、form_forブッロクの中で、以下のように使います。
ruby>>
<%= timezone_select :timezone %>
<<--

以下のような感じの結果が得られます。

ss

posted by genki genki on Tue 6 Jan 2009 at 03:26 with 0 comments

MerbのコントローラをParts的に利用するプラグイン
merb_component
を作りました。
Railsのcomponentに似てますが、Railsと比べて大分シンプルに実現できています。

使い方

githubからgenki-merb_componentをインストールし、
config/dependencies.rbの中で、以下のように記述します。

ruby>>
dependency "genki-merb_component", :require_as => "merb_component"
<<--

あとは、Viewの中から以下のような感じで呼び出せばOKです

ruby>>
<%= component Users, :show, :id => 1 %>
<<--

merb_partsと違って、全てのコントローラに対して利用出来ます。

posted by genki genki on Mon 5 Jan 2009 at 05:38 with 0 comments

以前、
benchmarkforrails
というRailsプラグインを紹介した事がありました。
しばらく互換性の問題があって使うのをやめていたのですが、
久々にRails-2.2.2環境で使ってみたら動いたので、
最新版のリポジトリの場所を紹介します。

gitで公開されているので、以下のようにインストールします。

pre>>
% ./script/plugin install git://github.com/cainlevy/benchmarkforrails.git
<<--

See Also

posted by genki genki on Fri 26 Dec 2008 at 14:20 with 0 comments

I made a SIMBL plugin
for Terminal.app which enable us to copy on selection.
Here is the plugin named TerminalCopyOnSelect.

TerminalCopyOnSelect.bundle.zip

INSTALLATION

  1. At first, you should install
    SIMBL.
  2. Download the zipped plugin file I mentioned above and expand it.
  3. Copy the extracted file "TerminalCopyOnSelect.bundle" to the plugin directory which is located at ~/Library/Application Support/SIMBL/Plugins/
  4. Terminate all processes of Terminal.app and restart it.

You're done!
Now you can get copied selected text from the terminal when you released mouse button on it.

You are also able to disable this feature by turning off the following menu "Copy On Select".

ss01

Finally, I opened the source of this plugin on the GitHub
under the MIT license.

Enjoy!

posted by takiuchi takiuchi on Tue 25 Nov 2008 at 19:10 with 8 comments

Railsのacts_as_searchableプラグインに類似検索機能をつけた
acts_as_searchable_with_similarityを、GitHubに移管いたしました。

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

今後はこちらをお使いいただけるとありがたいです。

posted by genki genki on Sat 25 Oct 2008 at 05:19 with 0 comments

久々にRailsプラグインの紹介です。

Plugins - NamedScope

This is not simple hack of named scope like you might find in WillPaginate. This is a fully backported and tested version of NamedScope that will work on rails 1.2.6 or 2.0.4.

Rails-2.0.4およびRails-1.2.6でNamedScopeが使えるようになるようです。

posted by genki genki on Sun 5 Oct 2008 at 07:26 with 0 comments

This release includes a small spec change.

I changed spec of count method. Now it works without :group option.
If you want old behaviour, you can use count_ids method instead.

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

Good luck ;-)

posted by takiuchi takiuchi on Sun 28 Sep 2008 at 03:55 with 0 comments

named_scopeによるPagination
を行うためのGemを作りました。
通常はwill_paginateを利用するほうがいいと思いますが、
:joinsを含む複雑なnamed_scopeを介してpaginationを行いたい場合には、
利用すると便利かもしれません。

pagination_scope

使い方

まず、モデルクラスの中でincludeします。

rails>>
class Post
include PaginationScope
end
<<--

これによって、Postクラスにpaginateというnamed_scopeが作成されます。

続いて、Paginationを利用したいコントローラのアクションメソッド内で、

rails>>
class PostsController < ApplicationController
def index
@posts = Post.not_deleted.paginate(params[:page], 10)
<<--

のようにScopeを取得します。

続いて、Viewで以下のようにPagination用HTMLを生成します。

html>>
<%= paginate @posts %>
<<--

paginateメソッドは PaginationScope によって導入されるViewヘルパーです。

posted by genki genki on Sat 16 Aug 2008 at 23:14 with 0 comments

named_scopeは大変素晴らしいRailsの新しい機能ですが、
おなじみのwith_scopeのように、
スコープつきのブロックを伴った利用ができないという問題がありました。
例えばこんな感じに利用しようとしてもうまくいきません。

ruby>>
User.active do
User.count # => Not run
end

User.active.with_scope do
User.count #=> Not scoped
end
<<ruby

そこで、昔ながらのwith_scopeと同じようにnamed_scopeを使えるようにする
Gemプラグインを作りました。

with_named_scope

これを使うと、以下のように期待通りに動きます。

ruby>>
User.active.with do
User.count #=> User.active.count
end
<<--

なかなか便利だと思うので、Rails本家にパッチを送っておきました。

Improved named_scope to be used like as with_scope

posted by genki genki on Fri 1 Aug 2008 at 21:09 with 0 comments

ちょっとActiveScaffoldを使う機会があったので自分用にメモ。

まずは配布サイト。

インストール方法。

sh>>
% ./script/plugin install http://activescaffold.googlecode.com/svn/tags/active_scaffold
<<--

利用レポート、チュートリアルなど。

ActiveScaffoldの前身であるAjaxScaffoldGeneratorはGemで提供されていたのですが、ActiveScaffoldはプラグインのみの提供。

posted by genki genki on Sun 13 Apr 2008 at 21:10 with 1 comment

久々にRailsプラグインの紹介です。

BackgroundFu
は、Jacek Becela氏による、時間がかかる処理をバックグラウンドプロセスで実行するためのRailsプラグインです。

使い方ですが、まずはインストール。

sh>>
% svn export https://svn.trix.pl/public/background_fu vendor/plugins/background_fu
<<--

続いて、各種ファイルを生成するGeneratorを起動します。

sh>>
% ./script/generate background
<<--

バックグラウンド処理の情報を管理するテーブルを作成するためのmigration
ファイルが生成されるので、マイグレーションを実行します。

sh>>
% rake db:migrate
<<--

これでひとまず準備完了。あとは、lib/workersの下に生成されている
exampleファイルや
README
を参考にしながら、Workerクラスを作ります。

Workerクラスの例

ruby>>
class ExampleWorker
def add(a, b)
a + b
end
end
<<--

このWorkerを呼び出す場合は、以下のようにします。

rails>>
Job.enqueue!(ExampleWorker, :add, 1, 2)
<<--

単純に時間がかかる処理を裏で実行したいだけならこれでOKです。
簡単ですね。
必要であれば、JobのIDを使ってもうちょっと複雑な処理も実行可能です。

Workerプロセスの起動は、以下のコマンドで行います。

sh>>
% ./script/daemons start
<<--

stopで停止、restartで再起動です。RAILS_ENVを指定する場合は、

sh>>
% RAILS_ENV=production ./script/daemons start
<<--

こんな感じですね。デフォルトではdevelopment環境になります。

See Also

posted by genki genki on Tue 25 Mar 2008 at 03:58 with 0 comments

While creating AR extending plugin, I had some trouble to test it. Because testing a such plugin needs creating db and its absurd. So here's my solution. 

Tip #1: First, extend the AR, and name it as a MockBase. Then extend MockBase to test your class. This prevents other tests like your rails app or other plugins from failing.

Tip #2. Requiring environment.rb loads all rails env this includes AR. Thus you can you use AR in your test class.

rails>>
#acts_as_notifiable_test.rb
begin
require File.dirname(FILE) + '/../../../../config/environment'
rescue LoadError
require 'rubygems'
gem 'activerecord'
require 'active_record'
end

class MockBase < ActiveRecord::Base; end
MockBase.class_eval do
alias_method :save, :valid?
def self.columns() @columns ||= []; end

def self.column(name, sql_type = nil, default = nil, null = true)
columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type, null)
end
end

class MockModel < MockBase
acts_as_notifiable :callback => :after_create, :message => "hello", :recipients => "test@gmail.com"
end

class ActsAsNotifiableTest < Test::Unit::TestCase
def test_option_message_string
assert_equal "hello", MockModel.new.instance_eval{jabber_message}
end
<<--

###Reference

posted by hibi hibi on Fri 21 Mar 2008 at 00:00 with 0 comments

数年に渡ってメンテナンスされているようなRailsアプリケーションの
config/routesは、
徐々にスパゲッティ化していく傾向があるように思えます。
ということで、今回は、
コントローラごとにRoutesをまとめて綺麗に記述する方法を紹介します。

方法は簡単です。with_optionsを使って、
prefixオプションを指定するようにします。

rails>>
map.with_options(:controller => 'posts',
:name_prefix => 'posts_',
:path_prefix => 'posts') do |posts|

posts_rss_path => 'posts/rss'

posts.rss 'rss', :action => 'rss'
end
<<--

しかし、全部のControllerにこれを書くのは面倒かもしれません。
ということで、プラグインを作りました。

このプラグインを使えば、以下のようにRoutesを書くことができます。

rails>>
map.with_controller('posts') do |posts|
posts.rss # posts_rss_path => 'posts/rss'
end
<<--

map.namespace(:posts)を使うと似たようなことができるのですが、
これは名前空間の作成に特化されているので、
今回の目的のために使用すると、若干思わしくない挙動をするようです。

posted by genki genki on Fri 14 Mar 2008 at 22:30 with 0 comments

RaPT
については以前
RaPT: Railsプラグイン管理ツール
で紹介しましたが、
手短にRaPTを使ってRailsプラグインを使う方法をまとめておきます。

インストール

sh>>

gem install rapt

<<--

プラグインをインストール

RAILS_ROOTで以下を実行。

sh>>
$ rapt install http://repo.pragprog.com/svn/Public/plugins/annotate_models
<<--

プラグインをアップデート

まさにこの為にRaptを使う価値があるという代物。

sh>>
$ rapt update annotate_models
<<--

便利です。

posted by genki genki on Thu 6 Mar 2008 at 15:11 with 2 comments

プラグインを作るのに手間取ったのでメモ。
ARに機能を追加させるようなプラグインのテストを書く際、AR派生クラスをnewしてメソッドを呼び動作を確かめたりしたくなります(私の場合、privateメソッドを呼びたくなった)。でもテストのためだけにテーブルを作るのはばからしい。でMockを使う方法、ARのテスト用Mockの登場です。

ポイントとしては、MockBaseで一旦ARを派生させてから、MockBaseを派生させたクラスを作るのがミソです。そうすることで他のテストに影響を与えないようにすることができます(tips from takiuchi)。

あともう一つ、environment.rbをズズーっとロードすることでRails全体を読み込むことができます。それによってARを使えるようになります。

rails>>
#acts_as_notifiable_test.rb
begin
require File.dirname(FILE) + '/../../../../config/environment'
rescue LoadError
require 'rubygems'
gem 'activerecord'
require 'active_record'
end

class MockBase < ActiveRecord::Base; end
MockBase.class_eval do
alias_method :save, :valid?
def self.columns() @columns ||= []; end

def self.column(name, sql_type = nil, default = nil, null = true)
columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type, null)
end
end

class MockModel < MockBase
acts_as_notifiable :callback => :after_create, :message => "hello", :recipients => "test@gmail.com"
end

class ActsAsNotifiableTest < Test::Unit::TestCase
def test_option_message_string
assert_equal "hello", MockModel.new.instance_eval{jabber_message}
end
<<--

###Reference

posted by satoko satoko on Thu 6 Mar 2008 at 10:59 with 0 comments

Redmineを使っていて、Issueの追加/変更通知がGTalkで来たらうれしいかもと思って作りました:acts_as_notifiable。

NOTE:

http://agilewebdevelopment.com/plugins/acts_as_notifiable

###Repository
http://svn.s21g.com/public/rails/plugins/acts_as_notifiable/

###Redmineに組み込む
0. XMPP4Rをインストール: http://xmpp4r.rubyforge.org/
shell>>
$sudo gem install xmpp4r
<<--

  1. プラグインをインストール
  2. 設定ファイルを作成: #{RAILS_ROOT}/config/acts_as_notifiable.yml
    rails>>

#{RAILS_ROOT}/config/acts_as_notifiable.yml
to:
recipients: you@gmail.com me@gmail.com
from:
id: your_notify_account@gmail.com
password: pass
connect: talk.google.com
<<--
3. モデルにacts_as_notifiableを追加
rails>>
class Issue
acts_as_notifiable :message => Proc.new {|o| "[#{o.project.name}:#{o.class.name}##{o.id}]#{o.status.name}:#{o.subject}\n #{o.journals.last.notes unless o.journals.blank?}"}
<<--
4. サーバ再起動

NOTE: 通知を受け取るIM側でyour_notify_account@gmail.comを追加するの忘れないように!

posted by satoko satoko on Thu 6 Mar 2008 at 05:29 with 0 comments

In my company, we're using a Redmine. And I thought it would be more useful if I could receive some activities(Like creating/updating Issue) via GTalk. Thus I created acts_as_notifiable.

NOTE:

  • I added this plugin to directory:

http://agilewebdevelopment.com/plugins/acts_as_notifiable

###Repository
http://svn.s21g.com/public/rails/plugins/acts_as_notifiable/

###To work with Redmine
0. Install XMPP4R: http://xmpp4r.rubyforge.org/
shell>>
$sudo gem install xmpp4r
<<--

  1. Install plugin
  2. Create file: #{RAILS_ROOT}/config/acts_as_notifiable.yml
    rails>>

#{RAILS_ROOT}/config/acts_as_notifiable.yml
to:
recipients: you@gmail.com me@gmail.com
from:
id: your_notify_account@gmail.com
password: pass
connect: talk.google.com
<<--
3. Add acts_as_notifiable to the Model class
rails>>
class Issue
acts_as_notifiable :message => Proc.new {|o| "[#{o.project.name}:#{o.class.name}##{o.id}]#{o.status.name}:#{o.subject}\n #{o.journals.last.notes unless o.journals.blank?}"}
<<--
4. restart server

NOTE: Don't forget to add your_notify_account@gmail.com to your IM client!

posted by hibi hibi on Wed 5 Mar 2008 at 16:58 with 0 comments

jRails
プラグインは、RailsアプリケーションのデフォルトJavaScriptライブラリである
prototype.js
+
script.aculo.us
の環境から、
jQuery
を使うようにするためのRailsプラグインです。

プラグインをインストールする方法は、通常のRailsプラグインと同様です。

sh>>
% ./script/plugin install http://ennerchi.googlecode.com/svn/trunk/plugins/jrails
<<sh

インストールすると、jQuery関係のJavaScriptファイル郡が
public/javascripts以下にコピーされます。

あとは、jRailsプラグインがRailsのJavaScriptヘルパーをjQuery対応に
してくれるので、そのままRailsアプリケーションを開発することができます。

当然ながら、prototype.jsやScript.aculo.us固有の関数は
利用できないので、既存のRailsアプリケーションをjQuery対応にする場合は、
そのあたりに注意が必要です。

See Also

posted by genki genki on Sat 1 Mar 2008 at 10:51 with 0 comments

OpenIdAuthentication is depend on gem ruby-openid 1.1.4. In addition, ruby-openid 1.1.4 is broken with 1.0.1 gem :(
So, I applied patch(Ticket#10604) and they works well.

  1. Install gem ruby-openid(2.0.4)
    shell>>
    gem install ruby-openid
    <<--

  2. Install plugin
    shell>>
    $ ./script/plugin install http://svn.rubyonrails.org/rails/plugins/open_id_authentication/
    <<--

  3. Apply patch

  • Get a patch and save as ticket10604.diff

http://dev.rubyonrails.org/ticket/10604

  • Move diff file to plugin root
    shell>>

#{RAILS_ROOT}/vendor/plugins/open_id_authentication/ticket10604.diff
<<--

  • Move to plugin root and do patch command
    shell>>
    $ patch -p1 < ticket10604.diff
    patching file init.rb
    Hunk #1 FAILED at 1.
    1 out of 1 hunk FAILED -- saving rejects to file init.rb.rej
    patching file lib/generators/open_id_authentication_tables/open_id_authentication_tables_generator.rb
    patching file lib/generators/open_id_authentication_tables/templates/migration.rb
    patching file lib/open_id_authentication.rb
    Hunk #5 succeeded at 69 with fuzz 1 (offset -2 lines).
    Hunk #6 succeeded at 88 (offset -2 lines).
    Hunk #7 succeeded at 152 (offset -2 lines).
    patching file lib/open_id_authentication/association.rb
    patching file lib/open_id_authentication/db_store.rb
    patching file lib/open_id_authentication/nonce.rb
    patching file lib/open_id_authentication/setting.rb
    patching file tasks/open_id_authentication_tasks.rake
    patching file test/normalize_test.rb
    patching file test/open_id_authentication_test.rb
    patching file test/status_test.rb
    <<--
  1. Do some work in README
  • Creating tables
    shell>>
    rake open_id_authentication:db:create
    <<--

  • Add some routes
    rails>>

#config/routes.rb
map.open_id_complete 'session', :controller => "sessions", :action => "create", :requirements => { :method => :get }
map.resource :session
<<--

  • Generate SessionsController, and create vews/sessions/new.html.erb
    Tip:NOT to use sample code in agilewebdevelopment.com. Use sample code in README.
    rails>>
    def open_id_authentication
    authenticate_with_open_id do |result, identity_url|
    if result.successful? && @current_user = @account.users.find_by_identity_url(identity_url)
    successful_login
    else
    failed_login(result.message || "Sorry, no user by that identity URL exists (#{identity_url})")
    end
    end
    end
    <<--
  1. Ommit version of ruby-openid
    rails>>

#open_id_authentication/init.rb
begin

gem 'ruby-openid', '=1.1.4'

gem 'ruby-openid'
<<--

posted by hibi hibi on Wed 27 Feb 2008 at 17:12 with 2 comments

OpenIdAuthenticationはruby-openid1.1.4にしか対応していません。ですが、gem1.0.1では1.1.4が正しく動作しないため、プラグインにパッチをあてて使うことにしました。

  1. ruby-openidをインストール(2.0.4)
    shell>>
    gem install ruby-openid
    <<--

  2. pluginのインストール
    shell>>
    $ ./script/plugin install http://svn.rubyonrails.org/rails/plugins/open_id_authentication/
    <<--

  3. パッチをあてる

  • パッチを入手ticket10604.diffとして保存

http://dev.rubyonrails.org/ticket/10604

  • プラグインのところに移動させておく
    shell>>

#{RAILS_ROOT}/vendor/plugins/open_id_authentication/ticket10604.diff
<<--

  • プラグインのルートに移動して、patchを当てる
    shell>>
    $ patch -p1 < ticket10604.diff
    patching file init.rb
    Hunk #1 FAILED at 1.
    1 out of 1 hunk FAILED -- saving rejects to file init.rb.rej
    patching file lib/generators/open_id_authentication_tables/open_id_authentication_tables_generator.rb
    patching file lib/generators/open_id_authentication_tables/templates/migration.rb
    patching file lib/open_id_authentication.rb
    Hunk #5 succeeded at 69 with fuzz 1 (offset -2 lines).
    Hunk #6 succeeded at 88 (offset -2 lines).
    Hunk #7 succeeded at 152 (offset -2 lines).
    patching file lib/open_id_authentication/association.rb
    patching file lib/open_id_authentication/db_store.rb
    patching file lib/open_id_authentication/nonce.rb
    patching file lib/open_id_authentication/setting.rb
    patching file tasks/open_id_authentication_tasks.rake
    patching file test/normalize_test.rb
    patching file test/open_id_authentication_test.rb
    patching file test/status_test.rb
    <<--
  1. READMEにあるExampleの作業
  • テーブル作成
    shell>>
    rake open_id_authentication:db:create
    <<--

  • routesに下記を加える
    rails>>
    map.open_id_complete 'session', :controller => "sessions", :action => "create", :requirements => { :method => :get }
    map.resource :session
    <<--

  • SessionsController、vews/sessions/new.html.erbの作成
    ここでmatakeさんと同じようにはまったのですが、SessionConroller#open_id_authenticationをREADMEにあるresult.successful?のほうを使うとプラグインに手を入れずに使うことができます。(agilewebdevelopment.comのExampleを使うとNG)
    rails>>
    def open_id_authentication
    authenticate_with_open_id do |result, identity_url|
    if result.successful? && @current_user = @account.users.find_by_identity_url(identity_url)
    successful_login
    else
    failed_login(result.message || "Sorry, no user by that identity URL exists (#{identity_url})")
    end
    end
    end
    <<--

  1. ruby-openidのバージョン指定をはずす
    rails>>

#open_id_authentication/init.rb
begin

gem 'ruby-openid', '=1.1.4'

gem 'ruby-openid'
<<--

###参考

posted by satoko satoko on Wed 27 Feb 2008 at 16:41 with 0 comments

At rev. 8929, I have found a good news for OpenID users.

http://svn.rubyonrails.org/rails/plugins/open_id_authentication/CHANGELOG

Tied plugin to ruby-openid 1.1.4 gem until we can make it compatible with 2.x [DHH]

Thanks DHH!

posted by genki genki on Tue 26 Feb 2008 at 16:25 with 0 comments

下記URLから入手できます。
http://svn.s21g.com/public/rails/plugins/tinyurl_helper/

###仕様
URLを渡すとTinyURLに変換してリンクを作ります。

###使い方

  • application_helper.rbでinclude
    rails>>
    module ApplicationHelper
    include TinyurlHelper
    end
    <<--
  • View内で
    rails>>
    <%= link_to_tinyurl "http://www.yahoo.co.jp" %>
    <<--

###作り方
0. 類似するプラグインを探してコーディングの検討をつける

  1. script/generateする
    shell>>
    script/generate plugin tinyurl_helper
    <<--
  2. 上で生成されたlib/tinyurl_helper.rbを編集
    rails>>
    require 'net/http'

module TinyurlHelper
def link_to_tinyurl(url, html_options = nil)
uri = 'http://tinyurl.com/api-create.php?url=' + url
uri = URI.parse(uri)
tiny_url = Net::HTTP.get_response(uri).body
options = {:title => url, :alt => url}
options = html_options.nil? ? options : options.merge(html_options)
link_to tiny_url, tiny_url, options
end
end
<<--
3. テストを書く(アプリテスト、プラグイン単体テスト両方通るように書くと吉)

rails>>

require 'test/unit'
require File.expand_path(File.dirname(FILE) + "/../lib/tinyurl_helper")

class TinyurlHelperTest < Test::Unit::TestCase
include TinyurlHelper

#dummy link_to
def link_to(name, options = {}, html_options = nil)
[name, html_options[:title]]
end

def test_link_to_tinyurl
url = 'http://www.yahoo.co.jp/'
tiny_url, title = link_to_tinyurl(url)
assert_equal 'http://tinyurl.com/910', tiny_url
assert_equal url, title
end

def test_link_to_tinyurl_with_title
url = 'http://www.yahoo.co.jp/'
tiny_url, title = link_to_tinyurl(url, {:title => 'title'})
assert_equal 'http://tinyurl.com/910', tiny_url
assert_equal 'title', title
end
end
<<--

  1. README, MIT-LICENSEを書く
  • READMEは名前と、概要・使い方を書く
  • MIT-LICENSEは名前だけ変更
  1. 公開用リポジトリにコミット
  2. pluginディレクトリに登録する

###Tips

  • プラグインはweb serverを再起動しないとリロードされない
  • helperを使えるようにする方法は2つ
  1. app/helper/application_helper.rbでinclude(上でやった方法)
  2. plugins/tinyurl_helper/init.rbでsendする
    rails>>
    ActionView::Base.send :include, TinyurlHelper
    <<--
posted by satoko satoko on Tue 26 Feb 2008 at 06:20 with 0 comments

今年の目標に、railsのプラグインを作るというのがあるのですが、時間ができたらと言わずに「さっさと/ささっと作れ」という助言をもらったのでささっとやってみました。まずはどいういうものかという初歩的なところから。
###Pluginディレクトリ
ここに多く集められています。
http://agilewebdevelopment.com/plugins

###様々な種類のプラグイン
プラグインはRailsの機能拡張するものなのですが、下記のように分類できます。

  • Helper系
  • Model/Controller系
  • acts_as_なんとかという名前が多い
    ex. acts_as_taggable
  • Generator系
  • その他
  • 上記のmix
    ex. acts_as_authenticated => model/controller拡張, generator
  • rake taskを作るもの
    ex. annotate_models

###作り方how-to

  • Generatorの作り方

http://blog.s21g.com/articles/215

  • pluginの作り方(情報が古い。rails変化早っ)

http://d.hatena.ne.jp/secondlife/20051101/1130850457

  • ロードパスについて

http://rakuto.blogspot.com/2006/06/rails-controllermodelview.html

###問題

  • プラグインのテスト、アプリのテスト両方のテストを通すようにtestを書くのが煩雑。
  • プラグインの更新を適用するのが面倒
    (gemのように簡単に最新にならないので、手動で削除、再インストールが必要)
posted by satoko satoko on Mon 25 Feb 2008 at 13:34 with 0 comments

今回は、Railsアプリケーションに、Undo/Redo機能を追加する
プラグインの紹介です。

What is RUR (Rails Undo Redo)

RUR (Rails-Undo-Redo) is a rails plugin (and soon a gem as well) to make it so easy to implement multi-level undo redo in your Rails application that you better start thinking of better excuses not to implement Undo/Redo (no, seriously, it is going to be a lot easier).

これはなかなか面白いプラグインですね。後で使ってみよう。

posted by genki genki on Tue 19 Feb 2008 at 01:27 with 0 comments

最近はJavaScriptを使っておれおれスクリプト言語の処理系を
実装するのが流行っていますね。
ちょっとその実用性について考えてみたのですが、
限定されたデータに対してだけアクセス可能な、
サンドボックス的なスクリプト言語というのは、Webサービスの
プラグイン記述言語(サイト内DSLと呼んでみる。
サイト内とDSが被ってる気がするけど気にしない)
としての需要があるきがします。

例えば、次のような特徴を備える言語が考えられます。

  • Cookie情報にはアクセスできない
  • 指定したDOM Elementの子要素にしかアクセスでいない
  • 指定した種類のElementしか作成できない
  • XmlHttpRequestオブジェクトを作成できない
  • 指定した種類のイベントしかObserveできない

どうでしょう。Facebookのようにサードパーティが
アプリケーションを追加できるようなプラットフォームを
作る場合に、JavaScript自体ではなく、JSで実装された、
よりSecureなまったく別の言語を使うことで
より安全性を高めることができるのではないでしょうか。

posted by genki genki on Wed 13 Feb 2008 at 18:37 with 0 comments

annotate_models
は、テーブルの情報をModelとFixtureのファイルに
コメントとして書き込んでくれる非常に便利なプラグインです。

永く愛用しているプラグインの一つなのですが、
しばらくメンテナンスされていないようなので、
欲しいと思っていたindexに関する情報も出力するようにしてみました。

http://svn.s21g.com/public/rails/plugins/annotate_models_with_index/

こんな感じに、インデックス情報をカラムごとに付加します。

rails>>

== Schema Information

Schema version: 48

Table name: users

id :integer(11) not null, primary key

(* snip *)

mobile_email :string(255) index_users_on_mobile_email(unique)

<<--

posted by genki genki on Thu 24 Jan 2008 at 01:10 with 0 comments

以前紹介した
BenchmarkForRails
は、Railsアプリケーションの詳細なベンチマークを
行うことが出来る便利なプラグインですが、
rake test:unitsの実行でエラーが発生する問題が
起こっていました。

調べてみたところ、init.rbファイルにrequire文が
足りていないのが原因のようだったので、対処法を紹介します。

vendor/plugins/benchmarkforrails/init.rb

rails>>
require 'dispatcher'
require 'benchmark_for_rails'

The special :request benchmark. This tries to encompass everything that runs

to handle a request.

BenchmarkForRails.watch(:request, ::Dispatcher, :dispatch)
<<--

上記の2行目を加えることで、エラーが出なくなります。

posted by genki genki on Sat 22 Dec 2007 at 22:21 with 0 comments

一時動かなくなっていた
restful_open_id_authenticationプラグイン
ですが、
ひとまず手元の環境で動く状態になったので、こちらに置いておきます。

http://svn.s21g.com/public/rails/plugins/restful_open_id_authentication_redux/

ruby-openid-2.0.1
のexamplesのコードが非常に参考になりました。

プラグイン中のmigrationジェネレータは、何も無い状態から
DBを作るためのマイグレーションになっています。

すでにrestful_open_id_authenticationプラグインを
使っている状態からアップグレードする場合は、下記
[2]に掲載したmigrationコードをご利用ください。

Enter at your own risk!

See Also

  1. restful_open_id_authenticationプラグインの更新に着手
  2. rescful_open_id_authenticationプラグインの更新#2
posted by genki genki on Fri 21 Dec 2007 at 08:09 with 0 comments

restful_open_id_authenticationプラグイン
でOpenIDストアに使用していたDBを
ruby-openid 2.0に移行させるためのマイグレーション。
ruby-openid 2.0のexamplesから抜粋。

rails>>

Use this migration to upgrade the old 1.1 ActiveRecord store schema

to the new 2.0 schema.

class UpgradeOpenIdStore < ActiveRecord::Migration
def self.up
drop_table "open_id_settings"
drop_table "open_id_nonces"
create_table "open_id_nonces", :force => true do |t|
t.column :server_url, :string, :null => false
t.column :timestamp, :integer, :null => false
t.column :salt, :string, :null => false
end
end

def self.down
drop_table "open_id_nonces"
create_table "open_id_nonces", :force => true do |t|
t.column "nonce", :string
t.column "created", :integer
end

create_table "open_id_settings", :force => true do |t|
  t.column "setting", :string
  t.column "value", :binary
end

end
end
<<--

ちなみにオリジナルのプラグインが生成したマイグレーションコードはこちら。

rails>>
create_table :open_id_associations, :force => true do |t|
t.column :server_url, :binary
t.column :handle, :string
t.column :secret, :binary
t.column :issued, :integer
t.column :lifetime, :integer
t.column :assoc_type, :string
end

create_table :open_id_nonces, :force => true do |t|
  t.column :nonce,        :string
  t.column :created,      :integer
end

create_table :open_id_settings, :force => true do |t|
  t.column :setting,      :string
  t.column :value,        :binary
end

<<--

open_id_settingsは不要になって、open_id_nounces
内容が変わります。

posted by genki genki on Fri 21 Dec 2007 at 06:34 with 0 comments

昨日RubyGemsを1.0.0にアップデートしたところ、
require_gemが使えなくなってしまったため、
内部でrequire_gemを使っているGemが使えなくなりました。

かなり前から移行措置が取られていたため、
使えなくなったGemはほとんど無かったのですが、
一個だけ、ruby-openidの1.x.x系列が使えなくなっていました。

その結果、愛用していた
restful_open_id_authenticationプラグインが
動かなくなってしまいました。
結構いろんなプロダクトで使っていたので影響大です。

ruby-openidの2.x.x系列は、require_gemを使わないようなコードに
なっているのですが、インターフェイスが大分変わっているため、
すんなりとアップグレードが出来ない感じですね。

しかし、アップグレードしないわけにもいかないので、
restful_open_id_authenticationプラグインの
ruby-openid 2.x.x系対応に着手します。

すでに同じ問題に取り組んでいる方がいらっしゃいましたら、
喜んでご協力いたしますのでご連絡いただけるとありがたいです。

連絡先

posted by genki genki on Fri 21 Dec 2007 at 06:23 with 0 comments

Rails Plugin Watcherとしては、
とても興味深い内容の記事がPostされていました。

10 Ruby On Rails Plugins You Should Be Using

One of Ruby on Rails strengths is how easy it is to extend with Ruby Gems and plugins, becuase you don’t have to code everything yourself you can save a lot of time. One problem facing Rails codes is knowing what plugins are out there and how to use them. The following is a list of 12 plugins that should make your coding life much easier and save you a fair bit of time.

タイトルでは10と言ってるけど、実際には11個紹介されてるようです。
本文には12って書いてるからもっと増えるのかも?

簡単に使えて時間節約効果が高いもの、
という観点でチョイスしてるみたいですね。
acts_as_taggable_on_steroids はぜひ使うべきですね。
Tag系のプラグインの中では最高峰だと思います。

それ以外は、結構趣味の問題かなという気もしますね。

posted by genki genki on Thu 13 Dec 2007 at 01:04 with 0 comments

Fuシリーズ
に新しい仲間が登場。

Running Long Background Tasks In Ruby On Rails Made Dead Simple

BackgroundFu is simple. It has a nice interface resembling ActiveRecord (see examples below). It is small (51 lines of code, 73 lines of specs) and easily understandable. It’s perfect for doing those shiny ajax progress bars showing how busy your box is. It just works.

名前からして
BackgrounDRB
に近いのですが、機能も似ています。でももっとシンプル(Dead Simple)らしい。

プラグインリポジトリはこちらです。

posted by genki genki on Tue 11 Dec 2007 at 00:15 with 0 comments
最近話題の [ActiveScaffold](http://activescaffold.com/) の開発メンバーでもあるLance Ivy氏のレポート。 [**How Rails' Benchmarks Lie**](http://codelevy.com/articles/2007/11/28/how-rails-benchmarks-lie) >I’ve been on a benchmarking blogging spree lately. Creating BenchmarkForRails (B4R) with its non-invasive benchmarking technique has made it very easy to play around with timing of key Rails methods and develop a better picture of the true costs. The results have been amazing. Railsのベンチマークでは測定しきれない部分の ベンチマークを可能にする [BenchmarkForRails](http://code.google.com/p/benchmarkforrails/) というプラグインを作ったとの事。 具体的には、こんな感じで違いが出るようです(以下に抜粋) **Rails** Completed in 0.85246 (1 reqs/sec) Rendering: 0.48872 (57%) DB: 0.02561 (3%) **BenchmarkForRails** - [0.9532] GET /plans ---------------------------- 0.8528 processing action 0.5015 rendering 0.2533 activerecord find 0.0461 development mode 0.0073 before filters 0.0046 session management 0.0000 after filters ------------------------------ BenchmarkForRails - かなり細かいところまで計測できていますね。ちょっと面白いです。
posted by genki genki on Mon 10 Dec 2007 at 00:36 with 0 comments

今では、このプラグインのお世話になるような状況にはならなくなった
のですが、多人数でRailsアプリケーションを開発している場合には
便利なプラグインかもしれません。

Renumber clashing Rails migrations in one easy step

If you work in a team on a Rails project, chances are that you and your team mates occasionally create identically-numbered migrations. Renumbering a migration that you're working on is a pain, unless you're using this handy 'renumber_migrations' plugin.

このプラグインを使うと、マイグレーション番号が衝突した場合に、
Subversionのリポジトリを確認して、あるべき順序に番号を
振りなおしてくれます。

Subversionを使って管理していないプロジェクトでは使えないですが、
ちょっとソースを書き換えれば他のSCMを使ってる場合でも対応できる
ようにするのは難しくなさそうです。

使い方

まずは、以下のコマンドでプラグインをインストールします。

pre>>
% ./script/plugin install http://rails.sanityinc.com/plugins/renumber_migrations
<<--

あとは、Rakeタスクを実行するだけです。

pre>>
% rake db:migrate:renumber
<<--

posted by genki genki on Mon 10 Dec 2007 at 00:21 with 0 comments