flor 0.18.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +3 -0
  3. data/CREDITS.md +1 -0
  4. data/LICENSE.txt +1 -1
  5. data/Makefile +1 -1
  6. data/README.md +15 -1
  7. data/flor.gemspec +1 -2
  8. data/lib/flor.rb +2 -2
  9. data/lib/flor/colours.rb +5 -3
  10. data/lib/flor/conf.rb +1 -0
  11. data/lib/flor/core.rb +9 -8
  12. data/lib/flor/core/executor.rb +20 -16
  13. data/lib/flor/core/node.rb +1 -13
  14. data/lib/flor/core/procedure.rb +10 -1
  15. data/lib/flor/core/texecutor.rb +9 -2
  16. data/lib/flor/djan.rb +1 -0
  17. data/lib/flor/errors.rb +1 -0
  18. data/lib/flor/flor.rb +144 -15
  19. data/lib/flor/id.rb +1 -0
  20. data/lib/flor/log.rb +2 -1
  21. data/lib/flor/migrations/0001_tables.rb +1 -0
  22. data/lib/flor/migrations/0002_cunit_and_munit.rb +1 -0
  23. data/lib/flor/migrations/0003_timer_onid_bnid.rb +1 -0
  24. data/lib/flor/migrations/0004_trap_bnid.rb +1 -0
  25. data/lib/flor/migrations/0005_pointer_content.rb +1 -0
  26. data/lib/flor/parser.rb +19 -11
  27. data/lib/flor/pcore/_apply.rb +1 -0
  28. data/lib/flor/pcore/_arr.rb +1 -0
  29. data/lib/flor/pcore/_atom.rb +1 -0
  30. data/lib/flor/pcore/_att.rb +1 -0
  31. data/lib/flor/pcore/_coll.rb +1 -0
  32. data/lib/flor/pcore/_dmute.rb +1 -0
  33. data/lib/flor/pcore/_dol.rb +1 -0
  34. data/lib/flor/pcore/_dqs.rb +1 -0
  35. data/lib/flor/pcore/_dump.rb +1 -0
  36. data/lib/flor/pcore/_err.rb +1 -0
  37. data/lib/flor/pcore/_head.rb +1 -0
  38. data/lib/flor/pcore/_obj.rb +1 -0
  39. data/lib/flor/pcore/_pat_.rb +1 -0
  40. data/lib/flor/pcore/_pat_arr.rb +1 -0
  41. data/lib/flor/pcore/_pat_guard.rb +1 -0
  42. data/lib/flor/pcore/_pat_obj.rb +1 -0
  43. data/lib/flor/pcore/_pat_or.rb +1 -0
  44. data/lib/flor/pcore/_pat_regex.rb +1 -0
  45. data/lib/flor/pcore/_ref.rb +1 -0
  46. data/lib/flor/pcore/_rxs.rb +1 -0
  47. data/lib/flor/pcore/_skip.rb +1 -0
  48. data/lib/flor/pcore/_val.rb +1 -0
  49. data/lib/flor/pcore/all.rb +1 -0
  50. data/lib/flor/pcore/andor.rb +1 -0
  51. data/lib/flor/pcore/any.rb +1 -0
  52. data/lib/flor/pcore/apply.rb +1 -0
  53. data/lib/flor/pcore/arith.rb +1 -0
  54. data/lib/flor/pcore/array_qmark.rb +1 -0
  55. data/lib/flor/pcore/break.rb +1 -0
  56. data/lib/flor/pcore/case.rb +1 -0
  57. data/lib/flor/pcore/cmp.rb +1 -0
  58. data/lib/flor/pcore/collect.rb +2 -1
  59. data/lib/flor/pcore/cond.rb +1 -0
  60. data/lib/flor/pcore/cursor.rb +45 -3
  61. data/lib/flor/pcore/define.rb +1 -0
  62. data/lib/flor/pcore/detect.rb +1 -0
  63. data/lib/flor/pcore/do_return.rb +1 -0
  64. data/lib/flor/pcore/each.rb +1 -0
  65. data/lib/flor/pcore/echo.rb +1 -0
  66. data/lib/flor/pcore/empty.rb +1 -0
  67. data/lib/flor/pcore/fail.rb +1 -0
  68. data/lib/flor/pcore/filter.rb +1 -0
  69. data/lib/flor/pcore/find.rb +1 -0
  70. data/lib/flor/pcore/flatten.rb +1 -0
  71. data/lib/flor/pcore/for_each.rb +1 -0
  72. data/lib/flor/pcore/if.rb +1 -0
  73. data/lib/flor/pcore/includes.rb +1 -0
  74. data/lib/flor/pcore/inject.rb +1 -0
  75. data/lib/flor/pcore/iterator.rb +1 -0
  76. data/lib/flor/pcore/keys.rb +1 -0
  77. data/lib/flor/pcore/length.rb +1 -0
  78. data/lib/flor/pcore/loop.rb +1 -0
  79. data/lib/flor/pcore/map.rb +1 -0
  80. data/lib/flor/pcore/match.rb +1 -0
  81. data/lib/flor/pcore/matchr.rb +1 -0
  82. data/lib/flor/pcore/max.rb +1 -0
  83. data/lib/flor/pcore/merge.rb +1 -0
  84. data/lib/flor/pcore/move.rb +1 -0
  85. data/lib/flor/pcore/noeval.rb +1 -0
  86. data/lib/flor/pcore/noret.rb +1 -0
  87. data/lib/flor/pcore/not.rb +1 -0
  88. data/lib/flor/pcore/on.rb +4 -3
  89. data/lib/flor/pcore/on_cancel.rb +1 -0
  90. data/lib/flor/pcore/on_error.rb +1 -0
  91. data/lib/flor/pcore/push.rb +1 -0
  92. data/lib/flor/pcore/rand.rb +1 -0
  93. data/lib/flor/pcore/range.rb +1 -0
  94. data/lib/flor/pcore/reduce.rb +1 -0
  95. data/lib/flor/pcore/return.rb +1 -0
  96. data/lib/flor/pcore/reverse.rb +1 -0
  97. data/lib/flor/pcore/select.rb +1 -0
  98. data/lib/flor/pcore/sequence.rb +1 -0
  99. data/lib/flor/pcore/set.rb +1 -0
  100. data/lib/flor/pcore/shuffle.rb +1 -0
  101. data/lib/flor/pcore/slice.rb +1 -0
  102. data/lib/flor/pcore/sort.rb +1 -0
  103. data/lib/flor/pcore/sort_by.rb +1 -0
  104. data/lib/flor/pcore/split.rb +1 -0
  105. data/lib/flor/pcore/stall.rb +1 -0
  106. data/lib/flor/pcore/strings.rb +1 -0
  107. data/lib/flor/pcore/timestamp.rb +1 -0
  108. data/lib/flor/pcore/to_array.rb +1 -0
  109. data/lib/flor/pcore/twig.rb +1 -0
  110. data/lib/flor/pcore/type_of.rb +1 -0
  111. data/lib/flor/pcore/until.rb +1 -0
  112. data/lib/flor/punit/abort.rb +50 -0
  113. data/lib/flor/punit/c_collect.rb +1 -0
  114. data/lib/flor/punit/c_each.rb +19 -0
  115. data/lib/flor/punit/c_for_each.rb +2 -1
  116. data/lib/flor/punit/c_iterator.rb +1 -0
  117. data/lib/flor/punit/c_map.rb +1 -0
  118. data/lib/flor/punit/cancel.rb +1 -0
  119. data/lib/flor/punit/concurrence.rb +1 -0
  120. data/lib/flor/punit/cron.rb +1 -0
  121. data/lib/flor/punit/do_trap.rb +1 -0
  122. data/lib/flor/punit/every.rb +1 -0
  123. data/lib/flor/punit/graft.rb +1 -0
  124. data/lib/flor/punit/m_ram.rb +1 -0
  125. data/lib/flor/punit/on_timeout.rb +1 -0
  126. data/lib/flor/punit/part.rb +1 -0
  127. data/lib/flor/punit/schedule.rb +1 -0
  128. data/lib/flor/punit/signal.rb +1 -0
  129. data/lib/flor/punit/sleep.rb +1 -0
  130. data/lib/flor/punit/task.rb +1 -0
  131. data/lib/flor/punit/trace.rb +1 -0
  132. data/lib/flor/punit/trap.rb +10 -1
  133. data/lib/flor/to_string.rb +1 -0
  134. data/lib/flor/tools/env.rb +1 -0
  135. data/lib/flor/tools/shell.rb +1 -0
  136. data/lib/flor/tools/shell_out.rb +1 -0
  137. data/lib/flor/tt.rb +98 -0
  138. data/lib/flor/unit.rb +2 -0
  139. data/lib/flor/unit/caller.rb +152 -19
  140. data/lib/flor/unit/caller_jruby.rb +132 -0
  141. data/lib/flor/unit/dump.rb +36 -0
  142. data/lib/flor/unit/executor.rb +1 -0
  143. data/lib/flor/unit/ganger.rb +6 -12
  144. data/lib/flor/unit/hloader.rb +34 -7
  145. data/lib/flor/unit/hook.rb +3 -0
  146. data/lib/flor/unit/hooker.rb +32 -15
  147. data/lib/flor/unit/journal.rb +23 -0
  148. data/lib/flor/unit/loader.rb +102 -7
  149. data/lib/flor/unit/logger.rb +24 -5
  150. data/lib/flor/unit/models.rb +8 -1
  151. data/lib/flor/unit/models/execution.rb +51 -0
  152. data/lib/flor/unit/models/message.rb +1 -0
  153. data/lib/flor/unit/models/pointer.rb +1 -0
  154. data/lib/flor/unit/models/timer.rb +1 -0
  155. data/lib/flor/unit/models/trace.rb +1 -0
  156. data/lib/flor/unit/models/trap.rb +3 -2
  157. data/lib/flor/unit/scheduler.rb +35 -28
  158. data/lib/flor/unit/spooler.rb +1 -0
  159. data/lib/flor/unit/storage.rb +68 -44
  160. data/lib/flor/unit/taskers.rb +2 -1
  161. data/lib/flor/unit/waiter.rb +2 -1
  162. data/lib/flor/unit/wlist.rb +10 -8
  163. metadata +13 -10
@@ -1,7 +1,30 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  module Flor
3
4
 
4
- class Loader
5
+ class CoreLoader
6
+
7
+ def shutdown
8
+ end
9
+
10
+ # Called to interpret require: confs from hooks and friends
11
+ #
12
+ def require(conf)
13
+
14
+ re = conf['require']
15
+
16
+ return unless re
17
+
18
+ ::Kernel.require(
19
+ if path = conf['_path']
20
+ File.join(File.dirname(path), re)
21
+ else
22
+ re
23
+ end)
24
+ end
25
+ end
26
+
27
+ class Loader < CoreLoader
5
28
 
6
29
  # NB: tasker configuration entries start with "loa_"
7
30
 
@@ -12,10 +35,8 @@ module Flor
12
35
  @cache = {}
13
36
  @mutex = Mutex.new
14
37
 
15
- @root = File.absolute_path(@unit.conf['lod_path'] || @unit.conf['root'])
16
- end
17
-
18
- def shutdown
38
+ @root = File.absolute_path(
39
+ @unit.conf['lod_path'] || @unit.conf['root'] || '.')
19
40
  end
20
41
 
21
42
  def variables(domain)
@@ -98,8 +119,8 @@ module Flor
98
119
  .select { |pa, d| Flor.sub_domain?(d, domain) }
99
120
  .sort_by { |pa, d| d.count('.') }
100
121
  .collect { |pa, d|
101
- eval(pa, {}).each_with_index { |h, i|
102
- h['_path'] = pa + ":#{i}" } }
122
+ eval(pa, {})
123
+ .each_with_index { |h, i| h['_path'] = pa + ":#{i}" } }
103
124
  .flatten(1)
104
125
  end
105
126
 
@@ -109,8 +130,82 @@ module Flor
109
130
  .collect { |h| Flor::Hook.new(@unit, exid, h) }
110
131
  end
111
132
 
133
+ def domains(start=nil)
134
+
135
+ start ||= ''
136
+
137
+ Dir[File.join(@root, '**/*.{json,flo,flor,rb}')]
138
+ .collect { |pa| pa[@root.length..-1] }
139
+ .sort
140
+ .collect { |pa|
141
+ pa = pa[4..-1] if pa.match(/^\/usr\//)
142
+ case pa
143
+ when /\.flor?$/ then extract_flow_domain(pa)
144
+ when /\/lib\/hooks\// then extract_hook_domain(pa)
145
+ when /\/lib\/taskers\// then extract_tasker_domain(pa)
146
+ when /\/etc\/variables\// then extract_variable_domain(pa)
147
+ else nil
148
+ end }
149
+ .compact
150
+ .select { |pa| pa.length > 1 }
151
+ .collect { |pa|
152
+ pa = pa[1..-1] if pa[0, 1] == '/'
153
+ pa = pa[0..-2] if pa.match(/\/$/)
154
+ pa.gsub('/', '.') }
155
+ .sort
156
+ .uniq
157
+ .select { |dm| Flor.sub_domain?(start, dm) }
158
+ end
159
+
160
+ def definitions(start=nil)
161
+
162
+ start ||= ''
163
+
164
+ Dir[File.join(@root, '**/*.{flo,flor}')]
165
+ .collect { |pa| pa[@root.length..-1] }
166
+ .collect { |pa| pa.gsub(/\A\/usr\//, '/') }
167
+ .collect { |pa| pa.gsub(/\/lib\/(sub)?flows\//, '/') }
168
+ .collect { |pa| pa.gsub(/\.flor?\z/, '') }
169
+ .collect { |pa| pa.gsub(/\//, '.') }
170
+ .collect { |pa| pa.gsub(/\A\./, '') }
171
+ .sort
172
+ .select { |pa| Flor.sub_domain?(start, pa) }
173
+ end
174
+
112
175
  protected
113
176
 
177
+ def extract_flow_domain(pa)
178
+ #o = pa
179
+ pa
180
+ .gsub(/\/lib\/(sub)?flows\//, '/')
181
+ .split('/')[0..-2].join('/')
182
+ #.tap { |x| p 'flow:' + o + ':' + x }
183
+ end
184
+ def extract_hook_domain(pa)
185
+ #o = pa
186
+ pa
187
+ .gsub(/\/lib\/hooks\//, '/')
188
+ .gsub(/\/(dot|hooks)\.(json|rb)$/, '/')
189
+ .gsub(/\.(json|rb)$/, '')
190
+ #.tap { |x| p 'hook:' + o + ':' + x }
191
+ end
192
+ def extract_tasker_domain(pa)
193
+ #o = pa
194
+ pa
195
+ .gsub(/\/lib\/taskers\//, '/')
196
+ .gsub(/\/[^\/]+\/(dot|flor|tasker)\.(json|rb)$/, '/')
197
+ .gsub(/\.(json|rb)$/, '')
198
+ #.tap { |x| p 'tasker: ' + o + ': ' + x }
199
+ end
200
+ def extract_variable_domain(pa)
201
+ #o = pa
202
+ pa
203
+ .gsub(/\/etc\/variables\//, '/')
204
+ .gsub(/\/(dot|flor)\.(json|rb)$/, '/')
205
+ .gsub(/\.(json|rb)$/, '')
206
+ #.tap { |x| p 'variable: ' + o + ': ' + x }
207
+ end
208
+
114
209
  def split_dn(domain, name)
115
210
 
116
211
  if name
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  module Flor
3
4
 
@@ -62,17 +63,24 @@ module Flor
62
63
  n = Time.now.utc
63
64
  stp = Flor.tstamp(n)
64
65
 
66
+ dbi =
67
+ case @unit.storage.db.to_s
68
+ when /SQLite/ then @unit.storage.db.uri
69
+ else ''
70
+ end
71
+ dbi = ' ' + dbi if dbi.length > 0
72
+
65
73
  txt = elts.collect(&:to_s).join(' ')
66
74
  err = elts.find { |e| e.is_a?(Exception) }
67
75
 
68
- line = "#{stp} #{@uni} #{lvl} #{txt}"
76
+ head = "#{stp} #{@uni}#{dbi} #{lvl} "
69
77
 
70
78
  if err
71
- dig = lvl[0, 1] + Digest::MD5.hexdigest(line)[0, 4]
72
- @out.puts("#{stp} #{@uni} #{lvl} #{dig} #{txt}")
79
+ dig = lvl[0, 1] + Digest::MD5.hexdigest(head + txt)[0, 4]
80
+ @out.puts(head + dig + ' ' + txt)
73
81
  err.backtrace.each { |lin| @out.puts(" #{dig} #{@uni} #{lin}") }
74
82
  else
75
- @out.puts(line)
83
+ @out.puts(head + txt)
76
84
  end
77
85
  end
78
86
 
@@ -113,7 +121,18 @@ module Flor
113
121
  #
114
122
  msg = summarize_blob(msg)
115
123
 
116
- @out.puts "#{_c.blg}sto#{_c.rs} t#{Thread.current.object_id} #{level.upcase} #{msg}"
124
+ msg = "#{_c.dg}#{msg}"
125
+ msg = msg.gsub(/\b(INSERT|UPDATE)\b/) { |m| "#{_c.rs}#{m}#{_c.dg}" }
126
+
127
+ tim = Time.now.utc.strftime('%T.%L') # HH:MM:SS.123
128
+ dbi = @unit.storage.db.object_id.to_s(16)
129
+ tid = Thread.current.object_id.to_s(16)
130
+ lvl = level.upcase
131
+
132
+ @out.puts(
133
+ "#{_c.blg}sto#{_c.rs} " +
134
+ "#{tim} #{_c.dg}db#{dbi} th#{tid} " +
135
+ "#{_c.rs}#{lvl}#{_c.rs} #{msg}#{_c.rs}")
117
136
  end
118
137
 
119
138
  def size_to_s(s)
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  module Flor
3
4
 
@@ -92,6 +93,12 @@ module Flor
92
93
  end
93
94
  end
94
95
 
96
+ alias to_dump_h to_h
97
+ #
98
+ # Downsteam, #to_h answers are more complete, more standalone
99
+ # whereas, #to_dump_h answers are more compact (see florist).
100
+ # For now, they're just the same, it specializes downstream.
101
+
95
102
  class << self
96
103
 
97
104
  def from_h(h)
@@ -135,7 +142,7 @@ module Flor
135
142
 
136
143
  @models[key] ||=
137
144
  parent_module.const_set(
138
- "#{c}#{@db.object_id.to_s.gsub('-', 'M')}",
145
+ "#{c}#{self.object_id.to_s.gsub('-', 'M')}",
139
146
  Class.new(parent_module.const_get(c)) do
140
147
  self.dataset = s.db["#{table_prefix}#{key}".to_sym]
141
148
  self.unit = s.unit
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  module Flor
3
4
 
@@ -98,6 +99,56 @@ module Flor
98
99
  h
99
100
  end
100
101
 
102
+ def lookup_nodes(query, opts={})
103
+
104
+ @node_index ||= nodes
105
+ .sort_by { |k, _| k }
106
+ .inject({}) { |h, (k, v)|
107
+ #
108
+ # nid => [ node ]
109
+ #
110
+ h[k] = [ v ]
111
+ #
112
+ # code => [ node0, node1, ... ]
113
+ #
114
+ t =
115
+ (lookup_tree(v['parent'])[1][Flor.child_id(v['nid'])] rescue nil) ||
116
+ lookup_tree(v['nid'])
117
+ s = Flor.tree_to_flor(t, chop: true)
118
+ (h[s] ||= []) << v
119
+ #
120
+ # tag => [ node0, node1, ... ]
121
+ #
122
+ ts = v['tags']
123
+ ts.each { |t| (h[t] ||= []) << v } if ts
124
+ #
125
+ h }
126
+
127
+ @node_index
128
+ .select { |k, v|
129
+ case query
130
+ when Regexp then k.match(query)
131
+ else k == query
132
+ end }
133
+ .values
134
+ .flatten(1)
135
+ end
136
+
137
+ def lookup_node(query, opts={})
138
+
139
+ lookup_nodes(query, opts).first
140
+ end
141
+
142
+ def lookup_nids(query, opts={})
143
+
144
+ lookup_nodes(query, opts).collect { |n| n['nid'] }
145
+ end
146
+
147
+ def lookup_nid(query, opts={})
148
+
149
+ lookup_node(query, opts)['nid']
150
+ end
151
+
101
152
  class << self
102
153
 
103
154
  def by_status(s)
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  module Flor
3
4
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  module Flor
3
4
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  module Flor
3
4
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  module Flor
3
4
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  module Flor
3
4
 
@@ -124,7 +125,7 @@ module Flor
124
125
  'exid' => self.exid,
125
126
  'nid' => self.nid,
126
127
  'type' => 'trap',
127
- 'trap' => to_hash,
128
+ 'trap' => to_trap_h,
128
129
  'trap_id' => self.id,
129
130
  'message' => msg,
130
131
  'sm' => message['m'] }
@@ -133,7 +134,7 @@ module Flor
133
134
  #'dbg' => xx }
134
135
  end
135
136
 
136
- def to_hash
137
+ def to_trap_h
137
138
 
138
139
  values
139
140
  .inject({}) { |h, (k, v)| h[k.to_s] = v if k != :content; h }
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  module Flor
3
4
 
@@ -9,6 +10,7 @@ module Flor
9
10
  attr_reader :logger
10
11
 
11
12
  attr_reader :thread_status
13
+ attr_reader :last_queued_message_id
12
14
 
13
15
  attr_reader :archive
14
16
 
@@ -222,7 +224,8 @@ module Flor
222
224
 
223
225
  def queue(message, opts={})
224
226
 
225
- @storage.put_message(message)
227
+ @last_queued_message_id =
228
+ @storage.put_message(message)
226
229
 
227
230
  if opts[:wait]
228
231
  wait(message['exid'], opts)
@@ -356,9 +359,13 @@ module Flor
356
359
  ) unless nid
357
360
 
358
361
  fail ArgumentError.new(
359
- "cannot add iteration to missing node #{nid.inspect}"
362
+ "cannot add iteration to node #{nid.inspect} not present in tree"
360
363
  ) unless exe.lookup_tree(nid)
361
364
 
365
+ fail ArgumentError.new(
366
+ "cannot add iteration to node #{nid.inspect} not present in execution"
367
+ ) unless exe.nodes.has_key?(nid)
368
+
362
369
  queue(msg, opts)
363
370
  end
364
371
  alias add_iteration add_iterations
@@ -434,16 +441,14 @@ module Flor
434
441
  #
435
442
  # unit.dump() { |h| ... } # modify the has right before it's turned to JSON
436
443
  #
444
+ # unit.dump(hash: true) # returns the hash (instead of JSONing it)
445
+ #
437
446
  def dump(io=nil, opts=nil, &block)
438
447
 
439
448
  io, opts = nil, io if io.is_a?(Hash)
440
449
  opts ||= {}
441
450
 
442
- o = lambda { |k| v = opts[k] || opts["#{k}s".to_sym]; v ? Array(v) : nil }
443
- #
444
- exis = o[:exid]
445
- doms = o[:domain]
446
- sdms = o[:strict_domain] || o[:sdomain]
451
+ exis, doms, sdms = extract_dump_and_load_filters(opts)
447
452
  #
448
453
  filter = lambda { |q|
449
454
  q = q.where(
@@ -458,25 +463,25 @@ module Flor
458
463
  domain: sdms) if sdms
459
464
  q }
460
465
 
461
- exs, tms, tps, pts =
466
+ hash =
462
467
  storage.db.transaction {
463
- [ filter[executions].collect(&:to_h),
464
- filter[timers].collect(&:to_h),
465
- filter[traps].collect(&:to_h),
466
- filter[pointers].collect(&:to_h) ] }
467
468
 
468
- o = io ? io : StringIO.new
469
+ h = {
470
+ timestamp: Flor.tstamp,
471
+ executions: filter[executions].collect(&:to_h),
472
+ timers: filter[timers].collect(&:to_h),
473
+ traps: filter[traps].collect(&:to_h),
474
+ pointers: filter[pointers].collect(&:to_h) }
475
+
476
+ block.call(h) if block
469
477
 
470
- h = {
471
- timestamp: Flor.tstamp,
472
- executions: exs,
473
- timers: tms,
474
- traps: tps,
475
- pointers: pts }
478
+ h }
476
479
 
477
- block.call(h) if block
480
+ return hash if opts[:hash] || opts[:h]
481
+
482
+ o = io ? io : StringIO.new
478
483
 
479
- JSON.dump(h, o)
484
+ JSON.dump(hash, o)
480
485
 
481
486
  io ? io : o.string
482
487
  end
@@ -507,12 +512,7 @@ module Flor
507
512
  mks = DUMP_KEYS - h.keys
508
513
  fail Flor::FlorError.new("missing keys #{mks.inspect}") if mks.any?
509
514
 
510
- o = lambda { |k| v = opts[k] || opts["#{k}s".to_sym]; v ? Array(v) : nil }
511
- #
512
- exis = o[:exid]
513
- doms = o[:domain]
514
- sdms = o[:strict_domain] || o[:sdomain]
515
- #
515
+ exis, doms, sdms = extract_dump_and_load_filters(opts)
516
516
  doms = doms.collect { |d| /\A#{d}(\.#{Flor::NAME_REX})*\z/ } if doms
517
517
 
518
518
  counts = { executions: 0, timers: 0, traps: 0, pointers: 0, total: 0 }
@@ -541,7 +541,7 @@ module Flor
541
541
  cla.import(cols, rows) if rows.any?
542
542
  end
543
543
 
544
- block.call(h) if block
544
+ block.call(h, counts) if block
545
545
  end
546
546
 
547
547
  counts
@@ -549,6 +549,13 @@ module Flor
549
549
 
550
550
  protected
551
551
 
552
+ def extract_dump_and_load_filters(opts)
553
+
554
+ o = lambda { |k| v = opts[k] || opts["#{k}s".to_sym]; v ? Array(v) : nil }
555
+
556
+ [ o[:exid], o[:domain], o[:strict_domain] || o[:sdomain] ]
557
+ end
558
+
552
559
  def tick
553
560
 
554
561
  t0 = Time.now