From 67cd00cfbff52d24ab8d0aaacf465add28daa116 Mon Sep 17 00:00:00 2001 From: Brian Kidd Date: Fri, 8 Oct 2010 12:35:30 -0400 Subject: [PATCH] -refactored _execute() for much better readability :-) -added dependency for for ruby-debug-completion -turned on auto-eval for ruby-debug -added the ability to run debugger on the last line of a method: http://dancingpenguinsoflight.com/2009/09/an-improved-ruby-debugger-invocation/ --- Rakefile | 25 +++++++++++++------------ lib/aasm/state_transition.rb | 17 +++++------------ spec/spec_helper.rb | 3 +++ test/test_helper.rb | 4 ++-- 4 files changed, 23 insertions(+), 26 deletions(-) diff --git a/Rakefile b/Rakefile index e6f8d17..d382f70 100644 --- a/Rakefile +++ b/Rakefile @@ -4,20 +4,21 @@ require 'rake' begin require 'jeweler' Jeweler::Tasks.new do |gem| - gem.name = "aasm" + gem.name = 'aasm' gem.summary = %Q{State machine mixin for Ruby objects} gem.description = %Q{AASM is a continuation of the acts as state machine rails plugin, built for plain Ruby objects.} - gem.homepage = "http://rubyist.github.com/aasm/" - gem.authors = ["Scott Barron", "Scott Petersen", "Travis Tilley"] - gem.email = "scott@elitists.net, ttilley@gmail.com" - gem.add_development_dependency "rspec" - gem.add_development_dependency "shoulda" + gem.homepage = 'http://rubyist.github.com/aasm/' + gem.authors = ['Scott Barron', 'Scott Petersen', 'Travis Tilley'] + gem.email = 'scott@elitists.net, ttilley@gmail.com' + gem.add_development_dependency 'ruby-debug-completion' + gem.add_development_dependency 'rspec' + gem.add_development_dependency 'shoulda' gem.add_development_dependency 'sdoc' # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings end Jeweler::GemcutterTasks.new rescue LoadError - puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler" + puts 'Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler' end require 'spec/rake/spectask' @@ -38,7 +39,7 @@ begin end rescue LoadError task :rcov do - abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov" + abort 'RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov' end end @@ -66,7 +67,7 @@ begin end rescue LoadError task :reek do - abort "Reek is not available. In order to run reek, you must: sudo gem install reek" + abort 'Reek is not available. In order to run reek, you must: sudo gem install reek' end end @@ -78,7 +79,7 @@ begin end rescue LoadError task :roodi do - abort "Roodi is not available. In order to run roodi, you must: sudo gem install roodi" + abort 'Roodi is not available. In order to run roodi, you must: sudo gem install roodi' end end @@ -91,7 +92,7 @@ begin if File.exist?('VERSION') version = File.read('VERSION') else - version = "" + version = '' end rdoc.rdoc_dir = 'rdoc' @@ -103,6 +104,6 @@ begin rdoc.template = 'direct' end rescue LoadError - puts "aasm makes use of the sdoc gem. Install it with: sudo gem install sdoc" + puts 'aasm makes use of the sdoc gem. Install it with: sudo gem install sdoc' end diff --git a/lib/aasm/state_transition.rb b/lib/aasm/state_transition.rb index 991347b..4b57e72 100644 --- a/lib/aasm/state_transition.rb +++ b/lib/aasm/state_transition.rb @@ -35,18 +35,11 @@ class AASM::SupportingClasses::StateTransition private def _execute(obj, on_transition, *args) - if on_transition.is_a?(Proc) - if on_transition.arity != 0 - on_transition.call(obj, *args) - else - on_transition.call - end - elsif on_transition.is_a?(Symbol) || on_transition.is_a?(String) - if obj.send(:method, on_transition.to_sym).arity != 0 - obj.send(on_transition, *args) - else - obj.send(on_transition) - end + case on_transition + when Proc + on_transition.arity == 0 ? on_transition.call : on_transition.call(obj, *args) + when Symbol, String + obj.send(:method, on_transition.to_sym).arity == 0 ? obj.send(on_transition) : obj.send(on_transition, *args) end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 9b9df8e..53fbc18 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -6,6 +6,9 @@ require 'aasm' require 'spec' require 'spec/autorun' +require 'ruby-debug'; Debugger.settings[:autoeval] = true; debugger; rubys_debugger = 'annoying' +require 'ruby-debug/completion' + Spec::Runner.configure do |config| end diff --git a/test/test_helper.rb b/test/test_helper.rb index 5dc5fe1..6910119 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -23,8 +23,8 @@ class Test::Unit::TestCase end begin - require 'ruby-debug' - Debugger.start + require 'ruby-debug'; Debugger.settings[:autoeval] = true; debugger; rubys_debugger = 'annoying' + require 'ruby-debug/completion' rescue LoadError end