46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/roap/roap.rb', line 46
def included base
targets = []
base.singleton_methods(false).each do |method_name|
method = get_pure base, method_name
method ||= base.singleton_method(method_name)
targets.push({
:type => :singleton_method,
:name => method_name,
:pure => method })
end
base.instance_methods(false).each do |method_name|
method = get_pure base, method_name
method ||= base.instance_method(method_name)
targets.push({
:type => :instance_method,
:name => method_name,
:pure => method })
end
targets.each do |target|
pure = target[:pure]
method_name = target[:name]
type = target[:type]
attr = target[:pure].
attrs = []
body = Roap::Utils:: pure.
mds = body.scan /(@([^\n]+)\n((\s\s+[^\n]*\n?)*))/m
mds.each do |match, key, value|
attrs.push({:key=>key, :value=>value})
end
rules.each do |rule|
mds = Roap::Utils::scanex attr, rule[:expr]
mds.each do |md|
on_rules = Roap.class_variable_get :@@rules
on_rules.each do |on_rule|
on_md = rule[:attrs].match on_rule[:expr]
if on_md != nil
method = base.__send__ type, method_name
@@original_methods["#{base}::#{method.name}"] ||= method
method.define_singleton_method :pure do
@@original_methods["#{base}::#{method.name}"]
end
method.define_singleton_method :attrs do
attrs
end
on_rule[:block].call base, method, md, rule
end
end
break if rule[:attrs].match /^#\s*once/
end
end
end
end
|