rlyeh 0.0.1 → 0.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/example/simple.rb DELETED
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # -*- coding: utf-8 -*-
3
- $LOAD_PATH.unshift 'lib'
4
- require 'rlyeh'
5
-
6
- class MyApp < Rlyeh::Base
7
- on :privmsg do |env|
8
- p "MyApp1: #{env.message}"
9
- end
10
-
11
- on :privmsg do |env|
12
- p "MyApp2: #{env.message}"
13
- end
14
- end
15
-
16
- Rlyeh.run MyApp
data/lib/rlyeh/filter.rb DELETED
@@ -1,77 +0,0 @@
1
- module Rlyeh
2
- module Filter
3
- def self.included(base)
4
- base.extend ClassMethods
5
- end
6
-
7
- module ClassMethods
8
- def define_filter(*names, &block)
9
- names.each do |name|
10
- unless method_defined?("#{name}_with_filter")
11
- define_method(:"#{name}_with_filter") do |*args, &block|
12
- _run_filter_callbacks(:"#{name}", [:before, :around], *args, &block)
13
- result = send(:"#{name}_without_filter", *args, &block)
14
- _run_filter_callbacks(:"#{name}", [:around, :after], *args, &block)
15
- result
16
- end
17
- alias_method :"#{name}_without_filter", :"#{name}"
18
- alias_method :"#{name}", :"#{name}_with_filter"
19
- end
20
- end
21
- end
22
- end
23
-
24
- def _filter_callbacks
25
- @_filter_callbacks ||= {}
26
- end
27
- private :_filter_callbacks
28
-
29
- def _run_filter_callbacks(name, types, *args, &block)
30
- named_filter_callbacks = _filter_callbacks[name] || {}
31
- types.each do |type|
32
- (named_filter_callbacks[type] || []).each do |callback|
33
- callback.call(*args, &block)
34
- end
35
- end
36
- end
37
- private :_run_filter_callbacks
38
-
39
- def _insert_filter_callbacks(names, type, block, options = {})
40
- prepend = options[:prepend]
41
- names.each do |name|
42
- named_filter_callbacks = (_filter_callbacks[:"#{name}"] ||= {})
43
- callbacks = (named_filter_callbacks[type] ||= [])
44
- if prepend
45
- callbacks.unshift block
46
- else
47
- callbacks.push block
48
- end
49
- end
50
- end
51
- private :_insert_filter_callbacks
52
-
53
- def _remove_filter_callbacks(names, type, block)
54
- names.each do |name|
55
- named_filter_callbacks = (_filter_callbacks[:"#{name}"] ||= {})
56
- callbacks = (named_filter_callbacks[type] ||= [])
57
- callbacks.delete block
58
- end
59
- end
60
- private :_remove_filter_callbacks
61
-
62
- [:before, :after, :around].each do |type|
63
- define_method(:"#{type}_filter") do |*names, &block|
64
- _insert_filter_callbacks(names, type, block)
65
- end
66
- alias_method :"append_#{type}_filter", :"#{type}_filter"
67
-
68
- define_method(:"prepend_#{type}_filter") do |*names, &block|
69
- _insert_filter_callbacks(names, type, block, :prepend => true)
70
- end
71
-
72
- define_method(:"remove_#{type}_filter") do |*names, &block|
73
- _remove_filter_callbacks(names, type, block)
74
- end
75
- end
76
- end
77
- end
@@ -1,31 +0,0 @@
1
- module Rlyeh
2
- module Middleware
3
- class Builder
4
- def initialize(&block)
5
- @ins = []
6
- instance_eval(&block) if block_given?
7
- end
8
-
9
- def self.app(&block)
10
- self.new(&block).to_app
11
- end
12
-
13
- def use(middleware, *args, &block)
14
- @ins << lambda { |app| middleware.new(app, *args, &block) }
15
- end
16
-
17
- def run(app)
18
- @ins << app #lambda { |nothing| app }
19
- end
20
-
21
- def to_app
22
- inner_app = @ins.last
23
- @ins[0...-1].reverse.inject(inner_app) { |a, e| e.call(a) }
24
- end
25
-
26
- def call(env)
27
- to_app.call(env)
28
- end
29
- end
30
- end
31
- end