Permalink
Browse files

Converted to a gem.

  • Loading branch information...
1 parent 1b72c5e commit 44bd9a3ba23c369c130bc96f3e4f0aff14a4a098 @danielmorrison danielmorrison committed Oct 26, 2010
Showing with 132 additions and 53 deletions.
  1. +2 −0 .bundle/config
  2. +2 −0 Gemfile
  3. +49 −0 Gemfile.lock
  4. +3 −1 Rakefile
  5. +0 −5 init.rb
  6. +6 −41 lib/with_action.rb
  7. +3 −0 lib/with_action/version.rb
  8. +40 −0 lib/with_action/with_action.rb
  9. +0 −4 tasks/with_action_tasks.rake
  10. +2 −2 test/with_action_test.rb
  11. +25 −0 with_action.gemspec
View
@@ -0,0 +1,2 @@
+---
+BUNDLE_DISABLE_SHARED_GEMS: "1"
View
@@ -0,0 +1,2 @@
+source :gemcutter
+gemspec
View
@@ -0,0 +1,49 @@
+PATH
+ remote: .
+ specs:
+ with_action (1.0.0)
+ actionpack
+ activesupport
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ abstract (1.0.0)
+ actionpack (3.0.1)
+ activemodel (= 3.0.1)
+ activesupport (= 3.0.1)
+ builder (~> 2.1.2)
+ erubis (~> 2.6.6)
+ i18n (~> 0.4.1)
+ rack (~> 1.2.1)
+ rack-mount (~> 0.6.12)
+ rack-test (~> 0.5.4)
+ tzinfo (~> 0.3.23)
+ activemodel (3.0.1)
+ activesupport (= 3.0.1)
+ builder (~> 2.1.2)
+ i18n (~> 0.4.1)
+ activesupport (3.0.1)
+ builder (2.1.2)
+ erubis (2.6.6)
+ abstract (>= 1.0.0)
+ i18n (0.4.1)
+ mocha (0.9.9)
+ rake
+ rack (1.2.1)
+ rack-mount (0.6.13)
+ rack (>= 1.0.0)
+ rack-test (0.5.6)
+ rack (>= 1.0)
+ rake (0.8.7)
+ tzinfo (0.3.23)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ actionpack
+ activesupport
+ bundler (>= 1.0.0)
+ mocha
+ with_action!
View
@@ -1,4 +1,6 @@
-require 'rake'
+require 'bundler'
+Bundler::GemHelper.install_tasks
+
require 'rake/testtask'
require 'rake/rdoctask'
View
@@ -1,5 +0,0 @@
-require 'with_action'
-
-ActionController::Base.class_eval do
- include CollectiveIdea::WithAction
-end
View
@@ -1,42 +1,7 @@
-module CollectiveIdea
- module WithAction
- def with_action(*actions)
- responder = ActionResponder.new(self)
- yield responder if block_given?
- actions.each {|a| responder.send(a) }
- responder.respond
- end
-
- class ActionResponder
- def initialize(controller)
- @controller = controller
- @order, @responses = [], {}
- end
-
- def respond
- action = @order.detect do |a|
- !@controller.params[a].blank? || !@controller.params["#{a}.x"].blank?
- end
- action ||= @order.include?(:any) ? :any : @order.first
- @responses[action].call if @responses[action]
- end
-
- def any(&block)
- method_missing(:any) do
- # reset
- @order, @responses = [], {}
- block.call.tap do
- respond
- end
- end
- end
-
- def method_missing(action, &block)
- @order << action
- block ||= lambda { @controller.send(action) }
- @responses[action] = block
- end
- end
-
- end
+require 'active_support'
+require 'action_controller'
+require 'with_action/with_action'
+
+ActionController::Base.class_eval do
+ include WithAction
end
@@ -0,0 +1,3 @@
+module WithAction
+ VERSION = "1.0.0"
+end
@@ -0,0 +1,40 @@
+module WithAction
+ def with_action(*actions)
+ responder = ActionResponder.new(self)
+ yield responder if block_given?
+ actions.each {|a| responder.send(a) }
+ responder.respond
+ end
+
+ class ActionResponder
+ def initialize(controller)
+ @controller = controller
+ @order, @responses = [], {}
+ end
+
+ def respond
+ action = @order.detect do |a|
+ !@controller.params[a].blank? || !@controller.params["#{a}.x"].blank?
+ end
+ action ||= @order.include?(:any) ? :any : @order.first
+ @responses[action].call if @responses[action]
+ end
+
+ def any(&block)
+ method_missing(:any) do
+ # reset
+ @order, @responses = [], {}
+ block.call.tap do
+ respond
+ end
+ end
+ end
+
+ def method_missing(action, &block)
+ @order << action
+ block ||= lambda { @controller.send(action) }
+ @responses[action] = block
+ end
+ end
+
+end
@@ -1,4 +0,0 @@
-# desc "Explaining what the task does"
-# task :with_action do
-# # Task goes here
-# end
View
@@ -5,11 +5,11 @@
require File.dirname(__FILE__) + '/../lib/with_action'
class WithActionTest < Test::Unit::TestCase
- include CollectiveIdea::WithAction
+ include WithAction
def setup
@params = {}
- @responder = CollectiveIdea::WithAction::ActionResponder.new(self)
+ @responder = WithAction::ActionResponder.new(self)
end
def params
View
@@ -0,0 +1,25 @@
+# -*- encoding: utf-8 -*-
+require File.expand_path("../lib/with_action/version", __FILE__)
+
+Gem::Specification.new do |s|
+ s.name = "with_action"
+ s.version = WithAction::VERSION
+ s.platform = Gem::Platform::RUBY
+ s.authors = ["Brandon Keepers", "Daniel Morrison"]
+ s.email = ['info@collectiveidea.com']
+ s.homepage = "http://rubygems.org/gems/with_action"
+ s.summary = "A respond_to style helper for Rails controllers for doing different actions based on which request parameters are passed."
+ s.description = 'A respond_to style helper for doing different actions based on which request parameters are passed. Specifically, it is helpful if you want to use multiple form buttons on a page, such as "Save", "Save and Continue Editing", and "Cancel". with_action executes different blocks based on what the presence of request parameters.'
+
+ s.required_rubygems_version = ">= 1.3.6"
+ s.rubyforge_project = "with_action"
+
+ s.add_dependency "actionpack"
+
+ s.add_development_dependency "bundler", ">= 1.0.0"
+ s.add_development_dependency "mocha"
+
+ s.files = `git ls-files`.split("\n")
+ s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
+ s.require_path = 'lib'
+end

1 comment on commit 44bd9a3

Please tell how to install with_action. Thanks

Please sign in to comment.