Methods
Public Class methods
[ show source ]
# File lib/action_requires.rb, line 3
3: def self.action_requires(options)
4: unless options.is_a? Hash
5: options = {:names => [options].flatten}
6: end
7: options = {:type => :and}.merge(options)
8: options[:names] = [options[:names]].flatten
9: big_meth = "action_requires_wrapper_" << options[:names].join("_#{options[:type].to_s}_")
10: options[:names].each do |meth|
11: unless method_defined?(meth)
12: define_method("action_requires_#{meth}") do
13: return !params[meth.to_sym].blank?
14: end
15: end
16: end
17: unless method_defined?(big_meth)
18: delim = case options[:type]
19: when :and
20: " && "
21: when :or
22: " || "
23: end
24: eval %{
25: def #{big_meth}
26: unless #{options[:names].collect {|meth| "action_requires_#{meth}"}.join(delim)}
27: send_to_unknown
28: # return false
29: end
30: end
31: }
32: end
33: options.delete(:names)
34: options.delete(:type)
35: before_filter big_meth.to_sym, options
36: end
Public Instance methods
[ show source ]
# File lib/action_requires.rb, line 38
38: def action_requires_id
39: param = params[:id]
40: return !(param.blank? || param == "null" || (param.match(/^\D+/) unless param.is_a? Numeric))
41: end
[ show source ]
# File lib/action_requires.rb, line 43
43: def action_requires_xhr
44: send_to_unknown if !request.xhr?
45: end
[ show source ]
# File lib/action_requires.rb, line 47
47: def send_to_unknown
48: @orig_params = params
49: render :text => "!404!", :status => "404" unless performed?
50: end