ehbrs-tools 0.27.0 → 0.28.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (171) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -0
  3. data/Gemfile.lock +91 -38
  4. data/lib/ehbrs/tools/runner/fs/selected.rb +2 -6
  5. data/lib/ehbrs/tools/runner/music/lyrics.rb +3 -4
  6. data/lib/ehbrs/tools/runner/music/lyrics_book.rb +41 -0
  7. data/lib/ehbrs/tools/runner/music/selected.rb +6 -6
  8. data/lib/ehbrs/tools/runner/vg/wii.rb +2 -2
  9. data/lib/ehbrs/tools/runner/videos/series/rename.rb +1 -1
  10. data/lib/ehbrs/tools/version.rb +1 -1
  11. data/lib/ehbrs/user_dirs.rb +2 -2
  12. data/lib/ehbrs/videos/unsupported/search.rb +2 -2
  13. data/spec/lib/ehbrs/tools/runner/fs/used_space_spec.rb +2 -1
  14. data/vendor/aranha-parsers/aranha-parsers.gemspec +1 -0
  15. data/vendor/aranha-parsers/lib/aranha/parsers/base.rb +3 -1
  16. data/vendor/aranha-parsers/lib/aranha/parsers/html/node/default/numeric_support.rb +70 -0
  17. data/vendor/aranha-parsers/lib/aranha/parsers/html/node/default/string_support.rb +77 -0
  18. data/vendor/aranha-parsers/lib/aranha/parsers/html/node/default.rb +2 -94
  19. data/vendor/aranha-parsers/lib/aranha/parsers/json/base.rb +20 -0
  20. data/vendor/aranha-parsers/lib/aranha/parsers/json.rb +11 -0
  21. data/vendor/aranha-parsers/lib/aranha/parsers/source_address/http_get.rb +12 -15
  22. data/vendor/aranha-parsers/lib/aranha/parsers/version.rb +1 -1
  23. data/vendor/eac_cli/lib/eac_cli/config.rb +6 -3
  24. data/vendor/eac_cli/lib/eac_cli/version.rb +1 -1
  25. data/vendor/eac_fs/Gemfile +5 -0
  26. data/vendor/eac_fs/eac_fs.gemspec +20 -0
  27. data/vendor/{eac_ruby_utils/lib/eac_ruby_utils/filesystem_cache.rb → eac_fs/lib/eac_fs/cache.rb} +7 -2
  28. data/vendor/eac_fs/lib/eac_fs/cached_download.rb +39 -0
  29. data/vendor/eac_fs/lib/eac_fs/file_info.rb +29 -0
  30. data/vendor/eac_fs/lib/eac_fs/patches/module/fs_cache.rb +10 -0
  31. data/vendor/eac_fs/lib/eac_fs/patches/module.rb +4 -0
  32. data/vendor/eac_fs/lib/eac_fs/patches/object/fs_cache.rb +17 -0
  33. data/vendor/eac_fs/lib/eac_fs/patches/object.rb +4 -0
  34. data/vendor/eac_fs/lib/eac_fs/patches/pathname/info.rb +12 -0
  35. data/vendor/eac_fs/lib/eac_fs/patches/pathname.rb +4 -0
  36. data/vendor/eac_fs/lib/eac_fs/patches.rb +4 -0
  37. data/vendor/eac_fs/lib/eac_fs/traversable.rb +45 -0
  38. data/vendor/eac_fs/lib/eac_fs/traverser.rb +76 -0
  39. data/vendor/eac_fs/lib/eac_fs/version.rb +5 -0
  40. data/vendor/eac_fs/lib/eac_fs.rb +7 -0
  41. data/vendor/{eac_ruby_utils/spec/lib/eac_ruby_utils/filesystem_cache_spec.rb → eac_fs/spec/lib/eac_fs/cache_spec.rb} +2 -2
  42. data/vendor/eac_fs/spec/rubocop_spec.rb +3 -0
  43. data/vendor/eac_fs/spec/spec_helper.rb +4 -0
  44. data/vendor/eac_ruby_base0/eac_ruby_base0.gemspec +2 -1
  45. data/vendor/eac_ruby_base0/lib/eac_ruby_base0/application.rb +5 -5
  46. data/vendor/eac_ruby_base0/lib/eac_ruby_base0/core_ext.rb +1 -0
  47. data/vendor/eac_ruby_base0/lib/eac_ruby_base0/runner.rb +16 -7
  48. data/vendor/eac_ruby_base0/lib/eac_ruby_base0/runner_with/confirmation.rb +0 -1
  49. data/vendor/eac_ruby_base0/lib/eac_ruby_base0/runner_with/filesystem_traverser.rb +2 -2
  50. data/vendor/eac_ruby_base0/lib/eac_ruby_base0/version.rb +1 -1
  51. data/vendor/eac_ruby_gems_utils/Gemfile +5 -0
  52. data/vendor/eac_ruby_gems_utils/LICENCE +16 -0
  53. data/vendor/eac_ruby_gems_utils/README.rdoc +3 -0
  54. data/vendor/eac_ruby_gems_utils/eac_ruby_gems_utils.gemspec +30 -0
  55. data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/gem/command.rb +33 -0
  56. data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/gem/version_file.rb +41 -0
  57. data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/gem.rb +97 -0
  58. data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/tests/base.rb +57 -0
  59. data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/tests/minitest.rb +25 -0
  60. data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/tests/multiple/decorated_gem.rb +48 -0
  61. data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/tests/multiple/result.rb +25 -0
  62. data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/tests/multiple.rb +84 -0
  63. data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/tests/rspec.rb +21 -0
  64. data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/tests.rb +9 -0
  65. data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/version.rb +5 -0
  66. data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils.rb +7 -0
  67. data/vendor/eac_ruby_gems_utils/spec/code/rubocop_check_spec.rb +3 -0
  68. data/vendor/eac_ruby_gems_utils/spec/lib/eac_ruby_gems_utils/gem/version_file_spec.rb +14 -0
  69. data/vendor/eac_ruby_gems_utils/spec/lib/eac_ruby_gems_utils/gem/version_file_spec_files/a_version_file.rb +7 -0
  70. data/vendor/eac_ruby_gems_utils/spec/lib/eac_ruby_gems_utils/gem_spec.rb +20 -0
  71. data/vendor/eac_ruby_gems_utils/spec/spec_helper.rb +4 -0
  72. data/vendor/eac_ruby_gems_utils/spec/support/mygem/Gemfile +5 -0
  73. data/vendor/eac_ruby_gems_utils/spec/support/mygem/Gemfile.lock +19 -0
  74. data/vendor/eac_ruby_gems_utils/spec/support/mygem/Rakefile +14 -0
  75. data/vendor/eac_ruby_gems_utils/spec/support/mygem/exe/myrunner +5 -0
  76. data/vendor/eac_ruby_gems_utils/spec/support/mygem/lib/mygem/version.rb +5 -0
  77. data/vendor/eac_ruby_gems_utils/spec/support/mygem/lib/mygem.rb +5 -0
  78. data/vendor/eac_ruby_gems_utils/spec/support/mygem/mygem.gemspec +16 -0
  79. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/abstract_methods.rb +7 -0
  80. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/core_ext.rb +1 -0
  81. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/gems_registry/gem.rb +4 -0
  82. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/gems_registry.rb +1 -1
  83. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/class/abstract.rb +9 -0
  84. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/class/self_included_modules.rb +7 -0
  85. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/i18n_translate.rb +32 -0
  86. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/call_if_proc.rb +11 -0
  87. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/i18n_translate.rb +13 -0
  88. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/speaker/receiver.rb +10 -10
  89. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
  90. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/class/abstract_spec.rb +25 -0
  91. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/class/self_included_modules_spec.rb +30 -0
  92. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/object/call_if_proc_spec.rb +11 -0
  93. data/vendor/eac_templates/Gemfile +5 -0
  94. data/vendor/eac_templates/eac_templates.gemspec +19 -0
  95. data/vendor/eac_templates/lib/eac_templates/directory.rb +108 -0
  96. data/vendor/eac_templates/lib/eac_templates/file.rb +48 -0
  97. data/vendor/eac_templates/lib/eac_templates/patches/module/erb_template.rb +9 -0
  98. data/vendor/eac_templates/lib/eac_templates/patches/module/template.rb +10 -0
  99. data/vendor/eac_templates/lib/eac_templates/patches/module.rb +4 -0
  100. data/vendor/eac_templates/lib/eac_templates/patches/object/erb_template.rb +9 -0
  101. data/vendor/eac_templates/lib/eac_templates/patches/object/template.rb +9 -0
  102. data/vendor/eac_templates/lib/eac_templates/patches/object.rb +4 -0
  103. data/vendor/eac_templates/lib/eac_templates/patches.rb +4 -0
  104. data/vendor/eac_templates/lib/eac_templates/searcher.rb +53 -0
  105. data/vendor/eac_templates/lib/eac_templates/variable_not_found_error.rb +5 -0
  106. data/vendor/eac_templates/lib/eac_templates/variable_providers/base.rb +21 -0
  107. data/vendor/eac_templates/lib/eac_templates/variable_providers/config_reader.rb +27 -0
  108. data/vendor/eac_templates/lib/eac_templates/variable_providers/entries_reader.rb +23 -0
  109. data/vendor/eac_templates/lib/eac_templates/variable_providers/generic.rb +23 -0
  110. data/vendor/eac_templates/lib/eac_templates/variable_providers/hash.rb +27 -0
  111. data/vendor/eac_templates/lib/eac_templates/variable_providers.rb +23 -0
  112. data/vendor/eac_templates/lib/eac_templates/version.rb +5 -0
  113. data/vendor/eac_templates/lib/eac_templates.rb +7 -0
  114. data/vendor/eac_templates/spec/lib/eac_templates/file_spec.rb +35 -0
  115. data/vendor/eac_templates/spec/lib/eac_templates/file_spec_files/expected_content +2 -0
  116. data/vendor/eac_templates/spec/lib/eac_templates/file_spec_files/source.template +2 -0
  117. data/vendor/eac_templates/spec/lib/eac_templates/searcher_spec.rb +30 -0
  118. data/vendor/eac_templates/spec/lib/eac_templates/searcher_spec_files/path1/subdir1/file1.template +1 -0
  119. data/vendor/eac_templates/spec/lib/eac_templates/searcher_spec_files/path1/subdir1/file2 +1 -0
  120. data/vendor/eac_templates/spec/lib/eac_templates/searcher_spec_files/path2/subdir1/file3.template +1 -0
  121. data/vendor/eac_templates/spec/lib/object/template_spec.rb +23 -0
  122. data/vendor/eac_templates/spec/lib/object/template_spec_files/path/my_stub_with_template +1 -0
  123. data/vendor/eac_templates/spec/rubocop_spec.rb +3 -0
  124. data/vendor/eac_templates/spec/spec_helper.rb +4 -0
  125. data/vendor/ehbrs_ruby_utils/ehbrs_ruby_utils.gemspec +1 -0
  126. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/core_ext.rb +5 -0
  127. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/fs/compressed_package.rb +2 -2
  128. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/fs/selected/build.rb +1 -1
  129. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/fs/selected/build_file.rb +1 -1
  130. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/fs/selected.rb +13 -3
  131. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/music/lyrics_book/album.rb +42 -0
  132. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/music/lyrics_book/resource.rb +64 -0
  133. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/music/lyrics_book/song.rb +68 -0
  134. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/music/lyrics_book.rb +65 -0
  135. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/patches/object.rb +4 -0
  136. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/patches.rb +4 -0
  137. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/version.rb +1 -1
  138. data/vendor/ehbrs_ruby_utils/template/ehbrs_ruby_utils/music/lyrics_book/album/inner.html.erb +3 -0
  139. data/vendor/ehbrs_ruby_utils/template/ehbrs_ruby_utils/music/lyrics_book/custom_style.css +15 -0
  140. data/vendor/ehbrs_ruby_utils/template/ehbrs_ruby_utils/music/lyrics_book/index.html.erb +14 -0
  141. data/vendor/ehbrs_ruby_utils/template/ehbrs_ruby_utils/music/lyrics_book/main.html.erb +24 -0
  142. data/vendor/ehbrs_ruby_utils/template/ehbrs_ruby_utils/music/lyrics_book/resource/main.html.erb +8 -0
  143. data/vendor/ehbrs_ruby_utils/template/ehbrs_ruby_utils/music/lyrics_book/song/inner.html.erb +9 -0
  144. data/vendor/ultimate_lyrics/lib/ultimate_lyrics/provider.rb +4 -0
  145. data/vendor/ultimate_lyrics/lib/ultimate_lyrics/provider_search.rb +1 -1
  146. data/vendor/ultimate_lyrics/lib/ultimate_lyrics/providers_data.xml +2 -1
  147. data/vendor/ultimate_lyrics/lib/ultimate_lyrics/version.rb +1 -1
  148. data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/encyclopaedia_metallum__michael_jackson_thriller.target.yaml +1 -1
  149. data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/encyclopaedia_metallum__milton_nascimento_rouxinol.target.yaml +1 -1
  150. data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/hindilyrics_net_bollywood_songs__michael_jackson_thriller.source.html +18 -18
  151. data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/hindilyrics_net_bollywood_songs__michael_jackson_thriller.target.yaml +1 -1
  152. data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/hindilyrics_net_bollywood_songs__milton_nascimento_rouxinol.source.html +18 -18
  153. data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/hindilyrics_net_bollywood_songs__milton_nascimento_rouxinol.target.yaml +1 -1
  154. data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/lyrics_com__milton_nascimento_rouxinol.target.yaml +1 -3
  155. data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/lyricsplugin_com__michael_jackson_thriller.target.yaml +1 -1
  156. data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/lyricsplugin_com__milton_nascimento_rouxinol.target.yaml +1 -1
  157. data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/lyricsreg_com__milton_nascimento_rouxinol.source.html +3 -3
  158. data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/lyricsreg_com__milton_nascimento_rouxinol.target.yaml +1 -1
  159. data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/mp3lyrics_org__michael_jackson_thriller.source.html +3 -3
  160. data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/mp3lyrics_org__michael_jackson_thriller.target.yaml +1 -1
  161. data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/mp3lyrics_org__milton_nascimento_rouxinol.source.html +3 -3
  162. data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/mp3lyrics_org__milton_nascimento_rouxinol.target.yaml +1 -1
  163. data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/songlyrics_com__michael_jackson_thriller.source.html +15 -12
  164. data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/songlyrics_com__michael_jackson_thriller.target.yaml +1 -1
  165. metadata +107 -10
  166. data/lib/ehbrs/patches/module/erb_template.rb +0 -11
  167. data/lib/ehbrs/patches/object/erb_template.rb +0 -9
  168. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/traversable.rb +0 -47
  169. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/traverser.rb +0 -72
  170. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs_cache.rb +0 -12
  171. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/on_clean_ruby_environment.rb +0 -12
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.push File.expand_path('lib', __dir__)
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'mygem'
7
+ s.version = '1.0.0'
8
+ s.authors = ['Esquilo Azul Company']
9
+ s.summary = 'Stub gem.'
10
+
11
+ s.files = Dir['{exe,lib}/**/*', 'Gemfile', 'Rakefile']
12
+ s.bindir = 'exe'
13
+ s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
14
+
15
+ s.add_dependency 'rake'
16
+ end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'eac_ruby_utils/patches/class/self_included_modules'
3
4
  require 'eac_ruby_utils/patches/module/common_concern'
4
5
 
5
6
  module EacRubyUtils
@@ -27,6 +28,12 @@ module EacRubyUtils
27
28
  module AbstractMethods
28
29
  common_concern
29
30
 
31
+ class << self
32
+ def abstract?(a_class)
33
+ a_class.self_included_modules.include?(::EacRubyUtils::AbstractMethods)
34
+ end
35
+ end
36
+
30
37
  module ClassMethods
31
38
  def abstract_methods(*methods_names)
32
39
  methods_names.each do |method_name|
@@ -3,3 +3,4 @@
3
3
  require 'eac_ruby_utils/patches'
4
4
  require 'active_support/dependencies/autoload'
5
5
  require 'active_support/core_ext'
6
+ require 'active_support/json'
@@ -57,6 +57,10 @@ module EacRubyUtils
57
57
  gemspec.name.gsub('-', '/') + '/' + registry.module_suffix.underscore
58
58
  end
59
59
 
60
+ def to_s
61
+ "#{self.class.name}[#{gemspec.name}]"
62
+ end
63
+
60
64
  private
61
65
 
62
66
  def dependencies_uncached
@@ -21,7 +21,7 @@ module EacRubyUtils
21
21
 
22
22
  # @return [Array<EacRubyUtils::GemsRegistry::Gem>]
23
23
  def registered
24
- @registered ||= all_gems.select(&:found?)
24
+ @registered ||= all_gems.select(&:found?).sort
25
25
  end
26
26
 
27
27
  private
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/abstract_methods'
4
+
5
+ class Class
6
+ def abstract?
7
+ ::EacRubyUtils::AbstractMethods.abstract?(self)
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Class
4
+ def self_included_modules
5
+ ancestors.take_while { |a| a != superclass }.select { |ancestor| ancestor.instance_of?(Module) }
6
+ end
7
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/core_ext/string/inflections'
4
+ require 'i18n'
5
+
6
+ class Module
7
+ TRANSLATE_LOCALE_KEY = :__locale
8
+
9
+ def i18n_translate(entry_suffix, values = {})
10
+ on_i18n_locale(values.delete(TRANSLATE_LOCALE_KEY)) do
11
+ ::I18n.translate(i18n_translate_entry_full(entry_suffix), values)
12
+ end
13
+ end
14
+
15
+ def i18n_translate_entry_full(entry_suffix)
16
+ "#{i18n_translate_entry_self_prefix}.#{entry_suffix}"
17
+ end
18
+
19
+ def i18n_translate_entry_self_prefix
20
+ name.underscore.gsub('/', '.')
21
+ end
22
+
23
+ def on_i18n_locale(locale)
24
+ old_locale = ::I18n.locale
25
+ begin
26
+ ::I18n.locale = locale
27
+ yield
28
+ ensure
29
+ ::I18n.locale = old_locale
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/compact'
4
+
5
+ class Object
6
+ # If +self+ is a Proc, return the value of +.call+. If not, return +self+.
7
+ # @return [Object]
8
+ def call_if_proc
9
+ is_a?(::Proc) ? call : self
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/patches/module/i18n_translate'
4
+
5
+ class Object
6
+ def i18n_translate(entry_suffix, values = {})
7
+ self.class.i18n_translate(entry_suffix, values)
8
+ end
9
+
10
+ def on_i18n_locale(locale)
11
+ self.class.on_i18n_locale(locale)
12
+ end
13
+ end
@@ -8,7 +8,7 @@ module EacRubyUtils
8
8
  extend ::EacRubyUtils::AbstractMethods
9
9
 
10
10
  def error(_string)
11
- raise_abstract_method(__FILE__)
11
+ raise_abstract_method(__method__)
12
12
  end
13
13
 
14
14
  def fatal_error(string)
@@ -18,39 +18,39 @@ module EacRubyUtils
18
18
 
19
19
  # @see EacRubyUtils::Speaker::Sender.input
20
20
  def input(_question, _options = {})
21
- raise_abstract_method(__FILE__)
21
+ raise_abstract_method(__method__)
22
22
  end
23
23
 
24
24
  def info(_string)
25
- raise_abstract_method(__FILE__)
25
+ raise_abstract_method(__method__)
26
26
  end
27
27
 
28
28
  def infom(_string)
29
- raise_abstract_method(__FILE__)
29
+ raise_abstract_method(__method__)
30
30
  end
31
31
 
32
32
  def infov(*_args)
33
- raise_abstract_method(__FILE__)
33
+ raise_abstract_method(__method__)
34
34
  end
35
35
 
36
36
  def out(_string = '')
37
- raise_abstract_method(__FILE__)
37
+ raise_abstract_method(__method__)
38
38
  end
39
39
 
40
40
  def puts(_string = '')
41
- raise_abstract_method(__FILE__)
41
+ raise_abstract_method(__method__)
42
42
  end
43
43
 
44
44
  def success(_string)
45
- raise_abstract_method(__FILE__)
45
+ raise_abstract_method(__method__)
46
46
  end
47
47
 
48
48
  def title(_string)
49
- raise_abstract_method(__FILE__)
49
+ raise_abstract_method(__method__)
50
50
  end
51
51
 
52
52
  def warn(_string)
53
- raise_abstract_method(__FILE__)
53
+ raise_abstract_method(__method__)
54
54
  end
55
55
  end
56
56
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyUtils
4
- VERSION = '0.75.0'
4
+ VERSION = '0.79.0'
5
5
  end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/patches/class/abstract'
4
+
5
+ RSpec.describe ::Class do
6
+ let(:abstract_class) do
7
+ described_class.new do
8
+ enable_abstract_methods
9
+ end
10
+ end
11
+
12
+ let(:concrect_class) do
13
+ described_class.new(abstract_class)
14
+ end
15
+
16
+ describe '#abstract' do
17
+ it do
18
+ expect(abstract_class).to be_abstract
19
+ end
20
+
21
+ it do
22
+ expect(concrect_class).not_to be_abstract
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/patches/class/self_included_modules'
4
+
5
+ RSpec.describe ::Class do
6
+ let(:includeable_module) do
7
+ ::Module.new
8
+ end
9
+
10
+ let(:parent_class) do
11
+ module_to_include = includeable_module
12
+ described_class.new do
13
+ include module_to_include
14
+ end
15
+ end
16
+
17
+ let(:child_class) do
18
+ described_class.new(parent_class)
19
+ end
20
+
21
+ describe '#self_included_modules' do
22
+ it do
23
+ expect(parent_class.self_included_modules).to include(includeable_module)
24
+ end
25
+
26
+ it do
27
+ expect(child_class.self_included_modules).not_to include(includeable_module)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/patches/object/call_if_proc'
4
+
5
+ RSpec.describe ::Object do
6
+ describe '#call_if_proc' do
7
+ it { expect(nil.call_if_proc).to eq(nil) }
8
+ it { expect('a string'.call_if_proc).to eq('a string') }
9
+ it { expect(-> { 'a returned value' }.call_if_proc).to eq('a returned value') }
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.push File.expand_path('lib', __dir__)
4
+
5
+ require 'eac_templates/version'
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = 'eac_templates'
9
+ s.version = EacTemplates::VERSION
10
+ s.authors = ['Put here the authors']
11
+ s.summary = 'Put here de description.'
12
+
13
+ s.files = Dir['{lib}/**/*']
14
+
15
+ s.add_dependency 'eac_config', '~> 0.5'
16
+ s.add_dependency 'eac_ruby_utils', '~> 0.64'
17
+
18
+ s.add_development_dependency 'eac_ruby_gem_support', '~> 0.2'
19
+ end
@@ -0,0 +1,108 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_templates/file'
4
+
5
+ module EacTemplates
6
+ class Directory
7
+ TEMPLATE_EXTNAME = '.template'
8
+
9
+ attr_reader :path
10
+
11
+ def initialize(path)
12
+ @path = path.is_a?(::Pathname) ? path : ::Pathname.new(path.to_s)
13
+ end
14
+
15
+ def apply(variables_source, directory)
16
+ TemplateNode.new(self, '.', directory, variables_source).apply
17
+ end
18
+
19
+ def child(subpath)
20
+ child_path = ::File.join(path, subpath)
21
+ return ::EacTemplates::File.new(child_path) if ::File.file?(child_path)
22
+ return ::EacTemplates::Directory.new(child_path) if ::File.directory?(child_path)
23
+
24
+ raise "Child \"#{subpath}\" from \"#{path}\" not found"
25
+ end
26
+
27
+ def children
28
+ path.children.map do |path_child|
29
+ child(path_child.basename.to_path)
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def apply_fs_object(source_relative, target)
36
+ if ::File.directory?(source_absolute(source_relative))
37
+ apply_directory(source_relative, target)
38
+ elsif ::File.file?(source_absolute(source_relative))
39
+ end
40
+ end
41
+
42
+ def source_absolute(source_relative)
43
+ ::File.expand_path(source_relative, path)
44
+ end
45
+
46
+ class TemplateNode
47
+ attr_reader :source_directory, :source_relative, :target_root_directory, :variables_source
48
+
49
+ def initialize(source_directory, source_relative, target_root_directory, variables_source)
50
+ @source_directory = source_directory
51
+ @source_relative = source_relative
52
+ @target_root_directory = target_root_directory
53
+ @variables_source = variables_source
54
+ end
55
+
56
+ def apply
57
+ if file?
58
+ apply_file
59
+ elsif directory?
60
+ apply_directory
61
+ else
62
+ raise "Unknown filesystem type: #{source_absolute}"
63
+ end
64
+ end
65
+
66
+ private
67
+
68
+ def apply_directory
69
+ ::FileUtils.mkdir_p(target_absolute)
70
+ Dir.entries(source_absolute).each do |entry|
71
+ child(entry).apply unless %w[. ..].include?(entry)
72
+ end
73
+ end
74
+
75
+ def apply_file
76
+ if ::File.extname(source_absolute) == TEMPLATE_EXTNAME
77
+ ::EacTemplates::File.new(source_absolute).apply_to_file(
78
+ variables_source, target_absolute
79
+ )
80
+ else
81
+ ::FileUtils.cp(source_absolute, target_absolute)
82
+ end
83
+ end
84
+
85
+ def child(entry)
86
+ TemplateNode.new(source_directory, ::File.join(source_relative, entry),
87
+ target_root_directory, variables_source)
88
+ end
89
+
90
+ def file?
91
+ ::File.file?(source_absolute)
92
+ end
93
+
94
+ def directory?
95
+ ::File.directory?(source_absolute)
96
+ end
97
+
98
+ def source_absolute
99
+ ::File.expand_path(source_relative, source_directory.path)
100
+ end
101
+
102
+ def target_absolute
103
+ ::File.expand_path(source_relative, target_root_directory)
104
+ .gsub(/#{::Regexp.quote(TEMPLATE_EXTNAME)}\z/, '')
105
+ end
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'eac_templates/variable_providers'
5
+
6
+ module EacTemplates
7
+ class File
8
+ VARIABLE_DELIMITER = ::Regexp.quote('%%')
9
+ VARIABLE_PATTERN = /#{VARIABLE_DELIMITER}([a-z0-9\._]*)#{VARIABLE_DELIMITER}/i.freeze
10
+
11
+ enable_simple_cache
12
+ common_constructor :path do
13
+ self.path = path.to_pathname
14
+ end
15
+
16
+ # +variables_provider+ A [Hash] or object which responds to +read_entry(entry_name)+.
17
+ def apply(variables_source)
18
+ variables_provider = ::EacTemplates::VariableProviders.build(variables_source)
19
+ variables.inject(content) do |a, e|
20
+ a.gsub(variable_pattern(e), variables_provider.variable_value(e).to_s)
21
+ end
22
+ end
23
+
24
+ def apply_to_file(variables_source, output_file_path)
25
+ output_file_path.to_pathname.write(apply(variables_source))
26
+ end
27
+
28
+ private
29
+
30
+ def variables_uncached
31
+ content.scan(VARIABLE_PATTERN).map(&:first).map do |name|
32
+ sanitize_variable_name(name)
33
+ end.to_set
34
+ end
35
+
36
+ def content_uncached
37
+ path.read
38
+ end
39
+
40
+ def sanitize_variable_name(variable_name)
41
+ variable_name.to_s.downcase
42
+ end
43
+
44
+ def variable_pattern(name)
45
+ /#{VARIABLE_DELIMITER}#{::Regexp.quote(name)}#{VARIABLE_DELIMITER}/i
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'erb'
4
+
5
+ class Module
6
+ def erb_template(subpath, binding_obj)
7
+ ::ERB.new(template.child(subpath).path.read).result(binding_obj)
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/core_ext/string/inflections'
4
+ require 'eac_templates/searcher'
5
+
6
+ class Module
7
+ def template
8
+ @template ||= ::EacTemplates::Searcher.default.template(name.underscore)
9
+ end
10
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/require_sub'
4
+ ::EacRubyUtils.require_sub __FILE__
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_templates/patches/module/erb_template'
4
+
5
+ class Object
6
+ def erb_template(subpath, binding_obj = nil)
7
+ self.class.erb_template(subpath, binding_obj || binding)
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_templates/patches/module/template'
4
+
5
+ class Object
6
+ def template
7
+ self.class.template
8
+ end
9
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/require_sub'
4
+ ::EacRubyUtils.require_sub __FILE__
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/require_sub'
4
+ ::EacRubyUtils.require_sub __FILE__
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/core_ext/object/blank'
4
+ require 'eac_templates/directory'
5
+ require 'eac_templates/file'
6
+
7
+ module EacTemplates
8
+ class Searcher
9
+ class << self
10
+ def default
11
+ @default ||= new
12
+ end
13
+ end
14
+
15
+ def template(subpath, required = true)
16
+ path = template_path(subpath)
17
+ if path.blank?
18
+ return nil unless required
19
+
20
+ raise_template_not_found(subpath)
21
+ end
22
+ return ::EacTemplates::File.new(path) if ::File.file?(path)
23
+ return ::EacTemplates::Directory.new(path) if ::File.directory?(path)
24
+
25
+ raise 'Invalid branching'
26
+ end
27
+
28
+ # @return The absolute path of template if found, +nil+ otherwise.
29
+ def template_path(subpath)
30
+ included_paths.each do |included_path|
31
+ r = search_template_in_included_path(included_path, subpath)
32
+ return r if r
33
+ end
34
+ nil
35
+ end
36
+
37
+ def included_paths
38
+ @included_paths ||= ::Set.new
39
+ end
40
+
41
+ private
42
+
43
+ def raise_template_not_found(subpath)
44
+ raise "Template not found for subpath \"#{subpath}\"" \
45
+ " (Included paths: #{included_paths.to_a.join(::File::PATH_SEPARATOR)})"
46
+ end
47
+
48
+ def search_template_in_included_path(included_path, subpath)
49
+ path = ::File.join(included_path, subpath)
50
+ ::File.exist?(path) ? path : nil
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacTemplates
4
+ class VariableNotFoundError < StandardError; end
5
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_templates/variable_not_found_error'
4
+
5
+ module EacTemplates
6
+ module VariableProviders
7
+ class Base
8
+ attr_reader :source
9
+
10
+ def initialize(source)
11
+ @source = source
12
+ end
13
+
14
+ def variable_value(name)
15
+ return variable_fetch(name) if variable_exist?(name)
16
+
17
+ raise VariableNotFoundError, "Variable \"#{name}\" not found in #{source}"
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_config/node'
4
+ require 'eac_templates/variable_providers/base'
5
+
6
+ module EacTemplates
7
+ module VariableProviders
8
+ class ConfigReader < ::EacTemplates::VariableProviders::Base
9
+ class << self
10
+ def accept?(variables_source)
11
+ return false unless variables_source.respond_to?(:entry)
12
+
13
+ entry = variables_source.entry(:any_value)
14
+ entry.respond_to?(:value) && entry.respond_to?(:found?)
15
+ end
16
+ end
17
+
18
+ def variable_exist?(name)
19
+ source.entry(name).found?
20
+ end
21
+
22
+ def variable_fetch(name)
23
+ source.entry(name).value
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_templates/variable_providers/base'
4
+
5
+ module EacTemplates
6
+ module VariableProviders
7
+ class EntriesReader < ::EacTemplates::VariableProviders::Base
8
+ class << self
9
+ def accept?(variables_source)
10
+ variables_source.respond_to?(:read_entry)
11
+ end
12
+ end
13
+
14
+ def variable_exist?(_name)
15
+ true
16
+ end
17
+
18
+ def variable_fetch(name)
19
+ source.read_entry(name)
20
+ end
21
+ end
22
+ end
23
+ end