<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SNS開発者の本気帳 &#187; StateMachine</title>
	<atom:link href="http://www.synapz.jp/ogsy/tag/statemachine/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.synapz.jp/ogsy</link>
	<description></description>
	<lastBuildDate>Thu, 04 Mar 2010 14:59:47 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>[Rails 2.3.2] acts_as_state_machine から AASMへ変更</title>
		<link>http://www.synapz.jp/ogsy/2009/10/rails-aasm-state-machine/</link>
		<comments>http://www.synapz.jp/ogsy/2009/10/rails-aasm-state-machine/#comments</comments>
		<pubDate>Fri, 16 Oct 2009 07:30:32 +0000</pubDate>
		<dc:creator>ogsy</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[プログラミング]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[StateMachine]]></category>

		<guid isPermaLink="false">http://192.168.1.2/wpmu/ogsy/2009/10/16/rails-2-3-2-acts_as_state_machine-%e3%81%8b%e3%82%89-aasm%e3%81%b8%e5%a4%89%e6%9b%b4/</guid>
		<description><![CDATA[
こんちには、おがしょーです。
今回は自分の備忘録のためのエントリです。


ユーザー認証などでRestfulAuthenticationを使う場合、ステートマシンとして2種類のモジュールが使える。
1. acts_as_state_machine
2. AASM （rubyist-aasm）


※今回の流れ。
ググって出てくる参考サイトではほとんどacts_as_state_machineを使用していたので、迷い無くこれをチョイス。
↓
プラグインはGitHubからのインストールでまとめたいので探してみる、が見つからない。
↓
実は長い間アップデートされてない。
↓
後継でAASMなるものを発見。
↓
rubyist-aasmをインストールした後、RestfulAuthenticationをAASMに切り替える。
↓
find_in_stateがエラーになる。
↓
そういえばacts_as_state_machineに複数状態を指定できるパッチ当ててたっけ。。


引用元： kaeruspoon様
module ScottBarron
module Acts
module StateMachine
module ClassMethods
protected
def with_state_scope(target_states)
target_states = [target_states] unless target_states.is_a?(Array)
raise InvalidState unless target_states.all? {&#124;s&#124; states.include?(s)}
cond = []
cond_param = []
target_states.each do &#124;st&#124;
cond &#60;&#60; &#34;#{table_name}.#{state_column} = ?&#34;
cond_param &#60; {:conditions =&#62; [cond.join(" OR "), cond_param].flatten} do
yield if block_given?
end
end
end
end
end
end

↓
AASM用に変更してみる・・・が、動かない。AASMがgemだからか？？
↓
メソッド名を変えてリトライ。
[ RAILS/config/initializers/patch_aasm.rb ]
module AASM
module Persistence
module ActiveRecordPersistence
module ClassMethods
def find_in_states(number, state, *args)
with_states_scope state do
find(number, *args)
end
end
def count_in_states(state, *args)
with_states_scope state do
count(*args)
end
end
def [...]]]></description>
			<content:encoded><![CDATA[<p>
こんちには、おがしょーです。<br />
今回は自分の備忘録のためのエントリです。<br />
<br />
<br />
ユーザー認証などで<a href="http://github.com/technoweenie/restful-authentication" target="_BLANK">RestfulAuthentication</a>を使う場合、ステートマシンとして2種類のモジュールが使える。<br />
1. <a href="http://www.google.co.jp/search?q=acts_as_state_machine" target="_BLANK">acts_as_state_machine</a><br />
2. <a href="http://github.com/rubyist/aasm" target="_BLANK">AASM （rubyist-aasm）</a><br />
<br />
<br />
<b>※今回の流れ。</b><br />
ググって出てくる参考サイトではほとんどacts_as_state_machineを使用していたので、迷い無くこれをチョイス。<br />
↓<br />
プラグインはGitHubからのインストールでまとめたいので探してみる、が見つからない。<br />
↓<br />
実は長い間アップデートされてない。<br />
↓<br />
後継でAASMなるものを発見。<br />
↓<br />
rubyist-aasmをインストールした後、RestfulAuthenticationをAASMに切り替える。<br />
↓<br />
find_in_stateがエラーになる。<br />
↓<br />
そういえばacts_as_state_machineに複数状態を指定できるパッチ当ててたっけ。。<br />
<br />
<br />
引用元： <a href="http://www.kaeruspoon.net/articles/507" target="_BLANK">kaeruspoon</a>様<br />
<pre><code>module ScottBarron
module Acts
module StateMachine
module ClassMethods
protected
def with_state_scope(target_states)
target_states = [target_states] unless target_states.is_a?(Array)
raise InvalidState unless target_states.all? {|s| states.include?(s)}
cond = []
cond_param = []
target_states.each do |st|
cond &lt;&lt; &quot;#{table_name}.#{state_column} = ?&quot;
cond_param &lt; {:conditions =&gt; [cond.join(" OR "), cond_param].flatten} do
yield if block_given?
end
end
end
end
end
end</code>
</pre>
↓<br />
AASM用に変更してみる・・・が、動かない。AASMがgemだからか？？<br />
↓<br />
メソッド名を変えてリトライ。<br />
[ RAILS/config/initializers/patch_aasm.rb ]<br />
<pre><code>module AASM
module Persistence
module ActiveRecordPersistence
module ClassMethods
def find_in_states(number, state, *args)
with_states_scope state do
find(number, *args)
end
end
def count_in_states(state, *args)
with_states_scope state do
count(*args)
end
end
def calculate_in_states(state, *args)
with_states_scope state do
calculate(*args)
end
end
protected
def with_states_scope(target_states)
target_states = [target_states] unless target_states.is_a?(Array)
raise InvalidState unless target_states.all? {|s| aasm_states.include?(s)}
cond = []
cond_param = []
target_states.each do |st|
cond &lt;&lt; &quot;?&quot;
cond_param &lt; {:conditions =&gt; ["#{table_name}.#{aasm_column} IN (#{cond.join(', ')})", cond_param].flatten} do
yield if block_given?
end
end
end
end
end
end</code></pre>
↓<br />
できた (n&#8217;∀&#8217;)η<br />
<br />
<br />
まだgemとかよくわかってないのGitHubでForkして修正して・・・とかやりたかったけど無理でした。<br />
先は長いなぁ〜。<br />
<br />
<br />
おまけ。<br />
ステートマシンについてはこちらのページが詳しいです。<br />
<a href="http://www.ibm.com/developerworks/jp/java/library/j-cb03137/index.html" target="_BLANK">境界を越える: Rails での拡張</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.synapz.jp/ogsy/2009/10/rails-aasm-state-machine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
