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
@@ -1,113 +1,118 @@
1
- class RbbtException < StandardError; end
2
- class ParameterException < RbbtException; end
3
-
4
- class MissingParameterException < ParameterException
5
- def initialize(parameter)
6
- super("Missing parameter '#{parameter}'")
7
- end
8
- end
9
-
10
- class FieldNotFoundError < StandardError;end
1
+ require_relative '../../refactor'
2
+ Rbbt.require_instead 'scout/exceptions'
11
3
  class ClosedStream < StandardError; end
12
-
13
- class ProcessFailed < StandardError;
14
- attr_accessor :pid, :msg
15
- def initialize(pid = Process.pid, msg = nil)
16
- @pid = pid
17
- @msg = msg
18
- if @pid
19
- if @msg
20
- message = "Process #{@pid} failed - #{@msg}"
21
- else
22
- message = "Process #{@pid} failed"
23
- end
24
- else
25
- message = "Failed to run #{@msg}"
26
- end
27
- super(message)
28
- end
29
- end
30
-
31
- class SSHProcessFailed < StandardError
32
- attr_accessor :host, :cmd
33
- def initialize(host, cmd)
34
- @host = host
35
- @cmd = cmd
36
- message = "SSH server #{host} failed cmd '#{cmd}'"
37
- super(message)
38
- end
39
- end
40
-
41
- class ConcurrentStreamProcessFailed < ProcessFailed
42
- attr_accessor :concurrent_stream
43
- def initialize(pid = Process.pid, msg = nil, concurrent_stream = nil)
44
- super(pid, msg)
45
- @concurrent_stream = concurrent_stream
46
- end
47
- end
48
-
49
- class Aborted < StandardError; end
50
-
51
- class TryAgain < StandardError; end
52
-
53
- class TryThis < StandardError
54
- attr_accessor :payload
55
- def initialize(payload = nil)
56
- @payload = payload
57
- end
58
- end
59
-
60
- class SemaphoreInterrupted < TryAgain; end
61
- class LockInterrupted < TryAgain; end
62
-
63
- class RemoteServerError < StandardError; end
64
-
65
- class DependencyError < Aborted
66
- def initialize(msg)
67
- if defined? Step and Step === msg
68
- step = msg
69
- new_msg = [step.path, step.messages.last] * ": "
70
- super(new_msg)
71
- else
72
- super(msg)
73
- end
74
- end
75
- end
76
-
77
- class DependencyRbbtException < RbbtException
78
- def initialize(msg)
79
- if defined? Step and Step === msg
80
- step = msg
81
-
82
- new_msg = nil
83
- new_msg = [step.path, step.messages.last] * ": "
84
-
85
- super(new_msg)
86
- else
87
- super(msg)
88
- end
89
- end
90
- end
91
-
92
- class DontClose < Exception; end
93
-
94
- class KeepLocked < Exception
95
- attr_accessor :payload
96
- def initialize(payload)
97
- @payload = payload
98
- end
99
- end
100
-
101
- class KeepBar < Exception
102
- attr_accessor :payload
103
- def initialize(payload)
104
- @payload = payload
105
- end
106
- end
107
-
108
- class StopInsist < Exception
109
- attr_accessor :exception
110
- def initialize(exception)
111
- @exception = exception
112
- end
113
- end
4
+ RbbtException = ScoutException
5
+ #class RbbtException < ScoutException; end
6
+ #class ParameterException < RbbtException; end
7
+ #
8
+ #class MissingParameterException < ParameterException
9
+ # def initialize(parameter)
10
+ # super("Missing parameter '#{parameter}'")
11
+ # end
12
+ #end
13
+ #
14
+ #class FieldNotFoundError < StandardError;end
15
+ #class ClosedStream < StandardError; end
16
+ #
17
+ #class ProcessFailed < StandardError;
18
+ # attr_accessor :pid, :msg
19
+ # def initialize(pid = Process.pid, msg = nil)
20
+ # @pid = pid
21
+ # @msg = msg
22
+ # if @pid
23
+ # if @msg
24
+ # message = "Process #{@pid} failed - #{@msg}"
25
+ # else
26
+ # message = "Process #{@pid} failed"
27
+ # end
28
+ # else
29
+ # message = "Failed to run #{@msg}"
30
+ # end
31
+ # super(message)
32
+ # end
33
+ #end
34
+ #
35
+ #class SSHProcessFailed < StandardError
36
+ # attr_accessor :host, :cmd
37
+ # def initialize(host, cmd)
38
+ # @host = host
39
+ # @cmd = cmd
40
+ # message = "SSH server #{host} failed cmd '#{cmd}'"
41
+ # super(message)
42
+ # end
43
+ #end
44
+ #
45
+ #class ConcurrentStreamProcessFailed < ProcessFailed
46
+ # attr_accessor :concurrent_stream
47
+ # def initialize(pid = Process.pid, msg = nil, concurrent_stream = nil)
48
+ # super(pid, msg)
49
+ # @concurrent_stream = concurrent_stream
50
+ # end
51
+ #end
52
+ #
53
+ #class Aborted < StandardError; end
54
+ #
55
+ #class TryAgain < StandardError; end
56
+ #
57
+ #class TryThis < StandardError
58
+ # attr_accessor :payload
59
+ # def initialize(payload = nil)
60
+ # @payload = payload
61
+ # end
62
+ #end
63
+ #
64
+ #class SemaphoreInterrupted < TryAgain; end
65
+ #class LockInterrupted < TryAgain; end
66
+ #
67
+ #class RemoteServerError < StandardError; end
68
+ #
69
+ #class DependencyError < Aborted
70
+ # def initialize(msg)
71
+ # if defined? Step and Step === msg
72
+ # step = msg
73
+ # new_msg = [step.path, step.messages.last] * ": "
74
+ # super(new_msg)
75
+ # else
76
+ # super(msg)
77
+ # end
78
+ # end
79
+ #end
80
+ #
81
+ #class DependencyException < RbbtException
82
+ #class DependencyRbbtException < RbbtException
83
+ # def initialize(msg)
84
+ # if defined? Step and Step === msg
85
+ # step = msg
86
+ #
87
+ # new_msg = nil
88
+ # new_msg = [step.path, step.messages.last] * ": "
89
+ #
90
+ # super(new_msg)
91
+ # else
92
+ # super(msg)
93
+ # end
94
+ # end
95
+ #end
96
+ #
97
+ #class DontClose < Exception; end
98
+ #
99
+ #class KeepLocked < Exception
100
+ # attr_accessor :payload
101
+ # def initialize(payload)
102
+ # @payload = payload
103
+ # end
104
+ #end
105
+ #
106
+ #class KeepBar < Exception
107
+ # attr_accessor :payload
108
+ # def initialize(payload)
109
+ # @payload = payload
110
+ # end
111
+ #end
112
+ #
113
+ #class StopInsist < Exception
114
+ # attr_accessor :exception
115
+ # def initialize(exception)
116
+ # @exception = exception
117
+ # end
118
+ #end
@@ -1,230 +1,2 @@
1
- module Misc
2
- COLOR_LIST = %w(#BC80BD #CCEBC5 #FFED6F #8DD3C7 #FFFFB3 #BEBADA #FB8072 #80B1D3 #FDB462 #B3DE69 #FCCDE5 #D9D9D9)
3
-
4
- def self.colors_for(list)
5
- unused = COLOR_LIST.dup
6
-
7
- used = {}
8
- colors = list.collect do |elem|
9
- if used.include? elem
10
- used[elem]
11
- else
12
- color = unused.shift
13
- used[elem]=color
14
- color
15
- end
16
- end
17
-
18
- [colors, used]
19
- end
20
-
21
- def self.format_seconds(time, extended = false)
22
- seconds = time.to_i
23
- str = [seconds/3600, seconds/60 % 60, seconds % 60].map{|t| "%02i" % t }.join(':')
24
- str << ".%02i" % ((time - seconds) * 100) if extended
25
- str
26
- end
27
-
28
- def self.format_paragraph(text, size = 80, indent = 0, offset = 0)
29
- i = 0
30
- offset = 0 if offset.nil?
31
- indent = 0 if indent.nil?
32
- size = 80 if size.nil?
33
- size = size + offset + indent
34
- re = /((?:\n\s*\n\s*)|(?:\n\s*(?=\*)))/
35
- text.split(re).collect do |paragraph|
36
- i += 1
37
- str = if i % 2 == 1
38
- words = paragraph.gsub(/\s+/, "\s").split(" ")
39
- lines = []
40
- line = " "*offset
41
- word = words.shift
42
- while word
43
- word = word[0..size-indent-offset-4] + '...' if word.length >= size - indent - offset
44
- while word and Log.uncolor(line).length + Log.uncolor(word).length <= size - indent
45
- line << word << " "
46
- word = words.shift
47
- end
48
- offset = 0
49
- lines << ((" " * indent) << line[0..-2])
50
- line = ""
51
- end
52
- (lines * "\n")
53
- else
54
- paragraph
55
- end
56
- offset = 0
57
- str
58
- end*""
59
- end
60
-
61
- def self.format_definition_list_item(dt, dd, size = 80, indent = 20, color = :yellow)
62
- dd = "" if dd.nil?
63
- dt = Log.color color, dt if color
64
- dt = dt.to_s unless dd.empty?
65
- len = Log.uncolor(dt).length
66
-
67
- if indent < 0
68
- text = format_paragraph(dd, size, indent.abs-1, 0)
69
- text = dt << "\n" << text
70
- else
71
- offset = len - indent
72
- offset = 0 if offset < 0
73
- text = format_paragraph(dd, size, indent.abs+1, offset)
74
- text[0..len-1] = dt
75
- end
76
- text
77
- end
78
-
79
- def self.format_definition_list(defs, size = 80, indent = 20, color = :yellow, sep = "\n\n")
80
- entries = []
81
- defs.each do |dt,dd|
82
- text = format_definition_list_item(dt,dd,size,indent,color)
83
- entries << text
84
- end
85
- entries * sep
86
- end
87
-
88
- def self.camel_case(string)
89
- return string if string !~ /_/ && string =~ /[A-Z]+.*/
90
- string.split(/_|(\d+)/).map{|e|
91
- (e =~ /^[A-Z]{2,}$/ ? e : e.capitalize)
92
- }.join
93
- end
94
-
95
- def self.camel_case_lower(string)
96
- string.split('_').inject([]){ |buffer,e|
97
- buffer.push(buffer.empty? ? e.downcase : (e =~ /^[A-Z]{2,}$/ ? e : e.capitalize))
98
- }.join
99
- end
100
-
101
- def self.snake_case(string)
102
- return nil if string.nil?
103
- string = string.to_s if Symbol === string
104
- string.
105
- gsub(/([A-Z]{2,})([A-Z][a-z])/,'\1_\2').
106
- gsub(/([a-z])([A-Z])/,'\1_\2').
107
- gsub(/\s/,'_').gsub(/[^\w_]/, '').
108
- split("_").collect{|p| p.match(/[A-Z]{2,}/) ? p : p.downcase } * "_"
109
- end
110
-
111
- # source: https://gist.github.com/ekdevdes/2450285
112
- # author: Ethan Kramer (https://github.com/ekdevdes)
113
- def self.humanize(value, options = {})
114
- if options.empty?
115
- options[:format] = :sentence
116
- end
117
-
118
- values = value.to_s.split('_')
119
- values.each_index do |index|
120
- # lower case each item in array
121
- # Miguel Vazquez edit: Except for acronyms
122
- values[index].downcase! unless values[index].match(/[a-zA-Z][A-Z]/)
123
- end
124
- if options[:format] == :allcaps
125
- values.each do |value|
126
- value.capitalize!
127
- end
128
-
129
- if options.empty?
130
- options[:seperator] = " "
131
- end
132
-
133
- return values.join " "
134
- end
135
-
136
- if options[:format] == :class
137
- values.each do |value|
138
- value.capitalize!
139
- end
140
-
141
- return values.join ""
142
- end
143
-
144
- if options[:format] == :sentence
145
- values[0].capitalize! unless values[0].match(/[a-zA-Z][A-Z]/)
146
-
147
- return values.join " "
148
- end
149
-
150
- if options[:format] == :nocaps
151
- return values.join " "
152
- end
153
- end
154
-
155
- def self.fixascii(string)
156
- if string.respond_to?(:encode)
157
- self.fixutf8(string).encode("ASCII-8BIT")
158
- else
159
- string
160
- end
161
- end
162
-
163
- def self.to_utf8(string)
164
- string.encode("UTF-16BE", :invalid => :replace, :undef => :replace, :replace => "?").encode('UTF-8')
165
- end
166
-
167
- def self.fixutf8(string)
168
- return nil if string.nil?
169
- return string if string.respond_to?(:encoding) && string.encoding.to_s == "UTF-8" && (string.respond_to?(:valid_encoding?) && string.valid_encoding?) ||
170
- (string.respond_to?(:valid_encoding) && string.valid_encoding)
171
-
172
- if string.respond_to?(:encode)
173
- string.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
174
- else
175
- require 'iconv'
176
- @@ic ||= Iconv.new('UTF-8//IGNORE', 'UTF-8')
177
- @@ic.iconv(string)
178
- end
179
- end
180
-
181
- def self.humanize_list(list)
182
- return "" if list.empty?
183
- if list.length == 1
184
- list.first
185
- else
186
- list[0..-2].collect{|e| e.to_s} * ", " << " and " << list[-1].to_s
187
- end
188
- end
189
-
190
- def self.parse_sql_values(txt)
191
- io = StringIO.new txt.strip
192
-
193
- values = []
194
- fields = []
195
- current = nil
196
- quoted = false
197
- while c = io.getc
198
- if quoted
199
- if c == "'"
200
- quoted = false
201
- else
202
- current << c
203
- end
204
- else
205
- case c
206
- when "("
207
- current = ""
208
- when ")"
209
- fields << current
210
- values << fields
211
- fields = []
212
- current = nil
213
- when ','
214
- if not current.nil?
215
- fields << current
216
- current = ""
217
- end
218
- when "'"
219
- quoted = true
220
- when ";"
221
- break
222
- else
223
- current << c
224
- end
225
- end
226
- end
227
- values
228
- end
229
-
230
- end
1
+ require_relative 'refactor'
2
+ Rbbt.require_instead 'scout/misc/format'
@@ -1,107 +1,2 @@
1
- module IndiferentHash
2
-
3
- def self.setup(hash)
4
- hash.extend IndiferentHash
5
- end
6
-
7
- def merge(other)
8
- new = self.dup
9
- IndiferentHash.setup(new)
10
- other.each do |k,value|
11
- new[k] = value
12
- end
13
- new
14
- end
15
-
16
- def []=(key,value)
17
- delete(key)
18
- super(key,value)
19
- end
20
-
21
- def _default?
22
- @_default ||= self.default or self.default_proc
23
- end
24
-
25
- def [](key, *args)
26
- res = super(key, *args)
27
- res = IndiferentHash.setup(res) if Hash === res
28
- return res unless res.nil? or (_default? and not keys.include? key)
29
-
30
- case key
31
- when Symbol, Module
32
- res = super(key.to_s, *args)
33
- when String
34
- res = super(key.to_sym, *args)
35
- end
36
-
37
- res = IndiferentHash.setup(res) if Hash === res
38
-
39
- res
40
- end
41
-
42
- def values_at(*key_list)
43
- key_list.inject([]){|acc,key| acc << self[key]}
44
- end
45
-
46
- def include?(key)
47
- case key
48
- when Symbol, Module
49
- super(key) || super(key.to_s)
50
- when String
51
- super(key) || super(key.to_sym)
52
- else
53
- super(key)
54
- end
55
- end
56
-
57
- def delete(key)
58
- case key
59
- when Symbol, Module
60
- super(key) || super(key.to_s)
61
- when String
62
- super(key) || super(key.to_sym)
63
- else
64
- super(key)
65
- end
66
- end
67
-
68
- def clean_version
69
- clean = {}
70
- each do |k,v|
71
- clean[k.to_s] = v unless clean.include? k.to_s
72
- end
73
- clean
74
- end
75
- end
76
-
77
- module CaseInsensitiveHash
78
-
79
-
80
- def self.setup(hash)
81
- hash.extend CaseInsensitiveHash
82
- end
83
-
84
- def downcase_keys
85
- @downcase_keys ||= begin
86
- down = {}
87
- keys.collect{|key|
88
- down[key.to_s.downcase] = key
89
- }
90
- down
91
- end
92
- end
93
-
94
- def [](key, *rest)
95
- value = super(key, *rest)
96
- return value unless value.nil?
97
- key_downcase = key.to_s.downcase
98
- super(downcase_keys[key_downcase])
99
- end
100
-
101
- def values_at(*keys)
102
- keys.collect do |key|
103
- self[key]
104
- end
105
- end
106
-
107
- end
1
+ require_relative '../../refactor'
2
+ Rbbt.require_instead 'scout/indiferent_hash'