rbbt-util 5.44.1 → 6.0.4

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.
Files changed (175) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/bin/rbbt +67 -90
  4. data/bin/rbbt_exec.rb +2 -2
  5. data/etc/app.d/base.rb +2 -2
  6. data/etc/app.d/semaphores.rb +3 -3
  7. data/lib/rbbt/annotations/annotated_array.rb +207 -207
  8. data/lib/rbbt/annotations/refactor.rb +27 -0
  9. data/lib/rbbt/annotations/util.rb +282 -282
  10. data/lib/rbbt/annotations.rb +343 -320
  11. data/lib/rbbt/association/database.rb +200 -225
  12. data/lib/rbbt/association/index.rb +294 -291
  13. data/lib/rbbt/association/item.rb +227 -227
  14. data/lib/rbbt/association/open.rb +35 -34
  15. data/lib/rbbt/association/util.rb +0 -169
  16. data/lib/rbbt/association.rb +2 -4
  17. data/lib/rbbt/entity/identifiers.rb +119 -118
  18. data/lib/rbbt/entity/refactor.rb +12 -0
  19. data/lib/rbbt/entity.rb +319 -315
  20. data/lib/rbbt/hpc/batch.rb +72 -53
  21. data/lib/rbbt/hpc/lsf.rb +2 -2
  22. data/lib/rbbt/hpc/orchestrate/batches.rb +2 -2
  23. data/lib/rbbt/hpc/orchestrate/chains.rb +25 -5
  24. data/lib/rbbt/hpc/orchestrate/rules.rb +2 -2
  25. data/lib/rbbt/hpc/orchestrate.rb +19 -13
  26. data/lib/rbbt/hpc/slurm.rb +18 -18
  27. data/lib/rbbt/knowledge_base/entity.rb +13 -5
  28. data/lib/rbbt/knowledge_base/query.rb +2 -2
  29. data/lib/rbbt/knowledge_base/registry.rb +32 -31
  30. data/lib/rbbt/knowledge_base/traverse.rb +1 -1
  31. data/lib/rbbt/knowledge_base.rb +1 -1
  32. data/lib/rbbt/monitor.rb +36 -25
  33. data/lib/rbbt/persist/refactor.rb +166 -0
  34. data/lib/rbbt/persist/tsv/tokyocabinet.rb +105 -105
  35. data/lib/rbbt/persist/tsv.rb +187 -185
  36. data/lib/rbbt/persist.rb +556 -551
  37. data/lib/rbbt/refactor.rb +20 -0
  38. data/lib/rbbt/resource/path/refactor.rb +178 -0
  39. data/lib/rbbt/resource/path.rb +317 -497
  40. data/lib/rbbt/resource/util.rb +0 -48
  41. data/lib/rbbt/resource.rb +3 -390
  42. data/lib/rbbt/tsv/accessor.rb +2 -838
  43. data/lib/rbbt/tsv/attach.rb +303 -299
  44. data/lib/rbbt/tsv/change_id.rb +244 -245
  45. data/lib/rbbt/tsv/csv.rb +87 -85
  46. data/lib/rbbt/tsv/dumper.rb +2 -100
  47. data/lib/rbbt/tsv/excel.rb +26 -24
  48. data/lib/rbbt/tsv/field_index.rb +4 -1
  49. data/lib/rbbt/tsv/filter.rb +3 -2
  50. data/lib/rbbt/tsv/index.rb +2 -284
  51. data/lib/rbbt/tsv/manipulate.rb +750 -747
  52. data/lib/rbbt/tsv/marshal.rb +3 -3
  53. data/lib/rbbt/tsv/matrix.rb +2 -2
  54. data/lib/rbbt/tsv/parallel/through.rb +2 -1
  55. data/lib/rbbt/tsv/parallel/traverse.rb +783 -781
  56. data/lib/rbbt/tsv/parser.rb +678 -678
  57. data/lib/rbbt/tsv/refactor.rb +195 -0
  58. data/lib/rbbt/tsv/stream.rb +253 -251
  59. data/lib/rbbt/tsv/util.rb +420 -420
  60. data/lib/rbbt/tsv.rb +210 -208
  61. data/lib/rbbt/util/R/eval.rb +4 -4
  62. data/lib/rbbt/util/R/plot.rb +62 -166
  63. data/lib/rbbt/util/R.rb +21 -18
  64. data/lib/rbbt/util/cmd.rb +2 -318
  65. data/lib/rbbt/util/color.rb +269 -269
  66. data/lib/rbbt/util/colorize.rb +89 -89
  67. data/lib/rbbt/util/concurrency/processes/refactor.rb +22 -0
  68. data/lib/rbbt/util/concurrency/processes/worker.rb +2 -2
  69. data/lib/rbbt/util/concurrency/processes.rb +389 -386
  70. data/lib/rbbt/util/config.rb +169 -167
  71. data/lib/rbbt/util/filecache.rb +1 -1
  72. data/lib/rbbt/util/iruby.rb +20 -0
  73. data/lib/rbbt/util/log/progress/report.rb +241 -241
  74. data/lib/rbbt/util/log/progress/util.rb +99 -99
  75. data/lib/rbbt/util/log/progress.rb +102 -102
  76. data/lib/rbbt/util/log/refactor.rb +49 -0
  77. data/lib/rbbt/util/log.rb +486 -532
  78. data/lib/rbbt/util/migrate.rb +2 -2
  79. data/lib/rbbt/util/misc/concurrent_stream.rb +248 -246
  80. data/lib/rbbt/util/misc/development.rb +12 -11
  81. data/lib/rbbt/util/misc/exceptions.rb +117 -112
  82. data/lib/rbbt/util/misc/format.rb +2 -230
  83. data/lib/rbbt/util/misc/indiferent_hash.rb +2 -107
  84. data/lib/rbbt/util/misc/inspect.rb +2 -476
  85. data/lib/rbbt/util/misc/lock.rb +109 -106
  86. data/lib/rbbt/util/misc/omics.rb +9 -1
  87. data/lib/rbbt/util/misc/pipes.rb +765 -793
  88. data/lib/rbbt/util/misc/refactor.rb +20 -0
  89. data/lib/rbbt/util/misc/ssw.rb +27 -17
  90. data/lib/rbbt/util/misc/system.rb +92 -105
  91. data/lib/rbbt/util/misc.rb +39 -20
  92. data/lib/rbbt/util/named_array/refactor.rb +4 -0
  93. data/lib/rbbt/util/named_array.rb +3 -220
  94. data/lib/rbbt/util/open/refactor.rb +7 -0
  95. data/lib/rbbt/util/open.rb +3 -857
  96. data/lib/rbbt/util/procpath.rb +6 -6
  97. data/lib/rbbt/util/python/paths.rb +27 -0
  98. data/lib/rbbt/util/python/run.rb +115 -0
  99. data/lib/rbbt/util/python/script.rb +110 -0
  100. data/lib/rbbt/util/python/util.rb +3 -3
  101. data/lib/rbbt/util/python.rb +22 -81
  102. data/lib/rbbt/util/semaphore.rb +152 -148
  103. data/lib/rbbt/util/simpleopt.rb +9 -8
  104. data/lib/rbbt/util/ssh/refactor.rb +19 -0
  105. data/lib/rbbt/util/ssh.rb +122 -118
  106. data/lib/rbbt/util/tar.rb +117 -115
  107. data/lib/rbbt/util/tmpfile.rb +69 -67
  108. data/lib/rbbt/util/version.rb +2 -0
  109. data/lib/rbbt/workflow/refactor/entity.rb +11 -0
  110. data/lib/rbbt/workflow/refactor/export.rb +66 -0
  111. data/lib/rbbt/workflow/refactor/inputs.rb +24 -0
  112. data/lib/rbbt/workflow/refactor/recursive.rb +64 -0
  113. data/lib/rbbt/workflow/refactor/task_info.rb +66 -0
  114. data/lib/rbbt/workflow/refactor.rb +150 -0
  115. data/lib/rbbt/workflow/remote_workflow/driver/rest.rb +1 -2
  116. data/lib/rbbt/workflow/remote_workflow/driver/ssh.rb +55 -32
  117. data/lib/rbbt/workflow/remote_workflow/remote_step/rest.rb +3 -1
  118. data/lib/rbbt/workflow/remote_workflow/remote_step/ssh.rb +14 -5
  119. data/lib/rbbt/workflow/remote_workflow/remote_step.rb +19 -7
  120. data/lib/rbbt/workflow/remote_workflow.rb +6 -1
  121. data/lib/rbbt/workflow/step/run.rb +766 -766
  122. data/lib/rbbt/workflow/step/save_load_inputs.rb +254 -254
  123. data/lib/rbbt/workflow/step.rb +2 -362
  124. data/lib/rbbt/workflow/task.rb +118 -118
  125. data/lib/rbbt/workflow/usage.rb +289 -287
  126. data/lib/rbbt/workflow/util/archive.rb +6 -5
  127. data/lib/rbbt/workflow/util/data.rb +1 -1
  128. data/lib/rbbt/workflow/util/orchestrator.rb +249 -246
  129. data/lib/rbbt/workflow/util/trace.rb +79 -44
  130. data/lib/rbbt/workflow.rb +4 -882
  131. data/lib/rbbt-util.rb +21 -13
  132. data/lib/rbbt.rb +16 -3
  133. data/python/rbbt/__init__.py +96 -4
  134. data/python/rbbt/workflow/remote.py +104 -0
  135. data/python/rbbt/workflow.py +64 -0
  136. data/python/test.py +10 -0
  137. data/share/Rlib/plot.R +37 -37
  138. data/share/Rlib/svg.R +22 -5
  139. data/share/install/software/lib/install_helpers +1 -1
  140. data/share/rbbt_commands/hpc/list +2 -3
  141. data/share/rbbt_commands/hpc/orchestrate +4 -4
  142. data/share/rbbt_commands/hpc/tail +2 -0
  143. data/share/rbbt_commands/hpc/task +10 -7
  144. data/share/rbbt_commands/lsf/list +2 -3
  145. data/share/rbbt_commands/lsf/orchestrate +4 -4
  146. data/share/rbbt_commands/lsf/tail +2 -0
  147. data/share/rbbt_commands/lsf/task +10 -7
  148. data/share/rbbt_commands/migrate +1 -1
  149. data/share/rbbt_commands/pbs/list +2 -3
  150. data/share/rbbt_commands/pbs/orchestrate +4 -4
  151. data/share/rbbt_commands/pbs/tail +2 -0
  152. data/share/rbbt_commands/pbs/task +10 -7
  153. data/share/rbbt_commands/resource/produce +8 -1
  154. data/share/rbbt_commands/slurm/list +2 -3
  155. data/share/rbbt_commands/slurm/orchestrate +4 -4
  156. data/share/rbbt_commands/slurm/tail +2 -0
  157. data/share/rbbt_commands/slurm/task +10 -7
  158. data/share/rbbt_commands/system/clean +5 -5
  159. data/share/rbbt_commands/system/status +5 -5
  160. data/share/rbbt_commands/tsv/get +2 -3
  161. data/share/rbbt_commands/tsv/info +10 -13
  162. data/share/rbbt_commands/tsv/keys +18 -14
  163. data/share/rbbt_commands/tsv/slice +2 -2
  164. data/share/rbbt_commands/tsv/transpose +6 -2
  165. data/share/rbbt_commands/workflow/info +20 -24
  166. data/share/rbbt_commands/workflow/list +1 -1
  167. data/share/rbbt_commands/workflow/prov +20 -13
  168. data/share/rbbt_commands/workflow/retry +43 -0
  169. data/share/rbbt_commands/workflow/server +12 -2
  170. data/share/rbbt_commands/workflow/task +80 -73
  171. data/share/rbbt_commands/workflow/write_info +26 -9
  172. data/share/software/opt/ssw/ssw.c +861 -0
  173. data/share/software/opt/ssw/ssw.h +130 -0
  174. data/share/workflow_config.ru +3 -3
  175. metadata +45 -6
data/lib/rbbt/entity.rb CHANGED
@@ -1,315 +1,319 @@
1
- require 'rbbt/annotations'
2
- require 'rbbt/entity/identifiers'
3
-
4
- module Entity
5
-
6
- UNPERSISTED_PREFIX = "entity_unpersisted_property_"
7
-
8
- class MultipleEntity < TryAgain; end
9
-
10
- class DontPersist < Exception
11
- attr_accessor :payload
12
- def self.initialize(payload)
13
- @payload = payload
14
- end
15
- end
16
-
17
- class << self
18
- attr_accessor :formats, :entity_property_cache
19
- end
20
- FORMATS = begin
21
- hash = {}
22
- class << hash
23
- alias orig_include? include?
24
-
25
- attr_accessor :find_cache
26
-
27
- def find(value)
28
- self.find_cache ||= {}
29
- if self.find_cache.include? value
30
- self.find_cache[value]
31
- else
32
- self.find_cache[value] = begin
33
- if orig_include? value
34
- self.find_cache[value] = value
35
- else
36
- found = nil
37
- each do |k,v|
38
- if value.to_s == k.to_s
39
- found = k
40
- break
41
- elsif value.to_s =~ /\(#{Regexp.quote k}\)/
42
- found = k
43
- break
44
- end
45
- end
46
- found
47
- end
48
- end
49
- end
50
- end
51
-
52
- def [](value)
53
- res = super
54
- return res if res
55
- key = find(value)
56
- key ? super(key) : nil
57
- end
58
-
59
- def []=(key,value)
60
- self.find_cache = nil
61
- super
62
- end
63
-
64
- def include?(value)
65
- find(value) != nil
66
- end
67
- end
68
-
69
- hash
70
- end
71
-
72
- def self.formats
73
- FORMATS
74
- end
75
-
76
- dir = (defined?(Rbbt)? Rbbt.var.entity_property : 'var/entity_property')
77
- self.entity_property_cache = dir
78
-
79
- def self.entity_property_cache=(dir)
80
- @entity_property_cache = dir
81
- end
82
-
83
- attr_accessor :all_formats, :all_properties
84
- def self.extended(base)
85
- base.extend Annotation
86
- Entity.formats[base.to_s] = base
87
-
88
- base.module_eval do
89
- attr_accessor :_ary_property_cache
90
-
91
- attr_accessor :template, :list_template, :action_template, :list_action_template, :keep_id
92
-
93
- def self.format=(formats)
94
- formats = [formats] unless Array === formats
95
- self.all_formats ||= []
96
- self.all_formats = self.all_formats.concat(formats).uniq
97
- formats.each do |format|
98
- Entity.formats[format] ||= self
99
- end
100
- end
101
-
102
- def _ary_property_cache
103
- @_ary_property_cache ||= {}
104
- end
105
-
106
- def base_entity
107
- self.annotation_types.select{|m| Entity === m}.last
108
- end
109
-
110
- def property(*args, &block)
111
- class << self; self; end.property(*args,&block)
112
- end
113
-
114
- def to_yaml(*args)
115
- self.clean_annotations.dup.to_yaml(*args)
116
- end
117
-
118
-
119
- def encode_with(coder)
120
- coder.scalar = clean_annotations
121
- end
122
-
123
- def consolidate
124
- self.inject(nil){|acc,e|
125
- if acc.nil?
126
- acc = e
127
- else
128
- acc.concat e
129
- end
130
- }
131
- end
132
-
133
- def all_properties
134
- annotation_types.select{|m| Entity === m}.collect{|e| e.all_properties}.flatten.uniq
135
- end
136
-
137
- def self.property(name, &block)
138
- Log.debug "Defining property #{name} for #{self}"
139
-
140
- case
141
- when (Hash === name and name.size == 1)
142
- name, type = name.collect.first
143
- when (String === name or Symbol === name)
144
- type = :single
145
- else
146
- raise "Format of name ( => type) not understood: #{name.inspect}"
147
- end
148
-
149
- name = name.to_s unless String === name
150
-
151
- persisted_name = UNPERSISTED_PREFIX + name
152
- self.remove_method persisted_name if methods.include? persisted_name
153
-
154
- case type
155
- when :both
156
- define_method name, &block
157
-
158
- when :single, :single2array
159
- single_name = "_single_" << name
160
- define_method single_name, &block
161
- define_method name do |*args, &block|
162
- if Array === self
163
- res = self.collect{|e| e.send(single_name, *args)}
164
- res.first.annotate(res) if Annotated === res.first && type == :single2array
165
- res
166
- else
167
- self.send(single_name, *args, &block)
168
- end
169
- end
170
- when :array, :array2single
171
- ary_name = "_ary_" << name
172
- define_method ary_name, &block
173
-
174
- define_method name do |*args, &block|
175
- case
176
- when Array === self
177
- self.send(ary_name, *args, &block)
178
- when (Array === self.container and not self.container_index.nil? and self.container.respond_to? ary_name)
179
- cache_code = Misc.hash2md5({:name => ary_name, :args => args})
180
- res = (self.container._ary_property_cache[cache_code] ||= self.container.send(name, *args))
181
- if Hash === res
182
- res[self]
183
- else
184
- res[self.container_index]
185
- end
186
- else
187
- res = self.make_list.send(ary_name, *args, &block)
188
- Hash === res ? res[self] : res[0]
189
- end
190
- end
191
- when :multiple
192
- multi_name = "_multiple_" << name
193
-
194
- define_method multi_name do
195
- if self.instance_variable_get("@multiple_result_" + name.to_s)
196
- return self.instance_variable_get("@multiple_result_" + name.to_s)
197
- end
198
- raise MultipleEntity, "Entity property #{name} runs with multiple entities"
199
- end
200
-
201
- define_method name do |*args|
202
-
203
- if self.instance_variable_get("@multiple_result_" + name.to_s)
204
- return self.instance_variable_get("@multiple_result_" + name.to_s)
205
- end
206
-
207
- obj = if Array === self
208
- self
209
- elsif self.respond_to?(:container) && Array === self.container
210
- self.container
211
- else
212
- self.make_list
213
- end
214
-
215
- missing = []
216
- obj.each do |e|
217
- begin
218
- res = e.send(multi_name)
219
- e.instance_variable_set("@multiple_result_" + name.to_s, res)
220
- rescue MultipleEntity
221
- missing << e
222
- end
223
- end
224
-
225
- res = missing.any? ? block.call(missing) : nil
226
- case res
227
- when Array
228
- missing.zip(res).each do |o,res|
229
- raise "Multiple function '#{name}' result 'nil' for element '#{o}'" if res.nil?
230
- o.instance_variable_set("@multiple_result_" + name.to_s, res)
231
- o.send(multi_name)
232
- end
233
- when Hash
234
- res.each do |o,res|
235
- raise "Multiple function '#{name}' result 'nil' for element '#{o}'" if res.nil?
236
- o.instance_variable_set("@multiple_result_" + name.to_s, res)
237
- o.send(multi_name)
238
- end
239
- end
240
-
241
- if Array === self
242
- res = self.collect{|o| o.send(multi_name)}
243
- self.instance_variable_set("@multiple_result_" + name.to_s, res)
244
- res
245
- else
246
- res = self.send(multi_name)
247
- self.instance_variable_set("@multiple_result_" + name.to_s, res)
248
- res
249
- end
250
- end
251
-
252
- else
253
- raise "Type not undestood in property: #{ type }"
254
- end
255
- @all_properties ||= []
256
- @all_properties << name
257
- end
258
-
259
- def self.persist(method_name, type = nil, options = {})
260
- type = :memory if type.nil?
261
- options ||= {}
262
- options = Misc.add_defaults options, :dir => File.join(Entity.entity_property_cache, self.to_s, method_name.to_s)
263
-
264
- orig_method_name = method_name
265
- multi_name = "_multiple_" + method_name.to_s
266
- single_name = "_single_" + method_name.to_s
267
-
268
- method_name = multi_name if self.instance_methods.include?(multi_name.to_sym)
269
- method_name = single_name if self.instance_methods.include?(single_name.to_sym)
270
-
271
- orig_name = UNPERSISTED_PREFIX + method_name.to_s
272
- alias_method orig_name, method_name unless self.instance_methods.include? orig_name.to_sym
273
-
274
- define_method method_name do |*args|
275
- id = self.id
276
- persist_name = orig_method_name.to_s + ":" << (Array === id ? Misc.obj2digest(id) : id)
277
-
278
- persist_options = options
279
- persist_options = persist_options.merge(:other => {:args => args}) if args and args.any?
280
-
281
- begin
282
- Persist.persist(persist_name, type, persist_options.merge(:persist => true)) do
283
- self.send(orig_name, *args)
284
- end
285
- rescue DontPersist
286
- $!.payload
287
- end
288
- end
289
- end
290
-
291
- def self.unpersist(method_name)
292
- return unless orig_name = persisted?(method_name)
293
- alias_method method_name, orig_name
294
- remove_method orig_name
295
- end
296
-
297
- def self.persisted?(method_name)
298
- ["", "_multiple_", "_single_"].each do |type|
299
- orig_name = (UNPERSISTED_PREFIX + type + method_name.to_s).to_sym
300
- return orig_name if instance_methods.include?(orig_name)
301
- end
302
- return false
303
- end
304
-
305
- def self.with_persisted(method_name)
306
- persisted = persisted? method_name
307
- persist method_name unless persisted
308
- res = yield
309
- unpersist method_name unless persisted
310
- res
311
- end
312
-
313
- end
314
- end
315
- end
1
+ require_relative 'refactor'
2
+ Rbbt.require_instead 'scout/entity'
3
+ require_relative 'entity/refactor'
4
+ #require_relative 'persist'
5
+ #require_relative 'entity/identifiers'
6
+ #
7
+ #module Entity
8
+ #
9
+ # UNPERSISTED_PREFIX = "entity_unpersisted_property_"
10
+ #
11
+ # class MultipleEntity < TryAgain; end
12
+ #
13
+ # class DontPersist < Exception
14
+ # attr_accessor :payload
15
+ # def self.initialize(payload)
16
+ # @payload = payload
17
+ # end
18
+ # end
19
+ #
20
+ # class << self
21
+ # attr_accessor :formats, :entity_property_cache
22
+ # end
23
+ # FORMATS = begin
24
+ # hash = {}
25
+ # class << hash
26
+ # alias orig_include? include?
27
+ #
28
+ # attr_accessor :find_cache
29
+ #
30
+ # def find(value)
31
+ # self.find_cache ||= {}
32
+ # if self.find_cache.include? value
33
+ # self.find_cache[value]
34
+ # else
35
+ # self.find_cache[value] = begin
36
+ # if orig_include? value
37
+ # self.find_cache[value] = value
38
+ # else
39
+ # found = nil
40
+ # each do |k,v|
41
+ # if value.to_s == k.to_s
42
+ # found = k
43
+ # break
44
+ # elsif value.to_s =~ /\(#{Regexp.quote k}\)/
45
+ # found = k
46
+ # break
47
+ # end
48
+ # end
49
+ # found
50
+ # end
51
+ # end
52
+ # end
53
+ # end
54
+ #
55
+ # def [](value)
56
+ # res = super
57
+ # return res if res
58
+ # key = find(value)
59
+ # key ? super(key) : nil
60
+ # end
61
+ #
62
+ # def []=(key,value)
63
+ # self.find_cache = nil
64
+ # super
65
+ # end
66
+ #
67
+ # def include?(value)
68
+ # find(value) != nil
69
+ # end
70
+ # end
71
+ #
72
+ # hash
73
+ # end
74
+ #
75
+ # def self.formats
76
+ # FORMATS
77
+ # end
78
+ #
79
+ # dir = (defined?(Rbbt) && defined?(Resource) && Resource === Rbbt ? Rbbt.var.entity_property : 'var/entity_property')
80
+ # self.entity_property_cache = dir
81
+ #
82
+ # def self.entity_property_cache=(dir)
83
+ # @entity_property_cache = dir
84
+ # end
85
+ #
86
+ # attr_accessor :all_formats, :all_properties
87
+ # def self.extended(base)
88
+ # base.extend Annotation
89
+ # base.include ExtendedArray
90
+ # Entity.formats[base.to_s] = base
91
+ #
92
+ # base.module_eval do
93
+ # attr_accessor :_ary_property_cache
94
+ #
95
+ # attr_accessor :template, :list_template, :action_template, :list_action_template, :keep_id
96
+ #
97
+ # def self.format=(formats)
98
+ # formats = [formats] unless Array === formats
99
+ # self.all_formats ||= []
100
+ # self.all_formats = self.all_formats.concat(formats).uniq
101
+ # formats.each do |format|
102
+ # Entity.formats[format] ||= self
103
+ # end
104
+ # end
105
+ #
106
+ # def _ary_property_cache
107
+ # @_ary_property_cache ||= {}
108
+ # end
109
+ #
110
+ # def base_entity
111
+ # self.annotation_types.select{|m| Entity === m}.last
112
+ # end
113
+ #
114
+ # def property(*args, &block)
115
+ # class << self; self; end.property(*args,&block)
116
+ # end
117
+ #
118
+ # def to_yaml(*args)
119
+ # self.clean_annotations.dup.to_yaml(*args)
120
+ # end
121
+ #
122
+ #
123
+ # def encode_with(coder)
124
+ # coder.scalar = clean_annotations
125
+ # end
126
+ #
127
+ # def consolidate
128
+ # self.inject(nil){|acc,e|
129
+ # if acc.nil?
130
+ # acc = e
131
+ # else
132
+ # acc.concat e
133
+ # end
134
+ # }
135
+ # end
136
+ #
137
+ # def all_properties
138
+ # annotation_types.select{|m| Entity === m}.collect{|e| e.all_properties}.flatten.uniq
139
+ # end
140
+ #
141
+ # def self.property(name, &block)
142
+ # Log.debug "Defining property #{name} for #{self}"
143
+ #
144
+ # case
145
+ # when (Hash === name and name.size == 1)
146
+ # name, type = name.collect.first
147
+ # when (String === name or Symbol === name)
148
+ # type = :single
149
+ # else
150
+ # raise "Format of name ( => type) not understood: #{name.inspect}"
151
+ # end
152
+ #
153
+ # name = name.to_s unless String === name
154
+ #
155
+ # persisted_name = UNPERSISTED_PREFIX + name
156
+ # self.remove_method persisted_name if methods.include? persisted_name
157
+ #
158
+ # case type
159
+ # when :both
160
+ # define_method name, &block
161
+ #
162
+ # when :single, :single2array
163
+ # single_name = "_single_" << name
164
+ # define_method single_name, &block
165
+ # define_method name do |*args, &block|
166
+ # if Array === self
167
+ # res = self.collect{|e| e.send(single_name, *args)}
168
+ # res.first.annotate(res) if Annotated === res.first && type == :single2array
169
+ # res
170
+ # else
171
+ # self.send(single_name, *args, &block)
172
+ # end
173
+ # end
174
+ # when :array, :array2single
175
+ # ary_name = "_ary_" << name
176
+ # define_method ary_name, &block
177
+ #
178
+ # define_method name do |*args, &block|
179
+ # case
180
+ # when Array === self
181
+ # self.send(ary_name, *args, &block)
182
+ # when (ExtendedArray::ExtendedArrayItem === self && Array === self.container and not self.container_index.nil? and self.container.respond_to? ary_name)
183
+ # cache_code = Misc.digest({:name => ary_name, :args => args})
184
+ # res = (self.container._ary_property_cache[cache_code] ||= self.container.send(name, *args))
185
+ # if Hash === res
186
+ # res[self]
187
+ # else
188
+ # res[self.container_index]
189
+ # end
190
+ # else
191
+ # res = self.make_list.send(ary_name, *args, &block)
192
+ # Hash === res ? res[self] : res[0]
193
+ # end
194
+ # end
195
+ # when :multiple
196
+ # multi_name = "_multiple_" << name
197
+ #
198
+ # define_method multi_name do
199
+ # if self.instance_variable_get("@multiple_result_" + name.to_s)
200
+ # return self.instance_variable_get("@multiple_result_" + name.to_s)
201
+ # end
202
+ # raise MultipleEntity, "Entity property #{name} runs with multiple entities"
203
+ # end
204
+ #
205
+ # define_method name do |*args|
206
+ #
207
+ # if self.instance_variable_get("@multiple_result_" + name.to_s)
208
+ # return self.instance_variable_get("@multiple_result_" + name.to_s)
209
+ # end
210
+ #
211
+ # obj = if Array === self
212
+ # self
213
+ # elsif self.respond_to?(:container) && Array === self.container
214
+ # self.container
215
+ # else
216
+ # self.make_list
217
+ # end
218
+ #
219
+ # missing = []
220
+ # obj.each do |e|
221
+ # begin
222
+ # res = e.send(multi_name)
223
+ # e.instance_variable_set("@multiple_result_" + name.to_s, res)
224
+ # rescue MultipleEntity
225
+ # missing << e
226
+ # end
227
+ # end
228
+ #
229
+ # res = missing.any? ? block.call(missing) : nil
230
+ # case res
231
+ # when Array
232
+ # missing.zip(res).each do |o,res|
233
+ # raise "Multiple function '#{name}' result 'nil' for element '#{o}'" if res.nil?
234
+ # o.instance_variable_set("@multiple_result_" + name.to_s, res)
235
+ # o.send(multi_name)
236
+ # end
237
+ # when Hash
238
+ # res.each do |o,res|
239
+ # raise "Multiple function '#{name}' result 'nil' for element '#{o}'" if res.nil?
240
+ # o.instance_variable_set("@multiple_result_" + name.to_s, res)
241
+ # o.send(multi_name)
242
+ # end
243
+ # end
244
+ #
245
+ # if Array === self
246
+ # res = self.collect{|o| o.send(multi_name)}
247
+ # self.instance_variable_set("@multiple_result_" + name.to_s, res)
248
+ # res
249
+ # else
250
+ # res = self.send(multi_name)
251
+ # self.instance_variable_set("@multiple_result_" + name.to_s, res)
252
+ # res
253
+ # end
254
+ # end
255
+ #
256
+ # else
257
+ # raise "Type not undestood in property: #{ type }"
258
+ # end
259
+ # @all_properties ||= []
260
+ # @all_properties << name
261
+ # end
262
+ #
263
+ # def self.persist(method_name, type = nil, options = {})
264
+ # type = :memory if type.nil?
265
+ # options ||= {}
266
+ # options = IndiferentHash.add_defaults options, :dir => File.join(Entity.entity_property_cache, self.to_s, method_name.to_s)
267
+ #
268
+ # orig_method_name = method_name
269
+ # multi_name = "_multiple_" + method_name.to_s
270
+ # single_name = "_single_" + method_name.to_s
271
+ #
272
+ # method_name = multi_name if self.instance_methods.include?(multi_name.to_sym)
273
+ # method_name = single_name if self.instance_methods.include?(single_name.to_sym)
274
+ #
275
+ # orig_name = UNPERSISTED_PREFIX + method_name.to_s
276
+ # alias_method orig_name, method_name unless self.instance_methods.include? orig_name.to_sym
277
+ #
278
+ # define_method method_name do |*args|
279
+ # id = self.id
280
+ # persist_name = orig_method_name.to_s + ":" << (Array === id ? Misc.digest(id) : id)
281
+ #
282
+ # persist_options = options
283
+ # persist_options = persist_options.merge(:other => {:args => args}) if args and args.any?
284
+ #
285
+ # begin
286
+ # Persist.persist(persist_name, type, persist_options.merge(:persist => true)) do
287
+ # self.send(orig_name, *args)
288
+ # end
289
+ # rescue DontPersist
290
+ # $!.payload
291
+ # end
292
+ # end
293
+ # end
294
+ #
295
+ # def self.unpersist(method_name)
296
+ # return unless orig_name = persisted?(method_name)
297
+ # alias_method method_name, orig_name
298
+ # remove_method orig_name
299
+ # end
300
+ #
301
+ # def self.persisted?(method_name)
302
+ # ["", "_multiple_", "_single_"].each do |type|
303
+ # orig_name = (UNPERSISTED_PREFIX + type + method_name.to_s).to_sym
304
+ # return orig_name if instance_methods.include?(orig_name)
305
+ # end
306
+ # return false
307
+ # end
308
+ #
309
+ # def self.with_persisted(method_name)
310
+ # persisted = persisted? method_name
311
+ # persist method_name unless persisted
312
+ # res = yield
313
+ # unpersist method_name unless persisted
314
+ # res
315
+ # end
316
+ #
317
+ # end
318
+ # end
319
+ #end