vex 0.2
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/Manifest +112 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/config/README +2 -0
- data/config/dependencies.rb +10 -0
- data/config/gem.yml +7 -0
- data/init.rb +36 -0
- data/lib/nokogiri/nokogiri_ext.rb +96 -0
- data/lib/vex.rb +5 -0
- data/lib/vex/action_controller.rb +4 -0
- data/lib/vex/action_controller/verify_action.rb +97 -0
- data/lib/vex/action_controller/whitelisted_actions.rb +45 -0
- data/lib/vex/active_record.rb +3 -0
- data/lib/vex/active_record/__init__.rb +0 -0
- data/lib/vex/active_record/advisory_lock.rb +11 -0
- data/lib/vex/active_record/advisory_lock/mysql_adapter.rb +16 -0
- data/lib/vex/active_record/advisory_lock/sqlite_adapter.rb +78 -0
- data/lib/vex/active_record/belongs_to_many.rb +143 -0
- data/lib/vex/active_record/find_by_extension.rb +70 -0
- data/lib/vex/active_record/gem.rb +8 -0
- data/lib/vex/active_record/lite_table.rb +139 -0
- data/lib/vex/active_record/lite_view.rb +140 -0
- data/lib/vex/active_record/mass_load.rb +65 -0
- data/lib/vex/active_record/mysql_backup.rb +21 -0
- data/lib/vex/active_record/plugins/default_value_for/LICENSE.TXT +19 -0
- data/lib/vex/active_record/plugins/default_value_for/README.rdoc +421 -0
- data/lib/vex/active_record/plugins/default_value_for/Rakefile +6 -0
- data/lib/vex/active_record/plugins/default_value_for/init.rb +91 -0
- data/lib/vex/active_record/plugins/default_value_for/test.rb +279 -0
- data/lib/vex/active_record/plugins/default_value_for/test.sqlite3 +0 -0
- data/lib/vex/active_record/random_id.rb +56 -0
- data/lib/vex/active_record/resolver.rb +49 -0
- data/lib/vex/active_record/serialize_hash.rb +125 -0
- data/lib/vex/active_record/to_html.rb +53 -0
- data/lib/vex/active_record/validate.rb +76 -0
- data/lib/vex/active_record/validation_error_ext.rb +68 -0
- data/lib/vex/base.rb +2 -0
- data/lib/vex/base/app.rb +75 -0
- data/lib/vex/base/array/at_random.rb +17 -0
- data/lib/vex/base/array/cross.rb +26 -0
- data/lib/vex/base/array/each_batch.rb +32 -0
- data/lib/vex/base/array/parallel_map.rb +98 -0
- data/lib/vex/base/deprecation.rb +41 -0
- data/lib/vex/base/enumerable/deep.rb +95 -0
- data/lib/vex/base/enumerable/enumerable_ext.rb +59 -0
- data/lib/vex/base/enumerable/progress.rb +71 -0
- data/lib/vex/base/filesystem/fast_copy.rb +61 -0
- data/lib/vex/base/filesystem/grep.rb +34 -0
- data/lib/vex/base/filesystem/lock.rb +43 -0
- data/lib/vex/base/filesystem/lock.rb.test.lck +0 -0
- data/lib/vex/base/filesystem/lock.rb.test.pid +1 -0
- data/lib/vex/base/filesystem/make_dirs.rb +94 -0
- data/lib/vex/base/filesystem/parse_filename.rb +36 -0
- data/lib/vex/base/filesystem/tmp_file.rb +87 -0
- data/lib/vex/base/filesystem/write.rb +43 -0
- data/lib/vex/base/hash/compact.rb +38 -0
- data/lib/vex/base/hash/cross.rb +117 -0
- data/lib/vex/base/hash/easy_access.rb +141 -0
- data/lib/vex/base/hash/ensure_keys.rb +18 -0
- data/lib/vex/base/hash/extract.rb +71 -0
- data/lib/vex/base/hash/extras.rb +62 -0
- data/lib/vex/base/hash/inspect.rb +17 -0
- data/lib/vex/base/hash/simple_access_methods.rb +74 -0
- data/lib/vex/base/invalid_argument/invalid_argument.rb +97 -0
- data/lib/vex/base/local_conf.rb +35 -0
- data/lib/vex/base/net/http_ext.rb +227 -0
- data/lib/vex/base/net/socket_ext.rb +43 -0
- data/lib/vex/base/object/insp.rb +123 -0
- data/lib/vex/base/object/multiple_attributes.rb +58 -0
- data/lib/vex/base/object/singleton_methods.rb +23 -0
- data/lib/vex/base/object/with_benchmark.rb +110 -0
- data/lib/vex/base/range_array.rb +40 -0
- data/lib/vex/base/range_ext.rb +28 -0
- data/lib/vex/base/safe_token.rb +156 -0
- data/lib/vex/base/string/string_ext.rb +136 -0
- data/lib/vex/base/thread/deferred.rb +52 -0
- data/lib/vex/base/thread/sleep.rb +11 -0
- data/lib/vex/base/time/date_ext.rb +12 -0
- data/lib/vex/boot.rb +40 -0
- data/lib/vex/boot/array.rb +22 -0
- data/lib/vex/boot/blank.rb +41 -0
- data/lib/vex/boot/string.rb +60 -0
- data/migration/create_request_log.rb +28 -0
- data/r.rb +35 -0
- data/script/console +19 -0
- data/script/rebuild +7 -0
- data/tasks/echoe.rake +52 -0
- data/tasks/validate_db.rake +14 -0
- data/test/ar.rb +30 -0
- data/test/auto.rb +31 -0
- data/test/base-tests/local_conf.rb +25 -0
- data/test/base.rb +2 -0
- data/test/boot.rb +3 -0
- data/test/config/local.defaults.yml +4 -0
- data/test/config/local.yml +8 -0
- data/test/test.sqlite3 +0 -0
- data/test/test.sqlite3.Class#create.lck +0 -0
- data/test/test.sqlite3.Class#create.lck.lck +0 -0
- data/test/test.sqlite3.Class#create.lck.pid +1 -0
- data/test/test.sqlite3.Class#create.pid +1 -0
- data/test/test.sqlite3.LiteView.make.holders__view_dummy.lck +0 -0
- data/test/test.sqlite3.LiteView.make.holders__view_dummy.lck.lck +0 -0
- data/test/test.sqlite3.LiteView.make.holders__view_dummy.lck.pid +1 -0
- data/test/test.sqlite3.LiteView.make.holders__view_dummy.pid +1 -0
- data/test/test.sqlite3.vex.lck +0 -0
- data/test/test_helper.rb +49 -0
- data/test/tmp/copy.dat +1 -0
- data/test/tmp/lock.sqlite3 +0 -0
- data/test/tmp/lock.sqlite3.etest.lck +0 -0
- data/test/tmp/lock.sqlite3.etest.pid +1 -0
- data/test/tmp/somedata.dat +61 -0
- data/vex.gemspec +49 -0
- data/vex.tmproj +186 -0
- metadata +305 -0
data/Manifest
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
Manifest
|
|
2
|
+
Rakefile
|
|
3
|
+
VERSION
|
|
4
|
+
config/README
|
|
5
|
+
config/dependencies.rb
|
|
6
|
+
config/gem.yml
|
|
7
|
+
init.rb
|
|
8
|
+
lib/nokogiri/nokogiri_ext.rb
|
|
9
|
+
lib/vex.rb
|
|
10
|
+
lib/vex/action_controller.rb
|
|
11
|
+
lib/vex/action_controller/verify_action.rb
|
|
12
|
+
lib/vex/action_controller/whitelisted_actions.rb
|
|
13
|
+
lib/vex/active_record.rb
|
|
14
|
+
lib/vex/active_record/__init__.rb
|
|
15
|
+
lib/vex/active_record/advisory_lock.rb
|
|
16
|
+
lib/vex/active_record/advisory_lock/mysql_adapter.rb
|
|
17
|
+
lib/vex/active_record/advisory_lock/sqlite_adapter.rb
|
|
18
|
+
lib/vex/active_record/belongs_to_many.rb
|
|
19
|
+
lib/vex/active_record/find_by_extension.rb
|
|
20
|
+
lib/vex/active_record/gem.rb
|
|
21
|
+
lib/vex/active_record/lite_table.rb
|
|
22
|
+
lib/vex/active_record/lite_view.rb
|
|
23
|
+
lib/vex/active_record/mass_load.rb
|
|
24
|
+
lib/vex/active_record/mysql_backup.rb
|
|
25
|
+
lib/vex/active_record/plugins/default_value_for/LICENSE.TXT
|
|
26
|
+
lib/vex/active_record/plugins/default_value_for/README.rdoc
|
|
27
|
+
lib/vex/active_record/plugins/default_value_for/Rakefile
|
|
28
|
+
lib/vex/active_record/plugins/default_value_for/init.rb
|
|
29
|
+
lib/vex/active_record/plugins/default_value_for/test.rb
|
|
30
|
+
lib/vex/active_record/plugins/default_value_for/test.sqlite3
|
|
31
|
+
lib/vex/active_record/random_id.rb
|
|
32
|
+
lib/vex/active_record/resolver.rb
|
|
33
|
+
lib/vex/active_record/serialize_hash.rb
|
|
34
|
+
lib/vex/active_record/to_html.rb
|
|
35
|
+
lib/vex/active_record/validate.rb
|
|
36
|
+
lib/vex/active_record/validation_error_ext.rb
|
|
37
|
+
lib/vex/base.rb
|
|
38
|
+
lib/vex/base/app.rb
|
|
39
|
+
lib/vex/base/array/at_random.rb
|
|
40
|
+
lib/vex/base/array/cross.rb
|
|
41
|
+
lib/vex/base/array/each_batch.rb
|
|
42
|
+
lib/vex/base/array/parallel_map.rb
|
|
43
|
+
lib/vex/base/deprecation.rb
|
|
44
|
+
lib/vex/base/enumerable/deep.rb
|
|
45
|
+
lib/vex/base/enumerable/enumerable_ext.rb
|
|
46
|
+
lib/vex/base/enumerable/progress.rb
|
|
47
|
+
lib/vex/base/filesystem/fast_copy.rb
|
|
48
|
+
lib/vex/base/filesystem/grep.rb
|
|
49
|
+
lib/vex/base/filesystem/lock.rb
|
|
50
|
+
lib/vex/base/filesystem/lock.rb.test.lck
|
|
51
|
+
lib/vex/base/filesystem/lock.rb.test.pid
|
|
52
|
+
lib/vex/base/filesystem/make_dirs.rb
|
|
53
|
+
lib/vex/base/filesystem/parse_filename.rb
|
|
54
|
+
lib/vex/base/filesystem/tmp_file.rb
|
|
55
|
+
lib/vex/base/filesystem/write.rb
|
|
56
|
+
lib/vex/base/hash/compact.rb
|
|
57
|
+
lib/vex/base/hash/cross.rb
|
|
58
|
+
lib/vex/base/hash/easy_access.rb
|
|
59
|
+
lib/vex/base/hash/ensure_keys.rb
|
|
60
|
+
lib/vex/base/hash/extract.rb
|
|
61
|
+
lib/vex/base/hash/extras.rb
|
|
62
|
+
lib/vex/base/hash/inspect.rb
|
|
63
|
+
lib/vex/base/hash/simple_access_methods.rb
|
|
64
|
+
lib/vex/base/invalid_argument/invalid_argument.rb
|
|
65
|
+
lib/vex/base/local_conf.rb
|
|
66
|
+
lib/vex/base/net/http_ext.rb
|
|
67
|
+
lib/vex/base/net/socket_ext.rb
|
|
68
|
+
lib/vex/base/object/insp.rb
|
|
69
|
+
lib/vex/base/object/multiple_attributes.rb
|
|
70
|
+
lib/vex/base/object/singleton_methods.rb
|
|
71
|
+
lib/vex/base/object/with_benchmark.rb
|
|
72
|
+
lib/vex/base/range_array.rb
|
|
73
|
+
lib/vex/base/range_ext.rb
|
|
74
|
+
lib/vex/base/safe_token.rb
|
|
75
|
+
lib/vex/base/string/string_ext.rb
|
|
76
|
+
lib/vex/base/thread/deferred.rb
|
|
77
|
+
lib/vex/base/thread/sleep.rb
|
|
78
|
+
lib/vex/base/time/date_ext.rb
|
|
79
|
+
lib/vex/boot.rb
|
|
80
|
+
lib/vex/boot/array.rb
|
|
81
|
+
lib/vex/boot/blank.rb
|
|
82
|
+
lib/vex/boot/string.rb
|
|
83
|
+
migration/create_request_log.rb
|
|
84
|
+
r.rb
|
|
85
|
+
script/console
|
|
86
|
+
script/rebuild
|
|
87
|
+
tasks/echoe.rake
|
|
88
|
+
tasks/validate_db.rake
|
|
89
|
+
test/ar.rb
|
|
90
|
+
test/auto.rb
|
|
91
|
+
test/base-tests/local_conf.rb
|
|
92
|
+
test/base.rb
|
|
93
|
+
test/boot.rb
|
|
94
|
+
test/config/local.defaults.yml
|
|
95
|
+
test/config/local.yml
|
|
96
|
+
test/test.sqlite3
|
|
97
|
+
test/test.sqlite3.Class#create.lck
|
|
98
|
+
test/test.sqlite3.Class#create.lck.lck
|
|
99
|
+
test/test.sqlite3.Class#create.lck.pid
|
|
100
|
+
test/test.sqlite3.Class#create.pid
|
|
101
|
+
test/test.sqlite3.LiteView.make.holders__view_dummy.lck
|
|
102
|
+
test/test.sqlite3.LiteView.make.holders__view_dummy.lck.lck
|
|
103
|
+
test/test.sqlite3.LiteView.make.holders__view_dummy.lck.pid
|
|
104
|
+
test/test.sqlite3.LiteView.make.holders__view_dummy.pid
|
|
105
|
+
test/test.sqlite3.vex.lck
|
|
106
|
+
test/test_helper.rb
|
|
107
|
+
test/tmp/copy.dat
|
|
108
|
+
test/tmp/lock.sqlite3
|
|
109
|
+
test/tmp/lock.sqlite3.etest.lck
|
|
110
|
+
test/tmp/lock.sqlite3.etest.pid
|
|
111
|
+
test/tmp/somedata.dat
|
|
112
|
+
vex.tmproj
|
data/Rakefile
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
task :default => :"test:all"
|
|
2
|
+
task :test => :"test:all"
|
|
3
|
+
task :rcov => :"rcov:all"
|
|
4
|
+
|
|
5
|
+
namespace :test do
|
|
6
|
+
task :boot do
|
|
7
|
+
sh "ruby test/boot.rb"
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
task :base do
|
|
11
|
+
sh "ruby test/base.rb"
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
task :ar do
|
|
15
|
+
sh "ruby test/ar.rb"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
task :auto do
|
|
19
|
+
sh "ruby test/auto.rb"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
task :all => %w(boot base ar)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
namespace :rcov do
|
|
26
|
+
task :boot do
|
|
27
|
+
sh "rcov -T -o coverage/boot -x ruby/.*/gems test/boot.rb"
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
task :base do
|
|
31
|
+
sh "rcov -T -o coverage/base -x /vex/boot/ -x ruby/.*/gems test/base.rb"
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
task :ar do
|
|
35
|
+
sh "rcov -T -o coverage/ar -x /vex/boot/ -x /plugins/ -x /vex/base/ -x ruby/.*/gems test/ar.rb"
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
task :all => %w(boot base)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
task :rebuild => :test do
|
|
42
|
+
sh "rake -f tasks/echoe.rake rebuild"
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
task :manifest do
|
|
46
|
+
sh "rake -f tasks/echoe.rake manifest"
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
SKIP_ECHOE=true
|
|
50
|
+
|
|
51
|
+
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each do |ext|
|
|
52
|
+
load ext
|
|
53
|
+
end
|
data/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.2
|
data/config/README
ADDED
data/config/gem.yml
ADDED
data/init.rb
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#
|
|
2
|
+
# The initializer for the gem. Runs whenever the gem is loaded.
|
|
3
|
+
#
|
|
4
|
+
# DON'T CHANGE THIS FILE, CHANGE config/gem.rb INSTEAD!
|
|
5
|
+
#
|
|
6
|
+
|
|
7
|
+
__END__
|
|
8
|
+
|
|
9
|
+
gem_root = File.expand_path(File.dirname(__FILE__))
|
|
10
|
+
gem_name = File.basename gem_root
|
|
11
|
+
|
|
12
|
+
require "rubygems"
|
|
13
|
+
|
|
14
|
+
load "#{gem_root}/config/gem.rb"
|
|
15
|
+
load "#{gem_root}/config/dependencies.rb"
|
|
16
|
+
load "#{gem_root}/lib/#{gem_name}.rb"
|
|
17
|
+
|
|
18
|
+
dirs = Dir.glob("#{gem_root}/lib/*").select do |dir|
|
|
19
|
+
File.directory?(dir)
|
|
20
|
+
end.sort_by do |dir|
|
|
21
|
+
dir.ends_with?("boot") ? "" : dir
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
dirs.each do |dir|
|
|
25
|
+
if File.exists?("#{dir}/__init__.rb")
|
|
26
|
+
load("#{dir}/__init__.rb")
|
|
27
|
+
else
|
|
28
|
+
Dir.glob("#{dir}/*.rb").sort.each do |file|
|
|
29
|
+
load file
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
Dir.glob("#{gem_root}/lib/*.rb").sort.each do |file|
|
|
35
|
+
load file
|
|
36
|
+
end
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
module NokogiriExt
|
|
2
|
+
def full_name
|
|
3
|
+
ns = namespace
|
|
4
|
+
ns ? "#{ns}:#{name}" : name
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def transform(&block)
|
|
8
|
+
case r = yield(self)
|
|
9
|
+
when false
|
|
10
|
+
self.remove
|
|
11
|
+
when String
|
|
12
|
+
Nokogiri::HTML.fragment(r).children.each do |n|
|
|
13
|
+
add_previous_sibling n
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
self.remove
|
|
17
|
+
when Nokogiri::XML::Node
|
|
18
|
+
add_previous_sibling r
|
|
19
|
+
self.remove
|
|
20
|
+
else
|
|
21
|
+
children.each do |child| child.transform(&block) end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def remove_blanks
|
|
26
|
+
transform do |n|
|
|
27
|
+
n.name != "text" || !n.text.blank?
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
class Nokogiri::XML::Node
|
|
33
|
+
include NokogiriExt
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
class Nokogiri::XML::Document
|
|
37
|
+
private :transform
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
module NokogiriExt::Etest
|
|
41
|
+
SOURCE = <<-XML
|
|
42
|
+
<bb>
|
|
43
|
+
<i:xy></i:xy>
|
|
44
|
+
</bb>
|
|
45
|
+
XML
|
|
46
|
+
|
|
47
|
+
def assert_xml_equals(expected, actual)
|
|
48
|
+
expected = Nokogiri::XML(expected)
|
|
49
|
+
|
|
50
|
+
if expected == actual
|
|
51
|
+
assert true
|
|
52
|
+
return
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
expected = expected.remove_blanks
|
|
56
|
+
actual = actual.remove_blanks
|
|
57
|
+
|
|
58
|
+
if expected == actual
|
|
59
|
+
assert true
|
|
60
|
+
return
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
expected = expected.to_s.gsub(/<\?xml version=\"1.0\"\?>\n/, "")
|
|
64
|
+
actual = actual.to_s.gsub(/<\?xml version=\"1.0\"\?>\n/, "")
|
|
65
|
+
|
|
66
|
+
assert_equal expected, actual
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def test_assertion
|
|
70
|
+
doc = Nokogiri::XML SOURCE
|
|
71
|
+
assert_xml_equals SOURCE, doc
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def test_transform
|
|
75
|
+
doc = Nokogiri::XML SOURCE
|
|
76
|
+
doc.root.transform do |s| "<cc />" end
|
|
77
|
+
assert_xml_equals "<cc/>", doc
|
|
78
|
+
|
|
79
|
+
doc = Nokogiri::XML SOURCE
|
|
80
|
+
doc.root.transform do |s| s.name != "xy" end
|
|
81
|
+
assert_xml_equals "<bb/>", doc
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def test_transform2
|
|
85
|
+
doc = Nokogiri::XML SOURCE
|
|
86
|
+
doc.root.transform do |s|
|
|
87
|
+
if s.name == "xy"
|
|
88
|
+
"<cc />"
|
|
89
|
+
elsif s.name == "text" && s.text.blank?
|
|
90
|
+
false
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
assert_xml_equals "<bb><cc/></bb>", doc
|
|
95
|
+
end
|
|
96
|
+
end
|
data/lib/vex.rb
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# This module adds/modifies ActionController::Verification. It adds
|
|
2
|
+
#
|
|
3
|
+
# - adds verify? and verify, which verifies conditions on a per action
|
|
4
|
+
# base. On error the former returns false, while the latter raises
|
|
5
|
+
# an exception.
|
|
6
|
+
# - adds improved error messages
|
|
7
|
+
#
|
|
8
|
+
module ActionController::VerifyAction
|
|
9
|
+
class Error < ArgumentError; end
|
|
10
|
+
|
|
11
|
+
def self.fail(options, better_msg=nil)
|
|
12
|
+
msg = "Action verification failed: #{options.inspect}"
|
|
13
|
+
msg += " #{better_msg}" if better_msg
|
|
14
|
+
|
|
15
|
+
raise Error, "#{msg}."
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
|
|
20
|
+
def fail(*args)
|
|
21
|
+
ActionController::VerifyAction.fail(*args)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Rails 2.3's verify_action method does NOT return a value. Instead it
|
|
25
|
+
# 'executes' the add_flash, add_headers, render, and/or redirect_to
|
|
26
|
+
# options. We raise an additional exception here for a failed verification,
|
|
27
|
+
# which is to be catched later on to return true or false.
|
|
28
|
+
#
|
|
29
|
+
def apply_remaining_actions(options) # :nodoc:
|
|
30
|
+
super
|
|
31
|
+
fail(options)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Override Rails' verify_action
|
|
35
|
+
def verify_action(opts, catch_error = true)
|
|
36
|
+
begin
|
|
37
|
+
super(opts)
|
|
38
|
+
true
|
|
39
|
+
rescue Error
|
|
40
|
+
raise unless catch_error
|
|
41
|
+
false
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def verify?(opts)
|
|
46
|
+
verify_action(opts, true)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def verify(opts)
|
|
50
|
+
verify_action(opts, false)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# -- Reimplements Rails' verifications to add better error messages
|
|
54
|
+
|
|
55
|
+
def verify_presence_of_keys_in_hash(options, entry, hash) # :nodoc:
|
|
56
|
+
return unless keys = options[entry]
|
|
57
|
+
missing = if keys.is_a?(Array)
|
|
58
|
+
keys.find { |v| hash[v].nil? }
|
|
59
|
+
elsif hash[keys].nil?
|
|
60
|
+
keys
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
return unless missing
|
|
64
|
+
|
|
65
|
+
fail(options, "Missing key #{missing.inspect} in #{entry}")
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def verify_presence_of_keys_in_hash_flash_or_params(options) # :nodoc:
|
|
69
|
+
verify_presence_of_keys_in_hash(options, :params, params) ||
|
|
70
|
+
verify_presence_of_keys_in_hash(options, :session, session) ||
|
|
71
|
+
verify_presence_of_keys_in_hash(options, :flash, flash)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def verify_method(options) # :nodoc:
|
|
75
|
+
methods = options[:method]
|
|
76
|
+
return if methods.nil?
|
|
77
|
+
|
|
78
|
+
if methods.is_a?(Array)
|
|
79
|
+
return if methods.include?(request.method)
|
|
80
|
+
return if methods.include?(request.method.to_s)
|
|
81
|
+
else
|
|
82
|
+
return if request.method == methods.to_sym
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
fail(options, "Invalid request method #{request.method}")
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def verify_request_xhr_status(options) # :nodoc:
|
|
89
|
+
return if options[:xhr].nil?
|
|
90
|
+
return if request.xhr? == options[:xhr]
|
|
91
|
+
fail(options, "Unsupported XHR state #{request.xhr?}")
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
class ActionController::Base
|
|
96
|
+
include VerifyAction
|
|
97
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
class ActionController::Base
|
|
2
|
+
def self.whitelist_actions(*names)
|
|
3
|
+
extend WhitelistActions
|
|
4
|
+
include WhitelistControllerActions
|
|
5
|
+
|
|
6
|
+
before_filter :verify_whitelisted_actions
|
|
7
|
+
|
|
8
|
+
actions *names
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
module WhitelistControllerActions
|
|
12
|
+
def verify_whitelisted_actions
|
|
13
|
+
return if self.class.name.starts_with?("Clearance::")
|
|
14
|
+
|
|
15
|
+
valid_actions = self.class.whitelisted_actions
|
|
16
|
+
return if valid_actions == :skip || valid_actions.include?(action_name)
|
|
17
|
+
|
|
18
|
+
unless Rails.env.development?
|
|
19
|
+
error 404, "This page doesn't exist"
|
|
20
|
+
return
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
error 404, <<-TEXT
|
|
24
|
+
No such action exists: #{controller_name}##{action_name}.
|
|
25
|
+
Note: this application uses the whitelisted_actions plugin,
|
|
26
|
+
you might have to use the 'actions' method to whitelist your actions.
|
|
27
|
+
TEXT
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
module WhitelistActions
|
|
32
|
+
def whitelisted_actions
|
|
33
|
+
@whitelisted_actions ||
|
|
34
|
+
(superclass.respond_to?(:whitelisted_actions) ? superclass.whitelisted_actions : nil)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def skip_whitelist_actions
|
|
38
|
+
@whitelisted_actions = :skip
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def actions(*names)
|
|
42
|
+
@whitelisted_actions = names.map(&:to_s).to_set
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|