kinetic_sdk 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (245) hide show
  1. checksums.yaml +7 -0
  2. data/GettingStarted.md +64 -0
  3. data/README.md +383 -0
  4. data/bin/console +12 -0
  5. data/bin/setup +8 -0
  6. data/gems/kontena-websocket-client-0.1.1/Gemfile +4 -0
  7. data/gems/kontena-websocket-client-0.1.1/LICENSE +190 -0
  8. data/gems/kontena-websocket-client-0.1.1/README.md +138 -0
  9. data/gems/kontena-websocket-client-0.1.1/Rakefile +6 -0
  10. data/gems/kontena-websocket-client-0.1.1/benchmark/benchmark-client.rb +45 -0
  11. data/gems/kontena-websocket-client-0.1.1/benchmark/benchmark-em.rb +66 -0
  12. data/gems/kontena-websocket-client-0.1.1/benchmark/benchmark.rb +161 -0
  13. data/gems/kontena-websocket-client-0.1.1/benchmark/benchmark.sh +17 -0
  14. data/gems/kontena-websocket-client-0.1.1/benchmark/websocket-echo-server.go +207 -0
  15. data/gems/kontena-websocket-client-0.1.1/examples/websocket-echo-client.rb +80 -0
  16. data/gems/kontena-websocket-client-0.1.1/kontena-websocket-client.gemspec +24 -0
  17. data/gems/kontena-websocket-client-0.1.1/lib/kontena/websocket/client/connection.rb +119 -0
  18. data/gems/kontena-websocket-client-0.1.1/lib/kontena/websocket/client/version.rb +13 -0
  19. data/gems/kontena-websocket-client-0.1.1/lib/kontena/websocket/client.rb +848 -0
  20. data/gems/kontena-websocket-client-0.1.1/lib/kontena/websocket/error.rb +81 -0
  21. data/gems/kontena-websocket-client-0.1.1/lib/kontena/websocket/logging.rb +55 -0
  22. data/gems/kontena-websocket-client-0.1.1/lib/kontena/websocket/openssl_patch.rb +10 -0
  23. data/gems/kontena-websocket-client-0.1.1/lib/kontena-websocket-client.rb +15 -0
  24. data/gems/mime-types-3.1/Code-of-Conduct.rdoc +74 -0
  25. data/gems/mime-types-3.1/Contributing.rdoc +130 -0
  26. data/gems/mime-types-3.1/History.rdoc +658 -0
  27. data/gems/mime-types-3.1/Licence.rdoc +25 -0
  28. data/gems/mime-types-3.1/Manifest.txt +31 -0
  29. data/gems/mime-types-3.1/README.rdoc +202 -0
  30. data/gems/mime-types-3.1/Rakefile +254 -0
  31. data/gems/mime-types-3.1/lib/mime/type/columnar.rb +55 -0
  32. data/gems/mime-types-3.1/lib/mime/type.rb +573 -0
  33. data/gems/mime-types-3.1/lib/mime/types/_columnar.rb +135 -0
  34. data/gems/mime-types-3.1/lib/mime/types/cache.rb +56 -0
  35. data/gems/mime-types-3.1/lib/mime/types/columnar.rb +1 -0
  36. data/gems/mime-types-3.1/lib/mime/types/container.rb +30 -0
  37. data/gems/mime-types-3.1/lib/mime/types/deprecations.rb +32 -0
  38. data/gems/mime-types-3.1/lib/mime/types/full.rb +17 -0
  39. data/gems/mime-types-3.1/lib/mime/types/loader.rb +148 -0
  40. data/gems/mime-types-3.1/lib/mime/types/logger.rb +37 -0
  41. data/gems/mime-types-3.1/lib/mime/types/registry.rb +81 -0
  42. data/gems/mime-types-3.1/lib/mime/types.rb +228 -0
  43. data/gems/mime-types-3.1/lib/mime-types.rb +1 -0
  44. data/gems/mime-types-3.1/test/bad-fixtures/malformed +9 -0
  45. data/gems/mime-types-3.1/test/fixture/json.json +1 -0
  46. data/gems/mime-types-3.1/test/fixture/old-data +9 -0
  47. data/gems/mime-types-3.1/test/fixture/yaml.yaml +55 -0
  48. data/gems/mime-types-3.1/test/minitest_helper.rb +13 -0
  49. data/gems/mime-types-3.1/test/test_mime_type.rb +603 -0
  50. data/gems/mime-types-3.1/test/test_mime_types.rb +161 -0
  51. data/gems/mime-types-3.1/test/test_mime_types_cache.rb +109 -0
  52. data/gems/mime-types-3.1/test/test_mime_types_class.rb +155 -0
  53. data/gems/mime-types-3.1/test/test_mime_types_lazy.rb +43 -0
  54. data/gems/mime-types-3.1/test/test_mime_types_loader.rb +32 -0
  55. data/gems/mime-types-data-3.2016.0521/Code-of-Conduct.md +75 -0
  56. data/gems/mime-types-data-3.2016.0521/Contributing.md +157 -0
  57. data/gems/mime-types-data-3.2016.0521/History.md +351 -0
  58. data/gems/mime-types-data-3.2016.0521/Licence.md +25 -0
  59. data/gems/mime-types-data-3.2016.0521/Manifest.txt +18 -0
  60. data/gems/mime-types-data-3.2016.0521/README.md +61 -0
  61. data/gems/mime-types-data-3.2016.0521/Rakefile +80 -0
  62. data/gems/mime-types-data-3.2016.0521/data/mime-types.json +1 -0
  63. data/gems/mime-types-data-3.2016.0521/data/mime.content_type.column +1964 -0
  64. data/gems/mime-types-data-3.2016.0521/data/mime.docs.column +1964 -0
  65. data/gems/mime-types-data-3.2016.0521/data/mime.encoding.column +1964 -0
  66. data/gems/mime-types-data-3.2016.0521/data/mime.flags.column +1964 -0
  67. data/gems/mime-types-data-3.2016.0521/data/mime.friendly.column +1964 -0
  68. data/gems/mime-types-data-3.2016.0521/data/mime.pext.column +1964 -0
  69. data/gems/mime-types-data-3.2016.0521/data/mime.use_instead.column +1964 -0
  70. data/gems/mime-types-data-3.2016.0521/data/mime.xrefs.column +1964 -0
  71. data/gems/mime-types-data-3.2016.0521/lib/mime/types/data.rb +21 -0
  72. data/gems/mime-types-data-3.2016.0521/lib/mime-types-data.rb +3 -0
  73. data/gems/multipart-post-2.0.0/Gemfile +14 -0
  74. data/gems/multipart-post-2.0.0/History.txt +60 -0
  75. data/gems/multipart-post-2.0.0/Manifest.txt +9 -0
  76. data/gems/multipart-post-2.0.0/README.md +77 -0
  77. data/gems/multipart-post-2.0.0/Rakefile +9 -0
  78. data/gems/multipart-post-2.0.0/lib/composite_io.rb +108 -0
  79. data/gems/multipart-post-2.0.0/lib/multipart_post.rb +9 -0
  80. data/gems/multipart-post-2.0.0/lib/multipartable.rb +29 -0
  81. data/gems/multipart-post-2.0.0/lib/net/http/post/multipart.rb +27 -0
  82. data/gems/multipart-post-2.0.0/lib/parts.rb +96 -0
  83. data/gems/multipart-post-2.0.0/multipart-post.gemspec +22 -0
  84. data/gems/multipart-post-2.0.0/test/multibyte.txt +1 -0
  85. data/gems/multipart-post-2.0.0/test/net/http/post/test_multipart.rb +110 -0
  86. data/gems/multipart-post-2.0.0/test/test_composite_io.rb +115 -0
  87. data/gems/multipart-post-2.0.0/test/test_parts.rb +86 -0
  88. data/gems/parallel-1.12.1/MIT-LICENSE.txt +20 -0
  89. data/gems/parallel-1.12.1/lib/parallel/processor_count.rb +93 -0
  90. data/gems/parallel-1.12.1/lib/parallel/version.rb +3 -0
  91. data/gems/parallel-1.12.1/lib/parallel.rb +500 -0
  92. data/gems/ruby-progressbar-1.9.0/LICENSE.txt +19 -0
  93. data/gems/ruby-progressbar-1.9.0/README.md +38 -0
  94. data/gems/ruby-progressbar-1.9.0/Rakefile +2 -0
  95. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/base.rb +183 -0
  96. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/calculators/length.rb +99 -0
  97. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/calculators/running_average.rb +9 -0
  98. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/components/bar.rb +96 -0
  99. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/components/percentage.rb +29 -0
  100. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/components/rate.rb +43 -0
  101. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/components/time.rb +107 -0
  102. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/components/title.rb +13 -0
  103. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/components.rb +5 -0
  104. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/errors/invalid_progress_error.rb +4 -0
  105. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/format/formatter.rb +27 -0
  106. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/format/molecule.rb +59 -0
  107. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/format/string.rb +36 -0
  108. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/format.rb +3 -0
  109. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/output.rb +68 -0
  110. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/outputs/non_tty.rb +47 -0
  111. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/outputs/null.rb +33 -0
  112. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/outputs/tty.rb +32 -0
  113. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/progress.rb +118 -0
  114. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/refinements/enumerator.rb +25 -0
  115. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/refinements.rb +1 -0
  116. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/throttle.rb +25 -0
  117. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/time.rb +30 -0
  118. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/timer.rb +72 -0
  119. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/version.rb +3 -0
  120. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar.rb +18 -0
  121. data/gems/slugify-1.0.7/README +18 -0
  122. data/gems/slugify-1.0.7/lib/slugify.rb +1012 -0
  123. data/gems/slugify-1.0.7/lib/slugify_string.rb +11 -0
  124. data/gems/slugify-1.0.7/tests/slugify_test.rb +116 -0
  125. data/gems/slugify-1.0.7/tests/string_slugify_test.rb +23 -0
  126. data/gems/websocket-driver-0.6.5/CHANGELOG.md +123 -0
  127. data/gems/websocket-driver-0.6.5/LICENSE.md +22 -0
  128. data/gems/websocket-driver-0.6.5/README.md +369 -0
  129. data/gems/websocket-driver-0.6.5/examples/tcp_server.rb +28 -0
  130. data/gems/websocket-driver-0.6.5/ext/websocket-driver/Makefile +264 -0
  131. data/gems/websocket-driver-0.6.5/ext/websocket-driver/WebsocketMaskService.java +55 -0
  132. data/gems/websocket-driver-0.6.5/ext/websocket-driver/extconf.rb +4 -0
  133. data/gems/websocket-driver-0.6.5/ext/websocket-driver/websocket_mask.bundle +0 -0
  134. data/gems/websocket-driver-0.6.5/ext/websocket-driver/websocket_mask.c +41 -0
  135. data/gems/websocket-driver-0.6.5/ext/websocket-driver/websocket_mask.o +0 -0
  136. data/gems/websocket-driver-0.6.5/lib/websocket/driver/client.rb +140 -0
  137. data/gems/websocket-driver-0.6.5/lib/websocket/driver/draft75.rb +102 -0
  138. data/gems/websocket-driver-0.6.5/lib/websocket/driver/draft76.rb +96 -0
  139. data/gems/websocket-driver-0.6.5/lib/websocket/driver/event_emitter.rb +54 -0
  140. data/gems/websocket-driver-0.6.5/lib/websocket/driver/headers.rb +45 -0
  141. data/gems/websocket-driver-0.6.5/lib/websocket/driver/hybi/frame.rb +20 -0
  142. data/gems/websocket-driver-0.6.5/lib/websocket/driver/hybi/message.rb +31 -0
  143. data/gems/websocket-driver-0.6.5/lib/websocket/driver/hybi.rb +406 -0
  144. data/gems/websocket-driver-0.6.5/lib/websocket/driver/proxy.rb +68 -0
  145. data/gems/websocket-driver-0.6.5/lib/websocket/driver/server.rb +80 -0
  146. data/gems/websocket-driver-0.6.5/lib/websocket/driver/stream_reader.rb +55 -0
  147. data/gems/websocket-driver-0.6.5/lib/websocket/driver.rb +199 -0
  148. data/gems/websocket-driver-0.6.5/lib/websocket/http/headers.rb +112 -0
  149. data/gems/websocket-driver-0.6.5/lib/websocket/http/request.rb +45 -0
  150. data/gems/websocket-driver-0.6.5/lib/websocket/http/response.rb +29 -0
  151. data/gems/websocket-driver-0.6.5/lib/websocket/http.rb +15 -0
  152. data/gems/websocket-driver-0.6.5/lib/websocket/mask.rb +14 -0
  153. data/gems/websocket-driver-0.6.5/lib/websocket/websocket_mask.rb +2 -0
  154. data/gems/websocket-driver-0.6.5/lib/websocket_mask.bundle +0 -0
  155. data/gems/websocket-driver-0.6.5-java/CHANGELOG.md +123 -0
  156. data/gems/websocket-driver-0.6.5-java/LICENSE.md +22 -0
  157. data/gems/websocket-driver-0.6.5-java/README.md +369 -0
  158. data/gems/websocket-driver-0.6.5-java/examples/tcp_server.rb +28 -0
  159. data/gems/websocket-driver-0.6.5-java/ext/websocket-driver/WebsocketMaskService.java +55 -0
  160. data/gems/websocket-driver-0.6.5-java/ext/websocket-driver/extconf.rb +4 -0
  161. data/gems/websocket-driver-0.6.5-java/ext/websocket-driver/websocket_mask.c +41 -0
  162. data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/client.rb +140 -0
  163. data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/draft75.rb +102 -0
  164. data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/draft76.rb +96 -0
  165. data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/event_emitter.rb +54 -0
  166. data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/headers.rb +45 -0
  167. data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/hybi/frame.rb +20 -0
  168. data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/hybi/message.rb +31 -0
  169. data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/hybi.rb +406 -0
  170. data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/proxy.rb +68 -0
  171. data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/server.rb +80 -0
  172. data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/stream_reader.rb +55 -0
  173. data/gems/websocket-driver-0.6.5-java/lib/websocket/driver.rb +199 -0
  174. data/gems/websocket-driver-0.6.5-java/lib/websocket/http/headers.rb +112 -0
  175. data/gems/websocket-driver-0.6.5-java/lib/websocket/http/request.rb +45 -0
  176. data/gems/websocket-driver-0.6.5-java/lib/websocket/http/response.rb +29 -0
  177. data/gems/websocket-driver-0.6.5-java/lib/websocket/http.rb +15 -0
  178. data/gems/websocket-driver-0.6.5-java/lib/websocket/mask.rb +14 -0
  179. data/gems/websocket-driver-0.6.5-java/lib/websocket/websocket_mask.rb +2 -0
  180. data/gems/websocket-driver-0.6.5-java/lib/websocket_mask.jar +0 -0
  181. data/gems/websocket-extensions-0.1.3/CHANGELOG.md +15 -0
  182. data/gems/websocket-extensions-0.1.3/LICENSE.md +20 -0
  183. data/gems/websocket-extensions-0.1.3/README.md +313 -0
  184. data/gems/websocket-extensions-0.1.3/lib/websocket/extensions/parser.rb +111 -0
  185. data/gems/websocket-extensions-0.1.3/lib/websocket/extensions.rb +181 -0
  186. data/lib/kinetic-sdk.rb +1 -0
  187. data/lib/kinetic_sdk/bridgehub/bridgehub-sdk.rb +80 -0
  188. data/lib/kinetic_sdk/bridgehub/lib/access_keys.rb +67 -0
  189. data/lib/kinetic_sdk/bridgehub/lib/bridge.rb +69 -0
  190. data/lib/kinetic_sdk/discussions/discussions-sdk.rb +165 -0
  191. data/lib/kinetic_sdk/discussions/lib/discussions.rb +107 -0
  192. data/lib/kinetic_sdk/discussions/lib/invitations.rb +120 -0
  193. data/lib/kinetic_sdk/discussions/lib/messages.rb +190 -0
  194. data/lib/kinetic_sdk/discussions/lib/meta.rb +14 -0
  195. data/lib/kinetic_sdk/discussions/lib/participants.rb +64 -0
  196. data/lib/kinetic_sdk/discussions/lib/related_items.rb +54 -0
  197. data/lib/kinetic_sdk/discussions/lib/websockets.rb +96 -0
  198. data/lib/kinetic_sdk/filehub/filehub-sdk.rb +80 -0
  199. data/lib/kinetic_sdk/filehub/lib/access_keys.rb +67 -0
  200. data/lib/kinetic_sdk/filehub/lib/filestores.rb +67 -0
  201. data/lib/kinetic_sdk/request_ce/lib/attribute_definitions.rb +153 -0
  202. data/lib/kinetic_sdk/request_ce/lib/bridges.rb +66 -0
  203. data/lib/kinetic_sdk/request_ce/lib/categories.rb +34 -0
  204. data/lib/kinetic_sdk/request_ce/lib/datastore_form.rb +110 -0
  205. data/lib/kinetic_sdk/request_ce/lib/datastore_submissions.rb +157 -0
  206. data/lib/kinetic_sdk/request_ce/lib/form.rb +99 -0
  207. data/lib/kinetic_sdk/request_ce/lib/form_types.rb +51 -0
  208. data/lib/kinetic_sdk/request_ce/lib/jwt.rb +55 -0
  209. data/lib/kinetic_sdk/request_ce/lib/kapp.rb +93 -0
  210. data/lib/kinetic_sdk/request_ce/lib/meta.rb +14 -0
  211. data/lib/kinetic_sdk/request_ce/lib/oauth.rb +37 -0
  212. data/lib/kinetic_sdk/request_ce/lib/security_policy_definitions.rb +157 -0
  213. data/lib/kinetic_sdk/request_ce/lib/space.rb +89 -0
  214. data/lib/kinetic_sdk/request_ce/lib/submissions.rb +215 -0
  215. data/lib/kinetic_sdk/request_ce/lib/system_api.rb +69 -0
  216. data/lib/kinetic_sdk/request_ce/lib/teams.rb +113 -0
  217. data/lib/kinetic_sdk/request_ce/lib/users.rb +245 -0
  218. data/lib/kinetic_sdk/request_ce/lib/webhook_jobs.rb +142 -0
  219. data/lib/kinetic_sdk/request_ce/lib/webhooks.rb +192 -0
  220. data/lib/kinetic_sdk/request_ce/request-ce-sdk.rb +153 -0
  221. data/lib/kinetic_sdk/task/lib/access_keys.rb +94 -0
  222. data/lib/kinetic_sdk/task/lib/categories.rb +190 -0
  223. data/lib/kinetic_sdk/task/lib/config.rb +202 -0
  224. data/lib/kinetic_sdk/task/lib/engine.rb +42 -0
  225. data/lib/kinetic_sdk/task/lib/environment.rb +14 -0
  226. data/lib/kinetic_sdk/task/lib/errors.rb +165 -0
  227. data/lib/kinetic_sdk/task/lib/groups.rb +112 -0
  228. data/lib/kinetic_sdk/task/lib/handlers.rb +105 -0
  229. data/lib/kinetic_sdk/task/lib/health.rb +28 -0
  230. data/lib/kinetic_sdk/task/lib/license.rb +52 -0
  231. data/lib/kinetic_sdk/task/lib/policy_rules.rb +166 -0
  232. data/lib/kinetic_sdk/task/lib/setup.rb +56 -0
  233. data/lib/kinetic_sdk/task/lib/sources.rb +134 -0
  234. data/lib/kinetic_sdk/task/lib/tasks.rb +17 -0
  235. data/lib/kinetic_sdk/task/lib/trees.rb +274 -0
  236. data/lib/kinetic_sdk/task/lib/users.rb +75 -0
  237. data/lib/kinetic_sdk/task/task-sdk.rb +92 -0
  238. data/lib/kinetic_sdk/utils/kinetic-http-headers.rb +150 -0
  239. data/lib/kinetic_sdk/utils/kinetic-http-response.rb +75 -0
  240. data/lib/kinetic_sdk/utils/kinetic-http.rb +552 -0
  241. data/lib/kinetic_sdk/utils/logger.rb +70 -0
  242. data/lib/kinetic_sdk/utils/random.rb +30 -0
  243. data/lib/kinetic_sdk/version.rb +7 -0
  244. data/lib/kinetic_sdk.rb +57 -0
  245. metadata +414 -0
@@ -0,0 +1,36 @@
1
+ class ProgressBar
2
+ module Format
3
+ class String < ::String
4
+ MOLECULE_PATTERN = /%[a-zA-Z]/
5
+ ANSI_SGR_PATTERN = /\e\[[\d;]+m/
6
+
7
+ def displayable_length
8
+ gsub(ANSI_SGR_PATTERN, '').length
9
+ end
10
+
11
+ def bar_molecule_placeholder_length
12
+ @bar_molecule_placeholder_length ||= bar_molecules.size * 2
13
+ end
14
+
15
+ def non_bar_molecules
16
+ @non_bar_molecules ||= molecules.select(&:non_bar_molecule?)
17
+ end
18
+
19
+ def bar_molecules
20
+ @bar_molecules ||= molecules.select(&:bar_molecule?)
21
+ end
22
+
23
+ def molecules
24
+ @molecules ||= begin
25
+ molecules = []
26
+
27
+ scan(MOLECULE_PATTERN) do |match|
28
+ molecules << Molecule.new(match[1, 1])
29
+ end
30
+
31
+ molecules
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,3 @@
1
+ require 'ruby-progressbar/format/molecule'
2
+ require 'ruby-progressbar/format/formatter'
3
+ require 'ruby-progressbar/format/string'
@@ -0,0 +1,68 @@
1
+ class ProgressBar
2
+ class Output
3
+ DEFAULT_OUTPUT_STREAM = $stdout
4
+
5
+ attr_accessor :stream
6
+
7
+ def initialize(options = {})
8
+ self.bar = options[:bar]
9
+ self.stream = options[:output] || DEFAULT_OUTPUT_STREAM
10
+ self.throttle = Throttle.new(options)
11
+ self.length_calculator = Calculators::Length.new(
12
+ :length => options[:length],
13
+ :output => stream
14
+ )
15
+ end
16
+
17
+ def self.detect(options = {})
18
+ if options[:output].is_a?(Class) && options[:output] <= ProgressBar::Output
19
+ options[:output].new(options)
20
+ elsif (options[:output] || DEFAULT_OUTPUT_STREAM).tty?
21
+ Outputs::Tty.new(options)
22
+ else
23
+ Outputs::NonTty.new(options)
24
+ end
25
+ end
26
+
27
+ def log(string)
28
+ clear
29
+ stream.puts string
30
+
31
+ refresh(:force => true) unless bar.stopped?
32
+ end
33
+
34
+ def clear_string
35
+ ' ' * length_calculator.length
36
+ end
37
+
38
+ def length
39
+ length_calculator.length
40
+ end
41
+
42
+ def with_refresh
43
+ yield
44
+ refresh
45
+ end
46
+
47
+ def refresh(options = {})
48
+ throttle.choke(:force_update_if => (bar.stopped? || options[:force])) do
49
+ clear if length_calculator.length_changed?
50
+
51
+ print_and_flush
52
+ end
53
+ end
54
+
55
+ protected
56
+
57
+ attr_accessor :length_calculator,
58
+ :throttle,
59
+ :bar
60
+
61
+ private
62
+
63
+ def print_and_flush
64
+ stream.print bar_update_string + eol
65
+ stream.flush
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,47 @@
1
+ require 'ruby-progressbar/output'
2
+
3
+ class ProgressBar
4
+ module Outputs
5
+ class NonTty < Output
6
+ DEFAULT_FORMAT_STRING = '%t: |%b|'.freeze
7
+
8
+ def clear
9
+ self.last_update_length = 0
10
+
11
+ stream.print "\n"
12
+ end
13
+
14
+ def last_update_length
15
+ @last_update_length ||= 0
16
+ end
17
+
18
+ def bar_update_string
19
+ formatted_string = bar.to_s
20
+ formatted_string = formatted_string[0...-1] unless bar.finished?
21
+
22
+ output_string = formatted_string[last_update_length..-1]
23
+ self.last_update_length = formatted_string.length
24
+
25
+ output_string
26
+ end
27
+
28
+ def default_format
29
+ DEFAULT_FORMAT_STRING
30
+ end
31
+
32
+ def resolve_format(*)
33
+ default_format
34
+ end
35
+
36
+ def refresh_with_format_change(*); end
37
+
38
+ def eol
39
+ bar.stopped? ? "\n" : ''
40
+ end
41
+
42
+ protected
43
+
44
+ attr_writer :last_update_length
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,33 @@
1
+ require 'ruby-progressbar/output'
2
+
3
+ class ProgressBar
4
+ module Outputs
5
+ class Null < Output
6
+ alias refresh_with_format_change with_refresh
7
+
8
+ def clear; end
9
+ def log(_string); end
10
+ def refresh(*); end
11
+
12
+ def clear_string
13
+ ''
14
+ end
15
+
16
+ def bar_update_string
17
+ ''
18
+ end
19
+
20
+ def default_format
21
+ ''
22
+ end
23
+
24
+ def resolve_format(_format)
25
+ ''
26
+ end
27
+
28
+ def eol
29
+ ''
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,32 @@
1
+ require 'ruby-progressbar/output'
2
+
3
+ class ProgressBar
4
+ module Outputs
5
+ class Tty < Output
6
+ DEFAULT_FORMAT_STRING = '%t: |%B|'.freeze
7
+
8
+ alias refresh_with_format_change with_refresh
9
+
10
+ def clear
11
+ stream.print clear_string
12
+ stream.print "\r"
13
+ end
14
+
15
+ def bar_update_string
16
+ bar.to_s
17
+ end
18
+
19
+ def default_format
20
+ DEFAULT_FORMAT_STRING
21
+ end
22
+
23
+ def resolve_format(other_format)
24
+ other_format || default_format
25
+ end
26
+
27
+ def eol
28
+ bar.stopped? ? "\n" : "\r"
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,118 @@
1
+ require 'ruby-progressbar/errors/invalid_progress_error'
2
+
3
+ class ProgressBar
4
+ class Progress
5
+ DEFAULT_TOTAL = 100
6
+ DEFAULT_BEGINNING_POSITION = 0
7
+ DEFAULT_SMOOTHING = 0.1
8
+
9
+ attr_reader :total,
10
+ :progress
11
+
12
+ attr_accessor :starting_position,
13
+ :running_average,
14
+ :smoothing
15
+
16
+ def initialize(options = {})
17
+ self.total = options.fetch(:total, DEFAULT_TOTAL)
18
+ self.smoothing = options[:smoothing] || DEFAULT_SMOOTHING
19
+
20
+ start :at => DEFAULT_BEGINNING_POSITION
21
+ end
22
+
23
+ def start(options = {})
24
+ self.running_average = 0
25
+ self.progress = \
26
+ self.starting_position = options[:at] || progress
27
+ end
28
+
29
+ def finish
30
+ self.progress = total unless unknown?
31
+ end
32
+
33
+ def finished?
34
+ @progress == @total
35
+ end
36
+
37
+ def increment
38
+ if progress == total
39
+ warn "WARNING: Your progress bar is currently at #{progress} out of #{total} " \
40
+ "and cannot be incremented. In v2.0.0 this will become a " \
41
+ "ProgressBar::InvalidProgressError."
42
+ end
43
+
44
+ self.progress += 1 unless progress == total
45
+ end
46
+
47
+ def decrement
48
+ if progress == 0
49
+ warn "WARNING: Your progress bar is currently at #{progress} out of #{total} " \
50
+ "and cannot be decremented. In v2.0.0 this will become a " \
51
+ "ProgressBar::InvalidProgressError."
52
+ end
53
+
54
+ self.progress -= 1 unless progress == 0
55
+ end
56
+
57
+ def reset
58
+ start :at => starting_position
59
+ end
60
+
61
+ def progress=(new_progress)
62
+ if total && new_progress > total
63
+ fail ProgressBar::InvalidProgressError,
64
+ "You can't set the item's current value to be greater than the total."
65
+ end
66
+
67
+ @progress = new_progress
68
+
69
+ self.running_average = Calculators::RunningAverage.calculate(running_average,
70
+ absolute,
71
+ smoothing)
72
+ end
73
+
74
+ def total=(new_total)
75
+ unless progress.nil? || new_total.nil? || new_total >= progress
76
+ fail ProgressBar::InvalidProgressError,
77
+ "You can't set the item's total value to less than the current progress."
78
+ end
79
+
80
+ @total = new_total
81
+ end
82
+
83
+ def percentage_completed
84
+ return 0 if total.nil?
85
+ return 100 if total == 0
86
+
87
+ # progress / total * 100
88
+ #
89
+ # Doing this way so we can avoid converting each
90
+ # number to a float and then back to an integer.
91
+ #
92
+ (progress * 100 / total).to_i
93
+ end
94
+
95
+ def none?
96
+ running_average.zero? || progress.zero?
97
+ end
98
+
99
+ def unknown?
100
+ progress.nil? || total.nil?
101
+ end
102
+
103
+ def total_with_unknown_indicator
104
+ total || '??'
105
+ end
106
+
107
+ def percentage_completed_with_precision
108
+ return 100.0 if total == 0
109
+ return 0.0 if total.nil?
110
+
111
+ '%5.2f' % [(progress * 100 / total.to_f * 100).floor / 100.0]
112
+ end
113
+
114
+ def absolute
115
+ progress - starting_position
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,25 @@
1
+ class ProgressBar
2
+ module Refinements
3
+ module Enumerator
4
+ refine ::Enumerator do
5
+ # rubocop:disable Metrics/BlockNesting
6
+ def with_progressbar(options = {}, &block)
7
+ chain = ::Enumerator.new do |yielder|
8
+ progress_bar = ProgressBar.create(options.merge(:starting_at => 0, :total => size))
9
+
10
+ each do |*args|
11
+ yielder.yield(*args).tap do
12
+ progress_bar.increment
13
+ end
14
+ end
15
+ end
16
+
17
+ return chain unless block_given?
18
+
19
+ chain.each(&block)
20
+ end
21
+ # rubocop:enable Metrics/BlockNesting
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1 @@
1
+ require 'ruby-progressbar/refinements/enumerator'
@@ -0,0 +1,25 @@
1
+ class ProgressBar
2
+ class Throttle
3
+ attr_accessor :rate,
4
+ :started_at,
5
+ :stopped_at,
6
+ :timer
7
+
8
+ def initialize(options = {})
9
+ self.rate = options[:throttle_rate] || 0.01
10
+ self.started_at = nil
11
+ self.stopped_at = nil
12
+ self.timer = options.fetch(:throttle_timer, Timer.new)
13
+ end
14
+
15
+ def choke(options = {})
16
+ return unless !timer.started? ||
17
+ options.fetch(:force_update_if, false) ||
18
+ timer.elapsed_seconds >= rate
19
+
20
+ timer.restart
21
+
22
+ yield
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,30 @@
1
+ class ProgressBar
2
+ class Time
3
+ TIME_MOCKING_LIBRARY_METHODS = [
4
+ :__simple_stub__now, # ActiveSupport
5
+ :now_without_mock_time, # Timecop
6
+ :now_without_delorean, # Delorean
7
+ :now # Actual
8
+ ].freeze
9
+
10
+ def initialize(time = ::Time)
11
+ self.time = time
12
+ end
13
+
14
+ def now
15
+ time.__send__ unmocked_time_method
16
+ end
17
+
18
+ def unmocked_time_method
19
+ @unmocked_time_method ||= begin
20
+ TIME_MOCKING_LIBRARY_METHODS.find do |method|
21
+ time.respond_to? method
22
+ end
23
+ end
24
+ end
25
+
26
+ protected
27
+
28
+ attr_accessor :time
29
+ end
30
+ end
@@ -0,0 +1,72 @@
1
+ require 'ruby-progressbar/time'
2
+
3
+ class ProgressBar
4
+ class Timer
5
+ attr_accessor :started_at,
6
+ :stopped_at
7
+
8
+ def initialize(options = {})
9
+ self.time = options[:time] || Time.new
10
+ end
11
+
12
+ def start
13
+ self.started_at = stopped? ? time.now - (stopped_at - started_at) : time.now
14
+ self.stopped_at = nil
15
+ end
16
+
17
+ def stop
18
+ return unless started?
19
+
20
+ self.stopped_at = time.now
21
+ end
22
+
23
+ def pause
24
+ stop
25
+ end
26
+
27
+ def resume
28
+ start
29
+ end
30
+
31
+ def started?
32
+ started_at
33
+ end
34
+
35
+ def stopped?
36
+ stopped_at
37
+ end
38
+
39
+ def reset
40
+ self.started_at = nil
41
+ self.stopped_at = nil
42
+ end
43
+
44
+ def reset?
45
+ !started_at
46
+ end
47
+
48
+ def restart
49
+ reset
50
+ start
51
+ end
52
+
53
+ def elapsed_seconds
54
+ ((stopped_at || time.now) - started_at)
55
+ end
56
+
57
+ def elapsed_whole_seconds
58
+ elapsed_seconds.floor
59
+ end
60
+
61
+ def divide_seconds(seconds)
62
+ hours, seconds = seconds.divmod(3600)
63
+ minutes, seconds = seconds.divmod(60)
64
+
65
+ [hours, minutes, seconds]
66
+ end
67
+
68
+ protected
69
+
70
+ attr_accessor :time
71
+ end
72
+ end
@@ -0,0 +1,3 @@
1
+ class ProgressBar
2
+ VERSION = '1.9.0'.freeze
3
+ end
@@ -0,0 +1,18 @@
1
+ require 'ruby-progressbar/output'
2
+ require 'ruby-progressbar/outputs/tty'
3
+ require 'ruby-progressbar/outputs/non_tty'
4
+ require 'ruby-progressbar/timer'
5
+ require 'ruby-progressbar/progress'
6
+ require 'ruby-progressbar/throttle'
7
+ require 'ruby-progressbar/calculators/length'
8
+ require 'ruby-progressbar/calculators/running_average'
9
+ require 'ruby-progressbar/components'
10
+ require 'ruby-progressbar/format'
11
+ require 'ruby-progressbar/base'
12
+ require 'ruby-progressbar/refinements' unless RUBY_VERSION.start_with?('1.')
13
+
14
+ class ProgressBar
15
+ def self.create(*args)
16
+ ProgressBar::Base.new(*args)
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ A slugifier that converts utf-8 latin characters to their ascii counterpart.
2
+ All non-recognized characters are removed, only lowercase alfanumerical characters
3
+ and dashes are left. Also has an option to strip away starting, ending and double dashes.
4
+
5
+ Conversion is based on http://en.wikipedia.org/wiki/Latin_characters_in_Unicode
6
+
7
+ To use, just install it
8
+
9
+ gem install slugify
10
+
11
+ require it
12
+
13
+ require 'slugify'
14
+
15
+ and use it
16
+
17
+ "test test".slugify
18
+