-
Notifications
You must be signed in to change notification settings - Fork 0
/
events_conf.rb
49 lines (42 loc) · 1006 Bytes
/
events_conf.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Events-based configuration mechanism
#TODO(0) Defaults + validity properties
module AsyncConfModule
def conf_reader(*attrs)
for attr in attrs
module_eval <<-"end;"
def #{attr.to_s}
if defined?(@#{attr.to_s}) && @#{attr.to_s}
@#{attr.to_s}
else
configure! :#{attr.to_s}
nil
end
end
end;
end
end
def conf_writer(*attrs)
for attr in attrs
module_eval <<-"end;"
def #{attr.to_s}=(val)
@#{attr.to_s} = val
configured! :#{attr.to_s}
end
end;
end
end
def conf_accessor(*attrs)
conf_reader(*attrs)
conf_writer(*attrs)
end
protected :conf_reader, :conf_writer, :conf_accessor
end
#TODO(1) Separate!
module ConfAttributes
include EventPooling
fires :configure, :configured
# This is the valid signature for :configured event handler
# def configured(src, *args) #event(target, *properties)
##E.g. refresh
# end
end