wonkavision 0.5.4 → 0.5.9
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/CHANGELOG.rdoc +28 -16
- data/Gemfile +5 -0
- data/LICENSE.txt +21 -21
- data/Rakefile +47 -47
- data/lib/wonkavision.rb +75 -74
- data/lib/wonkavision/acts_as_oompa_loompa.rb +22 -22
- data/lib/wonkavision/event_binding.rb +21 -21
- data/lib/wonkavision/event_context.rb +9 -9
- data/lib/wonkavision/event_coordinator.rb +75 -75
- data/lib/wonkavision/event_handler.rb +15 -15
- data/lib/wonkavision/event_namespace.rb +79 -79
- data/lib/wonkavision/event_path_segment.rb +35 -35
- data/lib/wonkavision/message_mapper.rb +30 -30
- data/lib/wonkavision/message_mapper/indifferent_access.rb +30 -26
- data/lib/wonkavision/message_mapper/map.rb +241 -153
- data/lib/wonkavision/persistence/mongo_mapper_adapter.rb +32 -32
- data/lib/wonkavision/persistence/mongoid_adapter.rb +32 -0
- data/lib/wonkavision/plugins.rb +30 -30
- data/lib/wonkavision/plugins/business_activity.rb +92 -92
- data/lib/wonkavision/plugins/business_activity/event_binding.rb +15 -15
- data/lib/wonkavision/plugins/callbacks.rb +182 -182
- data/lib/wonkavision/plugins/event_handling.rb +111 -111
- data/lib/wonkavision/plugins/timeline.rb +79 -79
- data/lib/wonkavision/version.rb +3 -3
- data/test/business_activity_test.rb +31 -31
- data/test/event_handler_test.rb +68 -69
- data/test/event_namespace_test.rb +108 -108
- data/test/event_path_segment_test.rb +41 -41
- data/test/log/test.log +817 -18354
- data/test/map_test.rb +315 -201
- data/test/message_mapper_test.rb +20 -20
- data/test/test_activity_models.rb +72 -72
- data/test/test_helper.rb +70 -63
- data/test/timeline_test.rb +55 -61
- data/test/wonkavision_test.rb +9 -9
- metadata +72 -12
- data/wonkavision.gemspec +0 -97
@@ -1,26 +1,30 @@
|
|
1
|
-
module Wonkavision
|
2
|
-
module MessageMapper
|
3
|
-
module IndifferentAccess
|
4
|
-
def [](key)
|
5
|
-
key = key.to_s
|
6
|
-
super(key)
|
7
|
-
end
|
8
|
-
|
9
|
-
def []=(key,val)
|
10
|
-
super(key.to_s,val)
|
11
|
-
end
|
12
|
-
|
13
|
-
def include?(key)
|
14
|
-
super(key.to_s)
|
15
|
-
end
|
16
|
-
|
17
|
-
def
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
26
|
-
|
1
|
+
module Wonkavision
|
2
|
+
module MessageMapper
|
3
|
+
module IndifferentAccess
|
4
|
+
def [](key)
|
5
|
+
key = key.to_s
|
6
|
+
super(key)
|
7
|
+
end
|
8
|
+
|
9
|
+
def []=(key,val)
|
10
|
+
super(key.to_s,val)
|
11
|
+
end
|
12
|
+
|
13
|
+
def include?(key)
|
14
|
+
super(key.to_s)
|
15
|
+
end
|
16
|
+
|
17
|
+
def delete(key)
|
18
|
+
super(key.to_s)
|
19
|
+
end
|
20
|
+
|
21
|
+
def method_missing(sym,*args,&block)
|
22
|
+
return self[sym.to_s[0..-2]] = args[0] if sym.to_s =~ /.*=$/
|
23
|
+
return self[sym] if self.keys.include?(sym.to_s)
|
24
|
+
nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
@@ -1,153 +1,241 @@
|
|
1
|
-
module Wonkavision
|
2
|
-
|
3
|
-
module MessageMapper
|
4
|
-
class Map < Hash
|
5
|
-
include IndifferentAccess
|
6
|
-
|
7
|
-
def initialize(context)
|
8
|
-
@context_stack = []
|
9
|
-
@context_stack.push(context)
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
@context_stack
|
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
|
-
|
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
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
def
|
120
|
-
value(*args)
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
end
|
1
|
+
module Wonkavision
|
2
|
+
|
3
|
+
module MessageMapper
|
4
|
+
class Map < Hash
|
5
|
+
include IndifferentAccess
|
6
|
+
|
7
|
+
def initialize(context)
|
8
|
+
@context_stack = []
|
9
|
+
@context_stack.push(context)
|
10
|
+
@formats = default_formats
|
11
|
+
end
|
12
|
+
|
13
|
+
def formats
|
14
|
+
@formats
|
15
|
+
end
|
16
|
+
|
17
|
+
def context
|
18
|
+
@context_stack[-1]
|
19
|
+
end
|
20
|
+
|
21
|
+
def from (context,&block)
|
22
|
+
raise "No block ws provided to 'from'" unless block
|
23
|
+
return if context.nil?
|
24
|
+
|
25
|
+
@context_stack.push(context)
|
26
|
+
instance_eval(&block)
|
27
|
+
@context_stack.pop
|
28
|
+
end
|
29
|
+
|
30
|
+
def exec(map_name,exec_context=self.context)
|
31
|
+
mapped = MessageMapper.execute(map_name,exec_context)
|
32
|
+
self.merge!(mapped) if mapped
|
33
|
+
end
|
34
|
+
alias import exec
|
35
|
+
alias apply exec
|
36
|
+
|
37
|
+
def child(source,options={},&block)
|
38
|
+
raise "Neither a block nor a map_name were provided to 'map'" unless (block || options.keys.include?(:map_name))
|
39
|
+
if (source.is_a?(Hash))
|
40
|
+
field_name = source.keys[0]
|
41
|
+
ctx = source[field_name]
|
42
|
+
else
|
43
|
+
field_name = source
|
44
|
+
ctx = extract_value_from_context(context,field_name)
|
45
|
+
end
|
46
|
+
if ctx
|
47
|
+
if (map_name = options.delete(:map_name))
|
48
|
+
child = MessageMapper.execute(map_name,ctx)
|
49
|
+
else
|
50
|
+
child = Map.new(ctx)
|
51
|
+
child.instance_eval(&block)
|
52
|
+
end
|
53
|
+
else
|
54
|
+
child = {}
|
55
|
+
end
|
56
|
+
set_value(field_name,child,options)
|
57
|
+
end
|
58
|
+
|
59
|
+
def array(source,options={},&block)
|
60
|
+
if (source.is_a?(Hash))
|
61
|
+
field_name = source.keys[0]
|
62
|
+
ctx = source[field_name]
|
63
|
+
else
|
64
|
+
field_name = source
|
65
|
+
ctx = extract_value_from_context(context,field_name)
|
66
|
+
end
|
67
|
+
result = []
|
68
|
+
ctx = [ctx].compact.flatten
|
69
|
+
map_name = options.delete(:map_name)
|
70
|
+
ctx.each do |item|
|
71
|
+
if (map_name)
|
72
|
+
child = MessageMapper.execute(map_name,item)
|
73
|
+
else
|
74
|
+
child = Map.new(item)
|
75
|
+
child.instance_eval(&block)
|
76
|
+
end
|
77
|
+
result << child
|
78
|
+
end
|
79
|
+
set_value(field_name,result,options)
|
80
|
+
end
|
81
|
+
|
82
|
+
def string(*args)
|
83
|
+
value(*args) {to_s}
|
84
|
+
end
|
85
|
+
|
86
|
+
def float(*args)
|
87
|
+
value(*args){respond_to?(:to_f) ? to_f : self}
|
88
|
+
end
|
89
|
+
|
90
|
+
def dollars(*args)
|
91
|
+
args = add_options(args,:format=>:dollars)
|
92
|
+
float(*args)
|
93
|
+
end
|
94
|
+
alias dollar dollars
|
95
|
+
|
96
|
+
def percent(*args)
|
97
|
+
args = add_options(args,:format=>:percent)
|
98
|
+
float(*args)
|
99
|
+
end
|
100
|
+
alias percentage percent
|
101
|
+
|
102
|
+
def yes_no(*args)
|
103
|
+
args = add_options(args,:format=>:yes_no)
|
104
|
+
value(*args)
|
105
|
+
end
|
106
|
+
|
107
|
+
def iso8601(*args)
|
108
|
+
value(*args) do
|
109
|
+
if respond_to?(:strftime)
|
110
|
+
strftime("%Y-%m-%dT%H:%M:%S")
|
111
|
+
elsif respond_to?(:ToString)
|
112
|
+
ToString("yyyy-MM-ddTHH:mm:ss")
|
113
|
+
else
|
114
|
+
self
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def time(*args)
|
120
|
+
value(*args) do
|
121
|
+
if kind_of?(Time)
|
122
|
+
self
|
123
|
+
elsif respond_to?(:to_time)
|
124
|
+
to_time
|
125
|
+
elsif (time_str=to_s) && time_str.length > 0
|
126
|
+
begin
|
127
|
+
Time.parse(time_str)
|
128
|
+
rescue
|
129
|
+
self
|
130
|
+
end
|
131
|
+
else
|
132
|
+
self
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def date(*args)
|
138
|
+
value(*args) do
|
139
|
+
if kind_of?(Date)
|
140
|
+
self
|
141
|
+
elsif respond_to?(:to_date)
|
142
|
+
to_time
|
143
|
+
elsif (date_str=to_s) && date_str.length > 0
|
144
|
+
begin
|
145
|
+
Date.parse(date_str)
|
146
|
+
rescue
|
147
|
+
self
|
148
|
+
end
|
149
|
+
else
|
150
|
+
self
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
def boolean(*args)
|
156
|
+
value(*args) do
|
157
|
+
%w(true yes).include?(to_s.downcase) ? true : false
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
def int(*args)
|
162
|
+
value(*args){respond_to?(:to_i) ? to_i : self}
|
163
|
+
end
|
164
|
+
alias integer int
|
165
|
+
|
166
|
+
def value(*args,&block)
|
167
|
+
opts = args.length > 1 ? args.extract_options! : {}
|
168
|
+
|
169
|
+
if (args.length == 1 && args[0].is_a?(Hash))
|
170
|
+
args[0].each do |key,value|
|
171
|
+
value = context.instance_eval(&value) if value.is_a?(Proc)
|
172
|
+
value = value.instance_eval(&block) if block
|
173
|
+
set_value(key,value,opts)
|
174
|
+
end
|
175
|
+
else
|
176
|
+
args.each do |field_name|
|
177
|
+
value = extract_value_from_context(context,field_name,block)
|
178
|
+
set_value(field_name,value,opts)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
private
|
184
|
+
def format_value(val,opts={})
|
185
|
+
val = opts[:default] || opts[:default_value] if val.nil?
|
186
|
+
return val if val.nil?
|
187
|
+
|
188
|
+
format = opts[:format]
|
189
|
+
format ||= :float if opts[:precision]
|
190
|
+
return val unless format
|
191
|
+
formatter = formats[format] || format
|
192
|
+
default_formatter = formats[:default]
|
193
|
+
|
194
|
+
formatter.respond_to?(:call) ? formatter.call(val,format,opts) : default_formatter.call(val,formatter,opts)
|
195
|
+
end
|
196
|
+
|
197
|
+
def extract_value_from_context(context,field_name,block=nil)
|
198
|
+
if context.respond_to?(field_name.to_sym)
|
199
|
+
value = context.instance_eval("self.#{field_name}")
|
200
|
+
elsif context.respond_to?(:[])
|
201
|
+
value = context[field_name]
|
202
|
+
if value.nil? && field_name
|
203
|
+
value = context[field_name.to_sym] || context[field_name.to_s]
|
204
|
+
end
|
205
|
+
else
|
206
|
+
value = nil
|
207
|
+
end
|
208
|
+
value = value.instance_eval(&block) if block
|
209
|
+
value
|
210
|
+
end
|
211
|
+
|
212
|
+
def set_value(field_name,val,opts={})
|
213
|
+
if prefix = opts[:prefix]; field_name = "#{prefix}#{field_name}"; end
|
214
|
+
if suffix = opts[:suffix]; field_name = "#{field_name}#{suffix}"; end
|
215
|
+
self[field_name] = format_value(val,opts)
|
216
|
+
end
|
217
|
+
|
218
|
+
def default_formats
|
219
|
+
HashWithIndifferentAccess.new(
|
220
|
+
:default=>lambda {|v,f,opts| v.respond_to?(:strftime) ? v.strftime(f) : f % v } ,
|
221
|
+
:float =>lambda {|v,f,opts| precision_format(opts) % v },
|
222
|
+
:dollars=>lambda {|v,f,opts| "$#{precision_format(opts,2)}" % v},
|
223
|
+
:percent=>lambda {|v,f,opts| "#{precision_format(opts,1)}%%" % v},
|
224
|
+
:yes_no=>lambda {|v,f,opts| v ? "Yes" : "No"}
|
225
|
+
)
|
226
|
+
end
|
227
|
+
|
228
|
+
def precision_format(opts,default_precision=nil)
|
229
|
+
precision = opts[:precision] || default_precision
|
230
|
+
"%#{precision ? "." + precision.to_s : default_precision}f"
|
231
|
+
end
|
232
|
+
|
233
|
+
def add_options(args,new_options)
|
234
|
+
opts = args.length > 1 ? args.extract_options! : {}
|
235
|
+
opts.merge!(new_options)
|
236
|
+
args << opts
|
237
|
+
args
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
@@ -1,33 +1,33 @@
|
|
1
|
-
module Wonkavision
|
2
|
-
module Persistence
|
3
|
-
module MongoMapperAdapter
|
4
|
-
|
5
|
-
def self.included(model)
|
6
|
-
model.plugin Wonkavision::Persistence::MongoMapperAdapter
|
7
|
-
end
|
8
|
-
|
9
|
-
module ClassMethods
|
10
|
-
include Wonkavision::ActsAsOompaLoompa
|
11
|
-
|
12
|
-
def define_document_key(key_name,key_type,options={})
|
13
|
-
key(key_name, key_type, options) unless keys[key_name]
|
14
|
-
end
|
15
|
-
|
16
|
-
def update_activity(activity,event_data)
|
17
|
-
activity.assign(event_data)
|
18
|
-
:updated
|
19
|
-
end
|
20
|
-
|
21
|
-
def find_activity_instance(correlation_field_name,correlation_id)
|
22
|
-
self.send("find_or_create_by_#{correlation_field_name}",correlation_id)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
if defined?(::MongoMapper::Document)
|
32
|
-
MongoMapper::Document.append_inclusions(Wonkavision::Persistence::MongoMapperAdapter)
|
1
|
+
module Wonkavision
|
2
|
+
module Persistence
|
3
|
+
module MongoMapperAdapter
|
4
|
+
|
5
|
+
def self.included(model)
|
6
|
+
model.plugin Wonkavision::Persistence::MongoMapperAdapter
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
include Wonkavision::ActsAsOompaLoompa
|
11
|
+
|
12
|
+
def define_document_key(key_name,key_type,options={})
|
13
|
+
key(key_name, key_type, options) unless keys[key_name]
|
14
|
+
end
|
15
|
+
|
16
|
+
def update_activity(activity,event_data)
|
17
|
+
activity.assign(event_data)
|
18
|
+
:updated
|
19
|
+
end
|
20
|
+
|
21
|
+
def find_activity_instance(correlation_field_name,correlation_id)
|
22
|
+
self.send("find_or_create_by_#{correlation_field_name}",correlation_id)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
if defined?(::MongoMapper::Document)
|
32
|
+
MongoMapper::Document.append_inclusions(Wonkavision::Persistence::MongoMapperAdapter)
|
33
33
|
end
|