Skip to content

Commit

Permalink
Clean up ActionArgs module, don't override inherited
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Delcambre committed Apr 3, 2010
1 parent 06b96c3 commit cc4770d
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions lib/rails_action_args/abstract_controller.rb
Expand Up @@ -7,23 +7,18 @@ module ActionArgs
def self.included(base)
base.class_eval do
class << self
attr_accessor :action_argument_list
alias_method :old_inherited, :inherited
def action_arguments(action)
@action_arguments ||= {}
return @action_arguments[action] if @action_arguments[action]

# Stores the argument lists for all methods for this class.
#
# ==== Parameters
# klass<Class>::
# The controller that is being inherited from AbstractController.
def inherited(klass)
klass.action_argument_list = Hash.new do |hash,action|
args = klass.instance_method(action).get_args
arguments = args[0]
defaults = []
arguments.each {|a| defaults << a[0] if a.size == 2} if arguments
hash[action] = [arguments || [], defaults]
end
old_inherited(klass)
arguments = instance_method(action).get_args.first || []

defaults = arguments.map do |arg|
if arg.size == 2
arg.first
end
end.compact
@action_arguments[action] = [arguments, defaults]
end
end
end
Expand All @@ -37,7 +32,7 @@ def inherited(klass)
# ==== Raises
# BadRequest:: The params hash doesn't have a required parameter.
def send_action(action)
arguments, defaults = self.class.action_argument_list[action.to_s]
arguments, defaults = self.class.action_arguments(action.to_s)

args = arguments.map do |arg, default|
p = params.key?(arg.to_sym)
Expand Down

0 comments on commit cc4770d

Please sign in to comment.