-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1b72c5e
commit 44bd9a3
Showing
11 changed files
with
132 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,2 @@ | |||
--- | |||
BUNDLE_DISABLE_SHARED_GEMS: "1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,2 @@ | |||
source :gemcutter | |||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,42 +1,7 @@ | |||
module CollectiveIdea | require 'active_support' | ||
module WithAction | require 'action_controller' | ||
def with_action(*actions) | require 'with_action/with_action' | ||
responder = ActionResponder.new(self) |
|
||
yield responder if block_given? | ActionController::Base.class_eval do | ||
actions.each {|a| responder.send(a) } | include WithAction | ||
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 | |||
end | end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,3 @@ | |||
module WithAction | |||
VERSION = "1.0.0" | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 |
44bd9a3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please tell how to install with_action. Thanks