eac_tools 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (228) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +20 -14
  3. data/lib/eac_tools/version.rb +1 -1
  4. data/sub/avm/lib/avm/sources/base/configuration.rb +14 -6
  5. data/sub/avm/lib/avm/sources/base/testing.rb +50 -7
  6. data/sub/avm/lib/avm/sources/tests/builder.rb +8 -1
  7. data/sub/avm/lib/avm/sources/tests/single.rb +28 -9
  8. data/sub/avm/lib/avm/version.rb +1 -1
  9. data/sub/avm-eac_generic_base0/Gemfile +3 -0
  10. data/sub/avm-eac_generic_base0/avm-eac_generic_base0.gemspec +3 -3
  11. data/sub/avm-eac_generic_base0/lib/avm/eac_generic_base0/sources/base.rb +0 -6
  12. data/sub/avm-eac_generic_base0/lib/avm/eac_generic_base0/version.rb +1 -1
  13. data/sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/sources/base.rb +15 -7
  14. data/sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/version.rb +1 -1
  15. data/sub/eac_ruby_utils/Gemfile +16 -0
  16. data/sub/eac_ruby_utils/MIT-LICENCE +16 -0
  17. data/sub/eac_ruby_utils/README.rdoc +3 -0
  18. data/sub/eac_ruby_utils/eac_ruby_utils.gemspec +24 -0
  19. data/sub/eac_ruby_utils/lib/eac_ruby_utils/abstract_methods.rb +68 -0
  20. data/sub/eac_ruby_utils/lib/eac_ruby_utils/arguments_consumer.rb +81 -0
  21. data/sub/eac_ruby_utils/lib/eac_ruby_utils/bit.rb +46 -0
  22. data/sub/eac_ruby_utils/lib/eac_ruby_utils/bit_array.rb +81 -0
  23. data/sub/eac_ruby_utils/lib/eac_ruby_utils/blank_not_blank.rb +19 -0
  24. data/sub/eac_ruby_utils/lib/eac_ruby_utils/boolean.rb +31 -0
  25. data/sub/eac_ruby_utils/lib/eac_ruby_utils/by_reference.rb +23 -0
  26. data/sub/eac_ruby_utils/lib/eac_ruby_utils/byte.rb +105 -0
  27. data/sub/eac_ruby_utils/lib/eac_ruby_utils/byte_array.rb +36 -0
  28. data/sub/eac_ruby_utils/lib/eac_ruby_utils/common_concern/class_setup.rb +52 -0
  29. data/sub/eac_ruby_utils/lib/eac_ruby_utils/common_concern/module_setup.rb +41 -0
  30. data/sub/eac_ruby_utils/lib/eac_ruby_utils/common_concern.rb +20 -0
  31. data/sub/eac_ruby_utils/lib/eac_ruby_utils/common_constructor/class_initialize.rb +29 -0
  32. data/sub/eac_ruby_utils/lib/eac_ruby_utils/common_constructor/instance_initialize.rb +53 -0
  33. data/sub/eac_ruby_utils/lib/eac_ruby_utils/common_constructor/super_args.rb +54 -0
  34. data/sub/eac_ruby_utils/lib/eac_ruby_utils/common_constructor.rb +89 -0
  35. data/sub/eac_ruby_utils/lib/eac_ruby_utils/compact.rb +22 -0
  36. data/sub/eac_ruby_utils/lib/eac_ruby_utils/compare_by.rb +28 -0
  37. data/sub/eac_ruby_utils/lib/eac_ruby_utils/context.rb +33 -0
  38. data/sub/eac_ruby_utils/lib/eac_ruby_utils/contextualizable.rb +21 -0
  39. data/sub/eac_ruby_utils/lib/eac_ruby_utils/core_ext.rb +7 -0
  40. data/sub/eac_ruby_utils/lib/eac_ruby_utils/custom_format.rb +53 -0
  41. data/sub/eac_ruby_utils/lib/eac_ruby_utils/enum.rb +102 -0
  42. data/sub/eac_ruby_utils/lib/eac_ruby_utils/envs/base_env.rb +28 -0
  43. data/sub/eac_ruby_utils/lib/eac_ruby_utils/envs/command/concat.rb +33 -0
  44. data/sub/eac_ruby_utils/lib/eac_ruby_utils/envs/command/envvars.rb +24 -0
  45. data/sub/eac_ruby_utils/lib/eac_ruby_utils/envs/command/extra_options.rb +33 -0
  46. data/sub/eac_ruby_utils/lib/eac_ruby_utils/envs/command.rb +172 -0
  47. data/sub/eac_ruby_utils/lib/eac_ruby_utils/envs/executable.rb +81 -0
  48. data/sub/eac_ruby_utils/lib/eac_ruby_utils/envs/file.rb +22 -0
  49. data/sub/eac_ruby_utils/lib/eac_ruby_utils/envs/local_env.rb +17 -0
  50. data/sub/eac_ruby_utils/lib/eac_ruby_utils/envs/process.rb +27 -0
  51. data/sub/eac_ruby_utils/lib/eac_ruby_utils/envs/spawn.rb +32 -0
  52. data/sub/eac_ruby_utils/lib/eac_ruby_utils/envs/ssh_env/dasho_options.rb +53 -0
  53. data/sub/eac_ruby_utils/lib/eac_ruby_utils/envs/ssh_env/identity_file.rb +25 -0
  54. data/sub/eac_ruby_utils/lib/eac_ruby_utils/envs/ssh_env/quiet.rb +24 -0
  55. data/sub/eac_ruby_utils/lib/eac_ruby_utils/envs/ssh_env/terminal.rb +34 -0
  56. data/sub/eac_ruby_utils/lib/eac_ruby_utils/envs/ssh_env.rb +75 -0
  57. data/sub/eac_ruby_utils/lib/eac_ruby_utils/envs.rb +23 -0
  58. data/sub/eac_ruby_utils/lib/eac_ruby_utils/fs/clearable_directory.rb +57 -0
  59. data/sub/eac_ruby_utils/lib/eac_ruby_utils/fs/extname.rb +30 -0
  60. data/sub/eac_ruby_utils/lib/eac_ruby_utils/fs/temp/directory.rb +16 -0
  61. data/sub/eac_ruby_utils/lib/eac_ruby_utils/fs/temp/file.rb +34 -0
  62. data/sub/eac_ruby_utils/lib/eac_ruby_utils/fs/temp.rb +52 -0
  63. data/sub/eac_ruby_utils/lib/eac_ruby_utils/fs.rb +9 -0
  64. data/sub/eac_ruby_utils/lib/eac_ruby_utils/gems_registry/gem.rb +79 -0
  65. data/sub/eac_ruby_utils/lib/eac_ruby_utils/gems_registry.rb +35 -0
  66. data/sub/eac_ruby_utils/lib/eac_ruby_utils/immutable/array_accessor.rb +32 -0
  67. data/sub/eac_ruby_utils/lib/eac_ruby_utils/immutable/base_accessor.rb +23 -0
  68. data/sub/eac_ruby_utils/lib/eac_ruby_utils/immutable/boolean_accessor.rb +16 -0
  69. data/sub/eac_ruby_utils/lib/eac_ruby_utils/immutable/class_methods.rb +20 -0
  70. data/sub/eac_ruby_utils/lib/eac_ruby_utils/immutable/common_accessor.rb +30 -0
  71. data/sub/eac_ruby_utils/lib/eac_ruby_utils/immutable/hash_accessor.rb +46 -0
  72. data/sub/eac_ruby_utils/lib/eac_ruby_utils/immutable/instance_methods.rb +21 -0
  73. data/sub/eac_ruby_utils/lib/eac_ruby_utils/immutable.rb +15 -0
  74. data/sub/eac_ruby_utils/lib/eac_ruby_utils/inflector.rb +29 -0
  75. data/sub/eac_ruby_utils/lib/eac_ruby_utils/listable/class_methods.rb +14 -0
  76. data/sub/eac_ruby_utils/lib/eac_ruby_utils/listable/instance_methods.rb +30 -0
  77. data/sub/eac_ruby_utils/lib/eac_ruby_utils/listable/integer_list.rb +23 -0
  78. data/sub/eac_ruby_utils/lib/eac_ruby_utils/listable/list.rb +111 -0
  79. data/sub/eac_ruby_utils/lib/eac_ruby_utils/listable/lists.rb +59 -0
  80. data/sub/eac_ruby_utils/lib/eac_ruby_utils/listable/string_list.rb +19 -0
  81. data/sub/eac_ruby_utils/lib/eac_ruby_utils/listable/symbol_list.rb +19 -0
  82. data/sub/eac_ruby_utils/lib/eac_ruby_utils/listable/value.rb +49 -0
  83. data/sub/eac_ruby_utils/lib/eac_ruby_utils/listable.rb +17 -0
  84. data/sub/eac_ruby_utils/lib/eac_ruby_utils/local_time_zone.rb +48 -0
  85. data/sub/eac_ruby_utils/lib/eac_ruby_utils/locales/from_all_gems.rb +4 -0
  86. data/sub/eac_ruby_utils/lib/eac_ruby_utils/locales/from_gem.rb +47 -0
  87. data/sub/eac_ruby_utils/lib/eac_ruby_utils/locales/module_i18n_translate.rb +74 -0
  88. data/sub/eac_ruby_utils/lib/eac_ruby_utils/locales.rb +9 -0
  89. data/sub/eac_ruby_utils/lib/eac_ruby_utils/method_class.rb +35 -0
  90. data/sub/eac_ruby_utils/lib/eac_ruby_utils/options_consumer.rb +62 -0
  91. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patch.rb +11 -0
  92. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/class/abstract.rb +9 -0
  93. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/class/common_constructor.rb +9 -0
  94. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/class/self_included_modules.rb +7 -0
  95. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/class/settings_provider.rb +10 -0
  96. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/class.rb +4 -0
  97. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerable/boolean_combinations.rb +45 -0
  98. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerable.rb +4 -0
  99. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerator/current.rb +9 -0
  100. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerator/stopped.rb +14 -0
  101. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerator.rb +4 -0
  102. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/hash/options_consumer.rb +10 -0
  103. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/hash/sym_keys_hash.rb +10 -0
  104. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/hash/to_struct.rb +10 -0
  105. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/hash.rb +5 -0
  106. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/kernel/nyi.rb +10 -0
  107. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/kernel.rb +4 -0
  108. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/module/abstract_methods.rb +10 -0
  109. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/module/common_concern.rb +9 -0
  110. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/module/compare_by.rb +9 -0
  111. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/module/context.rb +11 -0
  112. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/module/i18n_translate.rb +9 -0
  113. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/module/immutable.rb +10 -0
  114. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/module/listable.rb +10 -0
  115. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/module/method_class.rb +9 -0
  116. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/module/patch.rb +9 -0
  117. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/module/require_sub.rb +9 -0
  118. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/module/simple_cache.rb +10 -0
  119. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/module/speaker.rb +9 -0
  120. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/module.rb +4 -0
  121. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/asserts.rb +25 -0
  122. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/call_if_proc.rb +11 -0
  123. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/compact.rb +20 -0
  124. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/debug.rb +23 -0
  125. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/i18n_translate.rb +13 -0
  126. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_nil.rb +17 -0
  127. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_present.rb +19 -0
  128. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_respond.rb +22 -0
  129. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/to_pathname.rb +15 -0
  130. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/to_uri.rb +15 -0
  131. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object.rb +5 -0
  132. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/pathname/basename_noext.rb +10 -0
  133. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/pathname/basename_sub.rb +9 -0
  134. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/pathname/if_exist.rb +10 -0
  135. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/pathname/mkpath_s.rb +12 -0
  136. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/pathname/parent_n.rb +11 -0
  137. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/pathname/readlink_r.rb +11 -0
  138. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/pathname/reqdir_glob.rb +13 -0
  139. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/pathname.rb +4 -0
  140. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/regexp/if_match.rb +16 -0
  141. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/regexp/to_parser.rb +10 -0
  142. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/regexp.rb +4 -0
  143. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/string/delimited.rb +16 -0
  144. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/string/inflector.rb +11 -0
  145. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/string.rb +4 -0
  146. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/time/required_zone.rb +11 -0
  147. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/time.rb +4 -0
  148. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches.rb +4 -0
  149. data/sub/eac_ruby_utils/lib/eac_ruby_utils/recursive_builder.rb +51 -0
  150. data/sub/eac_ruby_utils/lib/eac_ruby_utils/regexp_parser.rb +34 -0
  151. data/sub/eac_ruby_utils/lib/eac_ruby_utils/require_sub.rb +134 -0
  152. data/sub/eac_ruby_utils/lib/eac_ruby_utils/rspec/default_setup.rb +20 -0
  153. data/sub/eac_ruby_utils/lib/eac_ruby_utils/rspec/setup/conditionals.rb +17 -0
  154. data/sub/eac_ruby_utils/lib/eac_ruby_utils/rspec/setup.rb +12 -0
  155. data/sub/eac_ruby_utils/lib/eac_ruby_utils/rspec/setup_manager.rb +49 -0
  156. data/sub/eac_ruby_utils/lib/eac_ruby_utils/rspec/stub_speaker.rb +39 -0
  157. data/sub/eac_ruby_utils/lib/eac_ruby_utils/rspec.rb +9 -0
  158. data/sub/eac_ruby_utils/lib/eac_ruby_utils/ruby/command.rb +32 -0
  159. data/sub/eac_ruby_utils/lib/eac_ruby_utils/ruby/on_clean_environment.rb +38 -0
  160. data/sub/eac_ruby_utils/lib/eac_ruby_utils/ruby.rb +9 -0
  161. data/sub/eac_ruby_utils/lib/eac_ruby_utils/settings_provider/setting_value.rb +69 -0
  162. data/sub/eac_ruby_utils/lib/eac_ruby_utils/settings_provider.rb +46 -0
  163. data/sub/eac_ruby_utils/lib/eac_ruby_utils/simple_cache.rb +77 -0
  164. data/sub/eac_ruby_utils/lib/eac_ruby_utils/speaker/receiver.rb +64 -0
  165. data/sub/eac_ruby_utils/lib/eac_ruby_utils/speaker/sender.rb +32 -0
  166. data/sub/eac_ruby_utils/lib/eac_ruby_utils/speaker.rb +16 -0
  167. data/sub/eac_ruby_utils/lib/eac_ruby_utils/string_delimited.rb +70 -0
  168. data/sub/eac_ruby_utils/lib/eac_ruby_utils/struct.rb +63 -0
  169. data/sub/eac_ruby_utils/lib/eac_ruby_utils/version.rb +5 -0
  170. data/sub/eac_ruby_utils/lib/eac_ruby_utils/yaml.rb +105 -0
  171. data/sub/eac_ruby_utils/lib/eac_ruby_utils.rb +6 -0
  172. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/abstract_methods_spec.rb +28 -0
  173. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/arguments_consumer_spec.rb +17 -0
  174. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/bit_array_spec.rb +22 -0
  175. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/blank_not_blank_spec.rb +16 -0
  176. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/byte_spec.rb +54 -0
  177. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/common_concern_spec.rb +65 -0
  178. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/common_constructor_spec.rb +125 -0
  179. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/compact_spec.rb +20 -0
  180. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/compare_by_spec.rb +38 -0
  181. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/custom_format_spec.rb +60 -0
  182. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/enum_spec.rb +43 -0
  183. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/envs/executable_spec.rb +37 -0
  184. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/envs/ssh_env_spec.rb +25 -0
  185. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/fs/extname_spec.rb +18 -0
  186. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/fs/temp/directory_spec.rb +12 -0
  187. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/fs/temp_spec.rb +52 -0
  188. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/inflector_spec.rb +16 -0
  189. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/listable_spec.rb +275 -0
  190. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/local_time_zone_spec.rb +17 -0
  191. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/method_class_spec.rb +46 -0
  192. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/options_consumer_spec.rb +80 -0
  193. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/class/abstract_spec.rb +25 -0
  194. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/class/self_included_modules_spec.rb +30 -0
  195. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/enumerable/boolean_combinations_spec.rb +39 -0
  196. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/enumerator/current_spec.rb +26 -0
  197. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/enumerator/stopped_spec.rb +32 -0
  198. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/hash/options_consumer_spec.rb +17 -0
  199. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/hash/sym_keys_hash_spec.rb +13 -0
  200. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/module/compare_by_spec.rb +36 -0
  201. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/module/listable_spec.rb +15 -0
  202. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/module/method_class_spec.rb +20 -0
  203. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/module/simple_cache_spec.rb +15 -0
  204. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/module/speaker_spec.rb +13 -0
  205. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/object/call_if_proc_spec.rb +11 -0
  206. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/object/compact_spec.rb +20 -0
  207. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/object/if_present_spec.rb +13 -0
  208. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/object/template_spec_files/path/my_stub_with_template +1 -0
  209. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/pathname/basename_noext_spec.rb +26 -0
  210. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/pathname/basename_sub_spec.rb +17 -0
  211. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/pathname/parent_n_spec.rb +33 -0
  212. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/string/delimited_spec.rb +34 -0
  213. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/recursive_builder_spec.rb +65 -0
  214. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/require_sub_spec/stubbed_module_a.rb +6 -0
  215. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/require_sub_spec/stubbed_not_module.rb +6 -0
  216. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/require_sub_spec.rb +19 -0
  217. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/ruby_spec.rb +22 -0
  218. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/settings_provider_spec.rb +57 -0
  219. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/simple_cache_spec.rb +129 -0
  220. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/struct_spec.rb +57 -0
  221. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/yaml_spec.rb +75 -0
  222. data/sub/eac_ruby_utils/spec/locales/pt-BR.yml +58 -0
  223. data/sub/eac_ruby_utils/spec/rubocop_check_spec.rb +3 -0
  224. data/sub/eac_ruby_utils/spec/spec_helper.rb +15 -0
  225. metadata +218 -23
  226. data/sub/avm/lib/avm/sources/tester.rb +0 -24
  227. data/sub/avm-eac_generic_base0/lib/avm/eac_generic_base0/sources/tester.rb +0 -56
  228. data/sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/sources/tester.rb +0 -36
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 52be2b949c88f70cad235bb01bab0f0155f1093364f0328a83ec022bcd5446e9
4
- data.tar.gz: b9b1dcf2119964ebe0052931f853579bbce9dc274412a780075dfc1df24cf550
3
+ metadata.gz: 9f62da51457512bc25b5321faa19507d05bd3fa231950ef6cfcbf39f70809f39
4
+ data.tar.gz: 641dc2b412c60738c9d5acb21d217cdcb5459430501c63498114d0336a6b7465
5
5
  SHA512:
6
- metadata.gz: 9bfcb9a6e13b090f254550a6c3b0f563f0d5c61fdef6227e29c660bec2f2d419803dbed1655ae29945f1c82d0f26e0f9c76408a74718f92d2817e749fb339ec2
7
- data.tar.gz: 34bf06360e871a1e7a88275da9222fb6ea92a75b0e177cb0ce6ff87c2bce3ee8412d7564dcfa045a9acc8cc90f2783d11241f4b3921b205433e937b29b605320
6
+ metadata.gz: a5a9048310a062489b32ecf8578dfdfad82a3d8ee9d7da42fdd1ea368d1c31d218828ff62641ce5b755a944f4310e268d85bff1f2adacf6c932bdbe47f1ae3ac
7
+ data.tar.gz: 82da69b9433611450a88634316e05e162d3af4fccb9da97b51747fe42fcfd535f2462111ab9152e56ffd07d04c55381b0297cfefce1b0f6b0249c4405a45d1ff
data/Gemfile.lock CHANGED
@@ -1,21 +1,21 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- eac_tools (0.3.0)
5
- avm-eac_generic_base0 (~> 0.2, >= 0.2.2)
4
+ eac_tools (0.4.0)
5
+ avm-eac_generic_base0 (~> 0.3)
6
6
  avm-eac_rails_base1 (~> 0.3, >= 0.3.1)
7
7
  avm-eac_redmine_base0 (~> 0.8)
8
8
  avm-eac_redmine_plugin_base0 (~> 0.1, >= 0.1.1)
9
- avm-eac_ruby_base1 (~> 0.8, >= 0.8.2)
9
+ avm-eac_ruby_base1 (~> 0.9)
10
10
  avm-tools (~> 0.121)
11
- eac_ruby_utils (~> 0.95, >= 0.95.1)
11
+ eac_ruby_utils (~> 0.95, >= 0.95.2)
12
12
 
13
13
  PATH
14
14
  remote: sub/avm-eac_generic_base0
15
15
  specs:
16
- avm-eac_generic_base0 (0.2.2)
17
- avm (~> 0.19)
18
- eac_ruby_utils (~> 0.80)
16
+ avm-eac_generic_base0 (0.3.0)
17
+ avm (~> 0.24)
18
+ eac_ruby_utils (~> 0.05, >= 0.95.2)
19
19
 
20
20
  PATH
21
21
  remote: sub/avm-eac_rails_base1
@@ -46,7 +46,7 @@ PATH
46
46
  PATH
47
47
  remote: sub/avm-eac_ruby_base1
48
48
  specs:
49
- avm-eac_ruby_base1 (0.8.2)
49
+ avm-eac_ruby_base1 (0.9.0)
50
50
  avm (~> 0.23)
51
51
  avm-eac_generic_base0 (~> 0.2)
52
52
  eac_ruby_utils (~> 0.95, >= 0.95.1)
@@ -73,7 +73,7 @@ PATH
73
73
  PATH
74
74
  remote: sub/avm
75
75
  specs:
76
- avm (0.23.0)
76
+ avm (0.24.0)
77
77
  eac_cli (~> 0.27, >= 0.27.6)
78
78
  eac_docker (~> 0.3)
79
79
  eac_git (~> 0.6)
@@ -108,6 +108,16 @@ PATH
108
108
  eac_fs (~> 0.10)
109
109
  eac_ruby_utils (~> 0.95, >= 0.95.1)
110
110
 
111
+ PATH
112
+ remote: sub/eac_ruby_utils
113
+ specs:
114
+ eac_ruby_utils (0.95.2)
115
+ activesupport (>= 4, < 7)
116
+ addressable (~> 2.6)
117
+ bundler
118
+ filesize
119
+ net-ssh (~> 4.2)
120
+
111
121
  GEM
112
122
  remote: https://rubygems.org/
113
123
  specs:
@@ -185,11 +195,6 @@ GEM
185
195
  rubocop (~> 0.80.1)
186
196
  rubocop-rails (~> 2.4.2)
187
197
  rubocop-rspec (~> 1.38.1)
188
- eac_ruby_utils (0.95.1)
189
- activesupport (>= 4, < 7)
190
- addressable (~> 2.6)
191
- filesize
192
- net-ssh (~> 4.2)
193
198
  eac_templates (0.3.1)
194
199
  eac_config (~> 0.5)
195
200
  eac_ruby_utils (~> 0.64)
@@ -300,6 +305,7 @@ DEPENDENCIES
300
305
  eac_fs!
301
306
  eac_ruby_base0!
302
307
  eac_ruby_gem_support (~> 0.5.1)
308
+ eac_ruby_utils!
303
309
  eac_tools!
304
310
 
305
311
  BUNDLED WITH
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacTools
4
- VERSION = '0.3.0'
4
+ VERSION = '0.4.0'
5
5
  end
@@ -11,19 +11,27 @@ module Avm
11
11
  module Configuration
12
12
  CONFIGURATION_FILENAMES = %w[.avm.yml .avm.yaml].freeze
13
13
 
14
+ # @return [EacRubyUtils::Envs::Command, nil]
15
+ def configuration_value_to_env_command(value)
16
+ configuration_value_to_shell_words(value).if_present { |v| env.command(v).chdir(path) }
17
+ end
18
+
19
+ # @return [Array<String>, nil]
20
+ def configuration_value_to_shell_words(value)
21
+ return nil if value.blank?
22
+
23
+ value.is_a?(::Enumerable) ? value.map(&:to_s) : ::Shellwords.split(value.to_s)
24
+ end
25
+
14
26
  # @return [Array<String>, nil]
15
27
  def read_configuration_as_shell_words(key)
16
- configuration.entry(key).value.if_present do |v|
17
- v.is_a?(::Enumerable) ? v.map(&:to_s) : ::Shellwords.split(v.to_s)
18
- end
28
+ configuration_value_to_shell_words(configuration.entry(key).value)
19
29
  end
20
30
 
21
31
  # Utility to read a configuration as a [EacRubyUtils::Envs::Command].
22
32
  # @return [EacRubyUtils::Envs::Command]
23
33
  def read_configuration_as_env_command(key)
24
- read_configuration_as_shell_words(key).if_present do |v|
25
- env.command(v).chdir(path)
26
- end
34
+ configuration_value_to_env_command(configuration.entry(key).value)
27
35
  end
28
36
 
29
37
  private
@@ -1,25 +1,68 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'eac_ruby_utils/core_ext'
4
+ require 'eac_ruby_utils/envs/command'
4
5
 
5
6
  module Avm
6
7
  module Sources
7
8
  class Base
8
9
  module Testing
9
- TEST_COMMAND_KEY = 'test.command'
10
+ DEFAULT_TEST_COMMANDS = {}.freeze
11
+ TEST_KEY = 'test'
12
+ TEST_COMMAND_KEY = "#{TEST_KEY}.command"
13
+ TEST_COMMANDS_KEY = "#{TEST_KEY}.commands"
10
14
 
11
15
  def configured_test_command
12
16
  read_configuration_as_env_command(TEST_COMMAND_KEY)
13
17
  end
14
18
 
15
- # @return [Avm::Sources::Tester]
16
- def tester
17
- tester_class.new(self)
19
+ # @return [Hash<String, EacRubyUtils::Envs::Command>, nil]
20
+ def configured_test_commands
21
+ configured_value_as_test_commands(configuration.entry(TEST_COMMANDS_KEY).value)
18
22
  end
19
23
 
20
- # @return [Class<Avm::Sources::Tester>
21
- def tester_class
22
- Avm::Sources::Tester
24
+ # @return [Hash<String, EacRubyUtils::Envs::Command>, nil]
25
+ def configured_value_as_test_commands(value)
26
+ return nil if value.blank?
27
+
28
+ [::EacRubyUtils::Envs::Command, ::Hash, ::Enumerable].each do |type|
29
+ next unless value.is_a?(type)
30
+
31
+ return send(
32
+ "configured_#{type.name.demodulize.variableize}_value_as_test_commands",
33
+ value
34
+ )
35
+ end
36
+
37
+ raise "Value for test commands should be a Hash or a Enumerable (Actual: #{value})"
38
+ end
39
+
40
+ # @return [Hash<String, EacRubyUtils::Envs::Command>]
41
+ def default_test_commands
42
+ DEFAULT_TEST_COMMANDS
43
+ end
44
+
45
+ # @return [Enumerable<EacRubyUtils::Envs::Command>]
46
+ def test_commands
47
+ configured_test_commands ||
48
+ configured_value_as_test_commands(configured_test_command)
49
+ default_test_commands
50
+ end
51
+
52
+ protected
53
+
54
+ def configured_command_value_as_test_commands(value)
55
+ configured_enumerable_value_as_test_commands([value])
56
+ end
57
+
58
+ def configured_enumerable_value_as_test_commands(value)
59
+ configured_hash_value_as_test_commands(
60
+ value.each_with_index.map { |v| ["test_#{v[1]}", v[0]] }.to_h
61
+ )
62
+ end
63
+
64
+ def configured_hash_value_as_test_commands(value)
65
+ value.map { |k, v| [k.to_s.strip, configuration_value_to_env_command(v)] }.to_h
23
66
  end
24
67
  end
25
68
  end
@@ -44,6 +44,13 @@ module Avm
44
44
  create_units(main_source.subs)
45
45
  end
46
46
 
47
+ # @return [Array<Avm::Sources::Tests::Single>]
48
+ def create_source_units(source)
49
+ source.test_commands.map do |test_name, test_command|
50
+ ::Avm::Sources::Tests::Single.new(self, source, test_name, test_command)
51
+ end
52
+ end
53
+
47
54
  # @return [Avm::Sources::Tests::Single]
48
55
  def create_unit(source)
49
56
  ::Avm::Sources::Tests::Single.new(self, source)
@@ -51,7 +58,7 @@ module Avm
51
58
 
52
59
  # @return [Array<Avm::Sources::Tests::Single>]
53
60
  def create_units(sources)
54
- sources.map { |a_source| create_unit(a_source) }
61
+ sources.flat_map { |a_source| create_source_units(a_source) }
55
62
  end
56
63
 
57
64
  # @return [Avm::Sources::Tests::Single]
@@ -14,9 +14,8 @@ module Avm
14
14
  enable_simple_cache
15
15
  enable_speaker
16
16
 
17
- common_constructor :builder, :source
17
+ common_constructor :builder, :source, :test_name, :test_command
18
18
 
19
- delegate :logs, :result, to: :tester
20
19
  delegate :to_s, to: :id
21
20
 
22
21
  def failed?
@@ -25,11 +24,7 @@ module Avm
25
24
 
26
25
  # @return [String]
27
26
  def id
28
- if main?
29
- MAIN_SOURCE_ID
30
- else
31
- relative_path_from_main_source.to_s
32
- end
27
+ "#{main? ? MAIN_SOURCE_ID : relative_path_from_main_source}\##{test_name}"
33
28
  end
34
29
 
35
30
  def main?
@@ -47,8 +42,32 @@ module Avm
47
42
 
48
43
  private
49
44
 
50
- def tester_uncached
51
- source.tester
45
+ # @return [EacFs::Logs]
46
+ def logs_uncached
47
+ ::EacFs::Logs.new.add(:stdout).add(:stderr)
48
+ end
49
+
50
+ # @return [Avm::Sources::Tests::Result]
51
+ def result_uncached
52
+ if test_command.blank?
53
+ ::Avm::Sources::Tests::Result::NONEXISTENT
54
+ elsif run_test_command
55
+ ::Avm::Sources::Tests::Result::SUCESSFUL
56
+ else
57
+ ::Avm::Sources::Tests::Result::FAILED
58
+ end
59
+ end
60
+
61
+ def run_test_command
62
+ execute_command_and_log(test_command)
63
+ end
64
+
65
+ # @return [true, false]
66
+ def execute_command_and_log(command)
67
+ r = command.execute
68
+ logs[:stdout].write(r[:stdout])
69
+ logs[:stderr].write(r[:stderr])
70
+ r[:exit_code].zero?
52
71
  end
53
72
  end
54
73
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Avm
4
- VERSION = '0.23.0'
4
+ VERSION = '0.24.0'
5
5
  end
@@ -3,3 +3,6 @@
3
3
  source 'https://rubygems.org'
4
4
 
5
5
  gemspec
6
+
7
+ local_gemfile = ::File.join(::File.dirname(__FILE__), 'Gemfile.local')
8
+ eval_gemfile local_gemfile if ::File.exist?(local_gemfile)
@@ -12,8 +12,8 @@ Gem::Specification.new do |s|
12
12
 
13
13
  s.files = Dir['{lib,locale}/**/*']
14
14
 
15
- s.add_dependency 'avm', '~> 0.19'
16
- s.add_dependency 'eac_ruby_utils', '~> 0.80'
15
+ s.add_dependency 'avm', '~> 0.24'
16
+ s.add_dependency 'eac_ruby_utils', '~> 0.05', '>= 0.95.2'
17
17
 
18
- s.add_development_dependency 'eac_ruby_gem_support', '~> 0.4'
18
+ s.add_development_dependency 'eac_ruby_gem_support', '~> 0.5.1'
19
19
  end
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'avm/eac_generic_base0/sources/tester'
4
3
  require 'avm/sources/base'
5
4
  require 'eac_ruby_utils/core_ext'
6
5
 
@@ -11,11 +10,6 @@ module Avm
11
10
  require_sub __FILE__, include_modules: true
12
11
  enable_abstract_methods
13
12
 
14
- # @return [Avm::EacGenericBase0::Sources::Tester]
15
- def tester_class
16
- Avm::EacGenericBase0::Sources::Tester
17
- end
18
-
19
13
  def valid?
20
14
  ::Avm::Registry.scms.detect_optional(path).present?
21
15
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Avm
4
4
  module EacGenericBase0
5
- VERSION = '0.2.2'
5
+ VERSION = '0.3.0'
6
6
  end
7
7
  end
@@ -3,7 +3,6 @@
3
3
  require 'avm/eac_generic_base0/sources/base'
4
4
  require 'avm/eac_ruby_base1/rubygems/version_file'
5
5
  require 'avm/eac_ruby_base1/sources/update'
6
- require 'avm/eac_ruby_base1/sources/tester'
7
6
  require 'avm/eac_ruby_base1/sources/runners/bundler'
8
7
  require 'avm/version_number'
9
8
  require 'eac_ruby_utils/core_ext'
@@ -12,12 +11,21 @@ module Avm
12
11
  module EacRubyBase1
13
12
  module Sources
14
13
  class Base < ::Avm::EacGenericBase0::Sources::Base
15
- require_sub __FILE__, include_modules: :prepend, require_dependency: true
14
+ RSPEC_TEST_COMMAND = 'rspec'
15
+
16
+ require_sub __FILE__, include_modules: :prepend
16
17
 
17
18
  # To-do: dismiss this method at Avm::EacRailsBase1::Instance and remove.
18
19
  # @return [EacRubyUtils::Envs::BaseEnv]
19
20
  attr_reader :env
20
21
 
22
+ # @return [Hash<String, EacRubyUtils::Envs::Command>]
23
+ def default_test_commands
24
+ {
25
+ RSPEC_TEST_COMMAND => rspec_test_command
26
+ }
27
+ end
28
+
21
29
  # To-do: dismiss this method at Avm::EacRailsBase1::Instance and remove.
22
30
  # @return [Avm::EacRubyBase1::Sources::Base]
23
31
  def env_set(env)
@@ -26,13 +34,13 @@ module Avm
26
34
  self
27
35
  end
28
36
 
29
- def valid?
30
- gemfile_path.exist? || gemspec_path.present?
37
+ # @return [EacRubyUtils::Envs::Command]
38
+ def rspec_test_command
39
+ bundle('exec', 'rspec', '--fail-fast').chdir_root
31
40
  end
32
41
 
33
- # @return [Avm::EacRubyBase1::Sources::Tester]
34
- def tester_class
35
- Avm::EacRubyBase1::Sources::Tester
42
+ def valid?
43
+ gemfile_path.exist? || gemspec_path.present?
36
44
  end
37
45
 
38
46
  def update
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Avm
4
4
  module EacRubyBase1
5
- VERSION = '0.8.2'
5
+ VERSION = '0.9.0'
6
6
  end
7
7
  end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Declare your gem's dependencies in users_support.gemspec.
6
+ # Bundler will treat runtime dependencies like base dependencies, and
7
+ # development dependencies will be added by default to the :development group.
8
+ gemspec
9
+
10
+ # Declare any dependencies that are still in development here instead of in
11
+ # your gemspec. These might include edge Rails or gems from your path or
12
+ # Git. Remember to move these dependencies to your gemspec before releasing
13
+ # your gem to rubygems.org.
14
+
15
+ # To use a debugger
16
+ # gem 'byebug', group: [:development, :test]
@@ -0,0 +1,16 @@
1
+ Copyright 2018 Eduardo Henrique Bogoni <eduardobogoni@gmail.com>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
4
+ associated documentation files (the "Software"), to deal in the Software without restriction,
5
+ including without limitation the rights to use, copy, modify, merge, publish, distribute,
6
+ sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
7
+ furnished to do so, subject to the following conditions:
8
+
9
+ The above copyright notice and this permission notice shall be included in all copies or substantial
10
+ portions of the Software.
11
+
12
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
13
+ NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
14
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
15
+ OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
16
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,3 @@
1
+ = E.A.C. Ruby Utilities
2
+
3
+ Utilities for E.A.C.'s Ruby projects.
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.push File.expand_path('lib', __dir__)
4
+
5
+ # Maintain your gem's version:
6
+ require 'eac_ruby_utils/version'
7
+
8
+ # Describe your gem and declare its dependencies:
9
+ Gem::Specification.new do |s|
10
+ s.name = 'eac_ruby_utils'
11
+ s.version = ::EacRubyUtils::VERSION
12
+ s.authors = ['Esquilo Azul Company']
13
+ s.summary = 'Utilities for E.A.C.\'s Ruby projects.'
14
+ s.license = 'MIT'
15
+
16
+ s.files = Dir['{lib}/**/*', 'MIT-LICENSE', 'README.rdoc']
17
+
18
+ s.add_dependency 'activesupport', '>= 4', '< 7'
19
+ s.add_dependency 'addressable', '~> 2.6'
20
+ s.add_dependency 'bundler'
21
+ s.add_dependency 'filesize'
22
+ s.add_dependency 'net-ssh', '~> 4.2'
23
+ s.add_development_dependency 'eac_ruby_gem_support', '~> 0.5.1'
24
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/patches/class/self_included_modules'
4
+ require 'eac_ruby_utils/patches/module/common_concern'
5
+
6
+ module EacRubyUtils
7
+ # Support to abstract methods.
8
+ #
9
+ # Usage:
10
+ #
11
+ # require 'eac_ruby_utils/abstract_methods'
12
+ #
13
+ # class BaseClass
14
+ # include EacRubyUtils::AbstractMethods
15
+ #
16
+ # abstract_methods :mymethod
17
+ # end
18
+ #
19
+ # BaseClass.new.mymethod # raise "Abstract method: mymethod"
20
+ #
21
+ # class SubClass
22
+ # def mymethod
23
+ # "Implemented"
24
+ # end
25
+ # end
26
+ #
27
+ # SubClass.new.mymethod # return "Implemented"
28
+ module AbstractMethods
29
+ common_concern
30
+
31
+ class << self
32
+ def abstract?(a_class)
33
+ a_class.self_included_modules.include?(::EacRubyUtils::AbstractMethods)
34
+ end
35
+ end
36
+
37
+ module ClassMethods
38
+ def abstract_methods(*methods_names)
39
+ methods_names.each do |method_name|
40
+ define_method method_name do
41
+ raise_abstract_method(method_name)
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ module InstanceMethods
48
+ def respond_to_missing?(method_name, include_private = false)
49
+ super || abstract_method?(method_name)
50
+ end
51
+
52
+ def method_missing(method_name, *arguments, &block)
53
+ raise_abstract_method(method_name) if abstract_method?(method_name)
54
+
55
+ super
56
+ end
57
+
58
+ def abstract_method?(method_name)
59
+ self.class.abstract_methods.include?(method_name.to_sym)
60
+ end
61
+
62
+ def raise_abstract_method(method_name)
63
+ raise ::NoMethodError, "Abstract method \"#{method_name}\" hit in \"#{self}\"" \
64
+ " (Class: #{self.class})"
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/hash_with_indifferent_access'
4
+ require 'ostruct'
5
+
6
+ module EacRubyUtils
7
+ class ArgumentsConsumer
8
+ class << self
9
+ def parse(args, positional = [], options = {})
10
+ new(args, positional, options).data
11
+ end
12
+ end
13
+
14
+ attr_reader :positional, :default_options
15
+
16
+ def initialize(positional, default_options)
17
+ @positional = positional.dup.freeze
18
+ @default_options = default_options.dup.freeze
19
+ end
20
+
21
+ def parse(args)
22
+ Parser.new(self, args).data
23
+ end
24
+
25
+ class Parser
26
+ attr_reader :data, :arguments_consumer
27
+
28
+ def initialize(arguments_consumer, args)
29
+ @arguments_consumer = arguments_consumer
30
+ @data = ::ActiveSupport::HashWithIndifferentAccess.new
31
+ @options_found = false
32
+ arguments_consumer.positional.each { |key| data[key] = nil }
33
+ data.merge!(arguments_consumer.default_options)
34
+ args.each_with_index { |value, index| add_arg(value, index) }
35
+ data.freeze
36
+ end
37
+
38
+ private
39
+
40
+ def add_arg(value, index)
41
+ arg = ::OpenStruct.new(value: value, index: index)
42
+ if arg.value.is_a?(::Hash)
43
+ add_hash_arg(arg)
44
+ else
45
+ add_positional_arg(arg)
46
+ end
47
+ end
48
+
49
+ def add_hash_arg(arg)
50
+ check_no_more_arguments(arg)
51
+ data.merge!(arg.value)
52
+ @options_found = true
53
+ end
54
+
55
+ def add_positional_arg(arg)
56
+ check_no_more_arguments(arg)
57
+ invalid_argument arg, 'No more valid positional' if
58
+ arg.index >= arguments_consumer.positional.count
59
+ data[arguments_consumer.positional[arg.index]] = arg.value
60
+ end
61
+
62
+ def check_no_more_arguments(arg)
63
+ return unless @options_found
64
+
65
+ invalid_argument arg, 'Hash already found - no more positional allowed'
66
+ end
67
+
68
+ def invalid_argument(arg, message)
69
+ raise InvalidArgumentError.new(self, arg, message)
70
+ end
71
+ end
72
+
73
+ class InvalidArgumentError < StandardError
74
+ def initialize(args_consumer, arg, message)
75
+ @args_consumer = args_consumer
76
+ @arg = arg
77
+ super "#{message} (Arg: #{arg}, Args Consumer: #{args_consumer})"
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/patches/module/compare_by'
4
+
5
+ module EacRubyUtils
6
+ class Bit
7
+ VALID_VALUES = [0, 1].freeze
8
+
9
+ class << self
10
+ def assert(obj)
11
+ return obj if obj.is_a?(self)
12
+
13
+ new(obj.to_i)
14
+ end
15
+
16
+ def valid_integer?(value)
17
+ value.is_a?(::Integer) && VALID_VALUES.include?(value)
18
+ end
19
+
20
+ def validate_integer(value)
21
+ return value if valid_integer?(value)
22
+
23
+ raise(::ArgumentError, "Invalid bit value: #{value} (Valid: #{VALID_VALUES})")
24
+ end
25
+ end
26
+
27
+ attr_reader :value
28
+ compare_by :value
29
+ delegate :to_s, :zero?, to: :value
30
+
31
+ # @param value [Integer]
32
+ def initialize(value)
33
+ @value = self.class.validate_integer(value)
34
+ end
35
+
36
+ # @return [Boolean]
37
+ def one?
38
+ !zero?
39
+ end
40
+
41
+ # @return [Integer]
42
+ def to_i
43
+ value
44
+ end
45
+ end
46
+ end