filt 0.0.3
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/lib/filt.rb +43 -0
- metadata +67 -0
data/lib/filt.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
module Filters
|
2
|
+
class << self
|
3
|
+
def included(mod)
|
4
|
+
mod.extend(Filters::ClassMethods)
|
5
|
+
mod.instance_methods(false).each{|method|mod.add_global_hook(method)}
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
def add_global_hook(method)
|
11
|
+
alias_method "__#{method}", method
|
12
|
+
define_method method do |*args,&block|
|
13
|
+
@@before_hooks ||= {}
|
14
|
+
@@after_hooks ||= {}
|
15
|
+
@@before_hooks.keys.each do |hook|
|
16
|
+
unless (@@before_hooks[hook][:except]||[]).include?(method) || (@@before_hooks[hook][:only] && !@@before_hooks[hook][:only].include?(method))
|
17
|
+
return unless send(hook)
|
18
|
+
end
|
19
|
+
end unless @@before_hooks[method] || @@after_hooks[method]
|
20
|
+
send("__#{method}",*args,&block)
|
21
|
+
@@after_hooks.keys.each do |hook|
|
22
|
+
unless (@@after_hooks[hook][:except]||[]).include?(method) || (@@after_hooks[hook][:only] && !@@after_hooks[hook][:only].include?(method))
|
23
|
+
return unless send(hook)
|
24
|
+
end
|
25
|
+
end unless @@before_hooks[method] || @@after_hooks[method]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def before_filter(hook_method,options={})
|
30
|
+
options.keys.each{|k|options[k] = [options[k]].flatten}
|
31
|
+
(@@before_hooks||={})[hook_method.to_sym] = options
|
32
|
+
end
|
33
|
+
|
34
|
+
def after_filter(hook_method,options={})
|
35
|
+
options.keys.each{|k|options[k] = [options[k]].flatten}
|
36
|
+
(@@after_hooks||={})[hook_method.to_sym] = options
|
37
|
+
end
|
38
|
+
|
39
|
+
def method_added(method)
|
40
|
+
add_global_hook(method) unless method.to_s[0,2] == "__" || instance_methods.include?("__#{method}".to_sym)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: filt
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 25
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
|
+
platform: ruby
|
12
|
+
authors: []
|
13
|
+
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-09-10 00:00:00 -05:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description:
|
23
|
+
email:
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
30
|
+
files:
|
31
|
+
- lib/filt.rb
|
32
|
+
has_rdoc: true
|
33
|
+
homepage:
|
34
|
+
licenses: []
|
35
|
+
|
36
|
+
post_install_message:
|
37
|
+
rdoc_options: []
|
38
|
+
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
hash: 3
|
47
|
+
segments:
|
48
|
+
- 0
|
49
|
+
version: "0"
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
hash: 3
|
56
|
+
segments:
|
57
|
+
- 0
|
58
|
+
version: "0"
|
59
|
+
requirements: []
|
60
|
+
|
61
|
+
rubyforge_project:
|
62
|
+
rubygems_version: 1.3.7
|
63
|
+
signing_key:
|
64
|
+
specification_version: 3
|
65
|
+
summary: before and after filter support for Ruby
|
66
|
+
test_files: []
|
67
|
+
|