public
Description: Merb More: The Full Stack. Take what you need; leave what you don't.
Homepage: http://www.merbivore.com
Clone URL: git://github.com/wycats/merb-more.git
ActionArgs can now eval to false

If an action argument eval'd to false (i.e. either def action(foo = nil) 
or def action(foo = false))
then action args would throw BadRequest if you did not supply an argument 
for foo in those examples.
Lighthouse ticket #97.

Signed-off-by: Michael S. Klishin <michael@novemberain.com>
adelcambre (author)
Mon May 12 12:36:51 -0700 2008
michaelklishin (committer)
Wed May 14 08:01:52 -0700 2008
commit  80e5040521fdd3dfe209f459373521d3c57550a2
tree    3147d71e2ed88a61bbc18937132f746d22310762
parent  0c825f720f8e153432aae88acc4205702effacfe
...
1
2
3
4
 
5
6
7
...
25
26
27
28
 
 
29
30
31
 
32
33
34
...
1
2
3
 
4
5
6
7
...
25
26
27
 
28
29
30
31
 
32
33
34
35
0
@@ -1,7 +1,7 @@
0
 class Merb::AbstractController
0
   
0
   class << self
0
- attr_accessor :action_argument_list
0
+ attr_accessor :action_argument_list
0
     alias_method :old_inherited, :inherited
0
 
0
     # Stores the argument lists for all methods for this class.
0
@@ -25,10 +25,11 @@ class Merb::AbstractController
0
   # ==== Raises
0
   # BadRequest:: The params hash doesn't have a required parameter.
0
   def _call_action(action)
0
- args = self.class.action_argument_list[action].map do |arg, default|
0
+ arguments, defaults = self.class.action_argument_list[action]
0
+ args = arguments.map do |arg, default|
0
       arg = arg
0
       p = params.key?(arg.to_sym)
0
- raise BadRequest unless p || default
0
+ raise BadRequest unless p || (defaults && defaults.include?(arg))
0
       p ? params[arg.to_sym] : default
0
     end
0
     __send__(action, *args)
...
35
36
37
38
 
39
40
41
 
42
43
44
45
46
47
48
49
50
51
 
52
53
54
...
35
36
37
 
38
39
40
 
41
42
43
44
45
 
46
47
48
49
 
50
51
52
53
0
@@ -35,20 +35,19 @@ class ParseTreeArray < Array
0
       # method defined with def keyword
0
       args = arg_node.arg_nodes
0
       default_node = arg_node.deep_array_node(:block)
0
- return args unless default_node
0
+ return [args, []] unless default_node
0
     else
0
       # assuming method defined with Module#define_method
0
- return []
0
+ return [[],[]]
0
     end
0
     
0
     # if it was defined with def, and we found the default_node,
0
     # that should bring us back to regularly scheduled programming..
0
-
0
     lasgns = default_node[1..-1]
0
     lasgns.each do |asgn|
0
       args.assoc(asgn[1]) << eval(RubyToRuby.new.process(asgn[2]))
0
     end
0
- args
0
+ [args, (default_node[1..-1].map { |asgn| asgn[1] })]
0
   end
0
 
0
 end
...
30
31
32
 
 
 
 
33
34
...
30
31
32
33
34
35
36
37
38
0
@@ -30,4 +30,8 @@ describe Merb::AbstractController do
0
     dispatch_to(ActionArgs, :funky_inherited_method, :foo => "bar", :bar => "baz").body.should == "bar baz"
0
   end
0
   
0
+ it "should be able to handle nil defaults" do
0
+ dispatch_to(ActionArgs, :with_default_nil, :foo => "bar").body.should == "bar "
0
+ end
0
+
0
 end
0
\ No newline at end of file
...
32
33
34
 
 
 
 
35
36
...
32
33
34
35
36
37
38
39
40
0
@@ -32,4 +32,8 @@ class ActionArgs < Merb::Controller
0
     "mos def"
0
   end
0
   
0
+ def with_default_nil(foo, bar = nil)
0
+ "#{foo} #{bar}"
0
+ end
0
+
0
 end
0
\ No newline at end of file

Comments

    No one has commented yet.