filtering_camping 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +43 -0
- data/lib/filtering_camping.rb +43 -0
- metadata +71 -0
data/README
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Only tested on latest HEAD
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'camping'
|
5
|
+
require 'filtering_camping'
|
6
|
+
|
7
|
+
Camping.goes :Filters
|
8
|
+
|
9
|
+
module Filters
|
10
|
+
include FilteringCamping
|
11
|
+
|
12
|
+
before :Index do
|
13
|
+
@hello = 2
|
14
|
+
end
|
15
|
+
|
16
|
+
before '/login' do
|
17
|
+
@world = 3
|
18
|
+
end
|
19
|
+
|
20
|
+
before :all do
|
21
|
+
@var = 1
|
22
|
+
end
|
23
|
+
|
24
|
+
module Controllers
|
25
|
+
class Index < R '/'
|
26
|
+
def get
|
27
|
+
(@hello == 2).to_s
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class Login < R '/login'
|
32
|
+
def get
|
33
|
+
(@world == 4).to_s
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class AnotherOne < R '/@'
|
38
|
+
def get
|
39
|
+
(@var == 1).to_s
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module CampingFilters
|
2
|
+
module ClassMethods
|
3
|
+
def filters
|
4
|
+
@filters ||= {:before => [], :after => []}
|
5
|
+
end
|
6
|
+
|
7
|
+
def before(actions, &blk)
|
8
|
+
actions = [actions] unless actions.is_a?(Array)
|
9
|
+
actions.each do |action|
|
10
|
+
filters[:before] << [action, blk]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def after(actions, &blk)
|
15
|
+
actions = [actions] unless actions.is_a?(Array)
|
16
|
+
actions.each do |action|
|
17
|
+
filters[:after] << [action, blk]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.included(mod)
|
23
|
+
mod.extend(ClassMethods)
|
24
|
+
end
|
25
|
+
|
26
|
+
def run_filters(type)
|
27
|
+
o = self.class.to_s.split("::")
|
28
|
+
filters = Object.const_get(o.first).filters
|
29
|
+
filters[type].each do |filter|
|
30
|
+
if (filter[0].is_a?(Symbol) && (filter[0] == o.last.to_sym || filter[0] == :all)) ||
|
31
|
+
(filter[0].is_a?(String) && /^#{filter[0]}\/?$/ =~ @env.REQUEST_URI)
|
32
|
+
self.instance_eval(&filter[1])
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def service(*a)
|
38
|
+
run_filters(:before)
|
39
|
+
ret = super(*a)
|
40
|
+
run_filters(:after)
|
41
|
+
self
|
42
|
+
end
|
43
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: filtering_camping
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Magnus Holm
|
14
|
+
autorequire: filtering_camping
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-05-30 00:00:00 -06:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: |
|
23
|
+
This is an plugin for the Ruby Camping framework, providing a filtering mechanism for controllers, i.e. the ability to specify code to be executed before and/or after a controller request.
|
24
|
+
|
25
|
+
email:
|
26
|
+
- judofyr@gmail.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- README
|
33
|
+
files:
|
34
|
+
- lib/filtering_camping.rb
|
35
|
+
- README
|
36
|
+
has_rdoc: true
|
37
|
+
homepage: http://github.com/judofyr/filtering_camping/
|
38
|
+
licenses: []
|
39
|
+
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
hash: 3
|
51
|
+
segments:
|
52
|
+
- 0
|
53
|
+
version: "0"
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 3
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
version: "0"
|
63
|
+
requirements: []
|
64
|
+
|
65
|
+
rubyforge_project: filtering_camping
|
66
|
+
rubygems_version: 1.3.7
|
67
|
+
signing_key:
|
68
|
+
specification_version: 3
|
69
|
+
summary: Controller filters for Camping web applications
|
70
|
+
test_files: []
|
71
|
+
|