action_requires 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ # require 'action_requires'
data/install.rb ADDED
@@ -0,0 +1 @@
1
+ # Install hook code here
@@ -0,0 +1,52 @@
1
+ class ActionController::Base
2
+
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
37
+
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
42
+
43
+ def action_requires_xhr
44
+ send_to_unknown if !request.xhr?
45
+ end
46
+
47
+ def send_to_unknown
48
+ @orig_params = params
49
+ render :text => "!404!", :status => "404" unless performed?
50
+ end
51
+
52
+ end
File without changes
@@ -0,0 +1,5 @@
1
+ --- !ruby/object:RubyForgeConfig
2
+ gem_name: action_requires
3
+ package: action_requires
4
+ project: magrathea
5
+ version: 1.0.0
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.2
3
+ specification_version: 1
4
+ name: action_requires
5
+ version: !ruby/object:Gem::Version
6
+ version: 1.0.0
7
+ date: 2007-09-11 00:00:00 -04:00
8
+ summary: action_requires
9
+ require_paths:
10
+ - lib
11
+ - lib
12
+ - lib
13
+ - lib/tasks
14
+ email:
15
+ homepage:
16
+ rubyforge_project: magrathea
17
+ description: "action_requires was developed by: markbates"
18
+ autorequire:
19
+ - action_requires
20
+ - action_requires
21
+ default_executable:
22
+ bindir: bin
23
+ has_rdoc: false
24
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
25
+ requirements:
26
+ - - ">"
27
+ - !ruby/object:Gem::Version
28
+ version: 0.0.0
29
+ version:
30
+ platform: ruby
31
+ signing_key:
32
+ cert_chain:
33
+ post_install_message:
34
+ authors:
35
+ - markbates
36
+ files:
37
+ - init.rb
38
+ - install.rb
39
+ - lib/action_requires.rb
40
+ - lib/tasks/ruby_forge_config.yml
41
+ - lib/tasks/rubyforge_config.yml
42
+ test_files: []
43
+
44
+ rdoc_options: []
45
+
46
+ extra_rdoc_files: []
47
+
48
+ executables: []
49
+
50
+ extensions: []
51
+
52
+ requirements: []
53
+
54
+ dependencies: []
55
+