ehbrs-tools 0.11.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ehbrs/google.rb +9 -0
  3. data/lib/ehbrs/google/translate.rb +11 -0
  4. data/lib/ehbrs/google/translate/session.rb +61 -0
  5. data/lib/ehbrs/runner/google.rb +19 -0
  6. data/lib/ehbrs/runner/google/translate.rb +92 -0
  7. data/lib/ehbrs/tools/version.rb +1 -1
  8. data/vendor/aranha-selenium/Gemfile +5 -0
  9. data/vendor/aranha-selenium/aranha-selenium.gemspec +19 -0
  10. data/vendor/aranha-selenium/lib/aranha/selenium.rb +8 -0
  11. data/vendor/aranha-selenium/lib/aranha/selenium/driver_factory.rb +47 -0
  12. data/vendor/aranha-selenium/lib/aranha/selenium/driver_factory/base.rb +76 -0
  13. data/vendor/aranha-selenium/lib/aranha/selenium/driver_factory/chrome.rb +28 -0
  14. data/vendor/aranha-selenium/lib/aranha/selenium/driver_factory/firefox.rb +54 -0
  15. data/vendor/aranha-selenium/lib/aranha/selenium/driver_factory/firefox_auto_download_mime_types +685 -0
  16. data/vendor/aranha-selenium/lib/aranha/selenium/session.rb +78 -0
  17. data/vendor/aranha-selenium/lib/aranha/selenium/version.rb +7 -0
  18. data/vendor/aranha-selenium/spec/rubocop_check_spec.rb +7 -0
  19. data/vendor/aranha-selenium/spec/spec_helper.rb +100 -0
  20. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern.rb +68 -0
  21. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/configs.rb +4 -12
  22. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs.rb +1 -1
  23. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner/_class_methods.rb +1 -1
  24. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/speaker.rb +1 -1
  25. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/list.rb +4 -0
  26. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/lists.rb +10 -12
  27. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/symbol_list.rb +19 -0
  28. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/common_concern.rb +10 -0
  29. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/patch.rb +1 -1
  30. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/require_sub.rb +2 -2
  31. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_present.rb +1 -1
  32. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash.rb +1 -3
  33. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/require_sub.rb +45 -2
  34. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
  35. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/yaml.rb +85 -2
  36. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/common_concern_spec.rb +42 -0
  37. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/common_constructor_spec.rb +1 -0
  38. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/console/docopt_runner_spec.rb +5 -5
  39. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/console/speaker_spec.rb +1 -1
  40. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/envs/executable_spec.rb +4 -0
  41. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/fs/temp/temp_spec.rb +1 -1
  42. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/listable_spec.rb +32 -0
  43. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/options_consumer_spec.rb +1 -1
  44. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/hash/sym_keys_hash_spec.rb +1 -1
  45. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/object/if_present_spec.rb +1 -1
  46. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/object/template_spec.rb +1 -1
  47. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/pathname/basename_sub_spec.rb +4 -4
  48. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/require_sub_spec.rb +19 -0
  49. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/require_sub_spec/stubbed_module_a.rb +6 -0
  50. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/require_sub_spec/stubbed_not_module.rb +6 -0
  51. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/templates/searcher_spec.rb +1 -1
  52. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/yaml_spec.rb +75 -0
  53. data/vendor/eac_ruby_utils/spec/locales/pt-BR.yml +17 -0
  54. metadata +26 -1
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'aranha/selenium/driver_factory'
4
+
5
+ module Aranha
6
+ module Selenium
7
+ class Session < ::SimpleDelegator
8
+ attr_reader :downloads, :wait
9
+
10
+ def initialize(options = {})
11
+ @downloads = Downloads.new
12
+ @wait = ::Selenium::WebDriver::Wait.new(timeout: 15)
13
+ super(
14
+ ::Aranha::Selenium::DriverFactory.create_driver(
15
+ options.merge(download_dir: @downloads.dir)
16
+ )
17
+ )
18
+ end
19
+
20
+ def find_or_not_element(find_element_args)
21
+ r = find_elements(find_element_args)
22
+ r.any? ? r.first : nil
23
+ end
24
+
25
+ def wait_for_click(find_element_args)
26
+ wait.until do
27
+ element = find_element(find_element_args)
28
+ element ? element_click(element) : nil
29
+ end
30
+ end
31
+
32
+ def wait_for_element(find_element_args)
33
+ wait.until { find_element(find_element_args) }
34
+ end
35
+
36
+ def wait_for_download
37
+ initial_downloads = downloads.current
38
+ yield
39
+ new_downloads = []
40
+ wait.until do
41
+ new_downloads = downloads.current - initial_downloads
42
+ new_downloads.any?
43
+ end
44
+ new_downloads.first
45
+ end
46
+
47
+ def current_source
48
+ element = find_element(xpath: '/html[1]')
49
+ raise 'Root element not found' unless element
50
+
51
+ s = element.attribute('innerHTML')
52
+ "<html>\n#{s}\n</html>\n"
53
+ end
54
+
55
+ class Downloads
56
+ attr_reader :dir
57
+
58
+ def initialize
59
+ @dir = ::Dir.mktmpdir
60
+ end
61
+
62
+ def current
63
+ Dir.glob("#{dir}/**/*")
64
+ end
65
+ end
66
+
67
+ private
68
+
69
+ def element_click(element)
70
+ element.click
71
+ element
72
+ rescue ::Selenium::WebDriver::Error::ElementClickInterceptedError,
73
+ ::Selenium::WebDriver::Error::ElementNotInteractableError
74
+ nil
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aranha
4
+ module Selenium
5
+ VERSION = '0.1.3'
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_gem_support/spec/examples/rubocop_check'
4
+
5
+ RSpec.describe ::RuboCop do
6
+ include_examples 'rubocop_check', ::File.expand_path('..', __dir__)
7
+ end
@@ -0,0 +1,100 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This file was generated by the `rspec --init` command. Conventionally, all
4
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
6
+ # this file to always be loaded, without a need to explicitly require it in any
7
+ # files.
8
+ #
9
+ # Given that it is always loaded, you are encouraged to keep this file as
10
+ # light-weight as possible. Requiring heavyweight dependencies from this file
11
+ # will add to the boot time of your test suite on EVERY test run, even for an
12
+ # individual file that may not need all of that loaded. Instead, consider making
13
+ # a separate helper file that requires the additional dependencies and performs
14
+ # the additional setup, and require it from the spec files that actually need
15
+ # it.
16
+ #
17
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
18
+ RSpec.configure do |config|
19
+ # rspec-expectations config goes here. You can use an alternate
20
+ # assertion/expectation library such as wrong or the stdlib/minitest
21
+ # assertions if you prefer.
22
+ config.expect_with :rspec do |expectations|
23
+ # This option will default to `true` in RSpec 4. It makes the `description`
24
+ # and `failure_message` of custom matchers include text for helper methods
25
+ # defined using `chain`, e.g.:
26
+ # be_bigger_than(2).and_smaller_than(4).description
27
+ # # => "be bigger than 2 and smaller than 4"
28
+ # ...rather than:
29
+ # # => "be bigger than 2"
30
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
31
+ end
32
+
33
+ # rspec-mocks config goes here. You can use an alternate test double
34
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
35
+ config.mock_with :rspec do |mocks|
36
+ # Prevents you from mocking or stubbing a method that does not exist on
37
+ # a real object. This is generally recommended, and will default to
38
+ # `true` in RSpec 4.
39
+ mocks.verify_partial_doubles = true
40
+ end
41
+
42
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
43
+ # have no way to turn it off -- the option exists only for backwards
44
+ # compatibility in RSpec 3). It causes shared context metadata to be
45
+ # inherited by the metadata hash of host groups and examples, rather than
46
+ # triggering implicit auto-inclusion in groups with matching metadata.
47
+ config.shared_context_metadata_behavior = :apply_to_host_groups
48
+
49
+ # The settings below are suggested to provide a good initial experience
50
+ # with RSpec, but feel free to customize to your heart's content.
51
+ # # This allows you to limit a spec run to individual examples or groups
52
+ # # you care about by tagging them with `:focus` metadata. When nothing
53
+ # # is tagged with `:focus`, all examples get run. RSpec also provides
54
+ # # aliases for `it`, `describe`, and `context` that include `:focus`
55
+ # # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
56
+ # config.filter_run_when_matching :focus
57
+ #
58
+ # # Allows RSpec to persist some state between runs in order to support
59
+ # # the `--only-failures` and `--next-failure` CLI options. We recommend
60
+ # # you configure your source control system to ignore this file.
61
+ # config.example_status_persistence_file_path = "spec/examples.txt"
62
+ #
63
+ # # Limits the available syntax to the non-monkey patched syntax that is
64
+ # # recommended. For more details, see:
65
+ # # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
66
+ # # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
67
+ # # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
68
+ # config.disable_monkey_patching!
69
+ #
70
+ # # This setting enables warnings. It's recommended, but in some cases may
71
+ # # be too noisy due to issues in dependencies.
72
+ # config.warnings = true
73
+ #
74
+ # # Many RSpec users commonly either run the entire suite or an individual
75
+ # # file, and it's useful to allow more verbose output when running an
76
+ # # individual spec file.
77
+ # if config.files_to_run.one?
78
+ # # Use the documentation formatter for detailed output,
79
+ # # unless a formatter has already been configured
80
+ # # (e.g. via a command-line flag).
81
+ # config.default_formatter = "doc"
82
+ # end
83
+ #
84
+ # # Print the 10 slowest examples and example groups at the
85
+ # # end of the spec run, to help surface which specs are running
86
+ # # particularly slow.
87
+ # config.profile_examples = 10
88
+ #
89
+ # # Run specs in random order to surface order dependencies. If you find an
90
+ # # order dependency and want to debug it, you can fix the order by providing
91
+ # # the seed, which is printed after each run.
92
+ # # --seed 1234
93
+ # config.order = :random
94
+ #
95
+ # # Seed global randomization in this process using the `--seed` CLI option.
96
+ # # Setting this allows you to use `--seed` to deterministically reproduce
97
+ # # test failures related to randomization by passing the same `--seed` value
98
+ # # as the one that triggered the failure.
99
+ # Kernel.srand config.seed
100
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/concern'
4
+ require 'eac_ruby_utils/simple_cache'
5
+ require 'eac_ruby_utils/patches/object/if_present'
6
+
7
+ module EacRubyUtils
8
+ class CommonConcern
9
+ CLASS_METHODS_MODULE_NAME = 'ClassMethods'
10
+ INSTANCE_METHODS_MODULE_NAME = 'InstanceMethods'
11
+
12
+ attr_reader :after_callback
13
+
14
+ def initialize(&after_callback)
15
+ @after_callback = after_callback
16
+ end
17
+
18
+ def setup(a_module)
19
+ Setup.new(self, a_module).run
20
+ end
21
+
22
+ class Setup
23
+ include ::EacRubyUtils::SimpleCache
24
+ attr_reader :a_module, :common_constructor
25
+
26
+ def initialize(common_constructor, a_module)
27
+ @common_constructor = common_constructor
28
+ @a_module = a_module
29
+ end
30
+
31
+ def run
32
+ setup = self
33
+ a_module.extend(::ActiveSupport::Concern)
34
+ a_module.included do
35
+ %w[class_methods instance_methods after_callback].each do |suffix|
36
+ setup.send("setup_#{suffix}", self)
37
+ end
38
+ end
39
+ end
40
+
41
+ def setup_class_methods(base)
42
+ class_methods_module.if_present { |v| base.extend v }
43
+ end
44
+
45
+ def setup_instance_methods(base)
46
+ instance_methods_module.if_present { |v| base.include v }
47
+ end
48
+
49
+ def setup_after_callback(base)
50
+ common_constructor.after_callback.if_present do |v|
51
+ base.instance_eval(&v)
52
+ end
53
+ end
54
+
55
+ def class_methods_module_uncached
56
+ a_module.const_get(CLASS_METHODS_MODULE_NAME)
57
+ rescue NameError
58
+ nil
59
+ end
60
+
61
+ def instance_methods_module_uncached
62
+ a_module.const_get(INSTANCE_METHODS_MODULE_NAME)
63
+ rescue NameError
64
+ nil
65
+ end
66
+ end
67
+ end
68
+ end
@@ -20,17 +20,11 @@ module EacRubyUtils
20
20
  load
21
21
  end
22
22
 
23
- def clear
24
- file.clear
25
- end
23
+ delegate :clear, to: :file
26
24
 
27
- def save
28
- file.save
29
- end
25
+ delegate :save, to: :file
30
26
 
31
- def load
32
- file.load
33
- end
27
+ delegate :load, to: :file
34
28
 
35
29
  def []=(entry_key, entry_value)
36
30
  write_entry(entry_key, entry_value)
@@ -48,9 +42,7 @@ module EacRubyUtils
48
42
  file.read(entry_key)
49
43
  end
50
44
 
51
- def autosave?
52
- file.autosave?
53
- end
45
+ delegate :autosave?, to: :file
54
46
 
55
47
  private
56
48
 
@@ -85,7 +85,7 @@ module EacRubyUtils
85
85
  def looped_entry_value_from_input(entry_key, options)
86
86
  loop do
87
87
  entry_value = entry_value_from_input(entry_key, options)
88
- next unless entry_value.present?
88
+ next if entry_value.blank?
89
89
  next if options[:validator] && !options[:validator].call(entry_value)
90
90
 
91
91
  return entry_value
@@ -10,7 +10,7 @@ module EacRubyUtils
10
10
  new(options).send(:run)
11
11
  rescue Docopt::Exit => e
12
12
  STDERR.write(e.message + "\n")
13
- ::Kernel.exit(DOCOPT_ERROR_EXIT_CODE)
13
+ ::Kernel.exit(DOCOPT_ERROR_EXIT_CODE) # rubocop:disable Rails/Exit
14
14
  end
15
15
  end
16
16
  end
@@ -26,7 +26,7 @@ module EacRubyUtils
26
26
 
27
27
  def fatal_error(string)
28
28
  puts "ERROR: #{string}".white.on_red
29
- Kernel.exit 1
29
+ Kernel.exit 1 # rubocop:disable Rails/Exit
30
30
  end
31
31
 
32
32
  def title(string)
@@ -12,6 +12,10 @@ module EacRubyUtils
12
12
  apply_constants
13
13
  end
14
14
 
15
+ def each_value(&block)
16
+ values.each(&block)
17
+ end
18
+
15
19
  def values
16
20
  @values.values.map(&:value)
17
21
  end
@@ -4,6 +4,7 @@ require 'active_support/hash_with_indifferent_access'
4
4
  require 'active_support/core_ext/string/inflections'
5
5
  require_relative 'integer_list'
6
6
  require_relative 'string_list'
7
+ require_relative 'symbol_list'
7
8
 
8
9
  module EacRubyUtils
9
10
  module Listable
@@ -14,18 +15,10 @@ module EacRubyUtils
14
15
  @source = source
15
16
  end
16
17
 
17
- def add_integer(item, *labels)
18
- check_acts_as_listable_new_item(item)
19
- acts_as_listable_items[item] = ::EacRubyUtils::Listable::IntegerList.new(
20
- self, item, labels
21
- )
22
- end
23
-
24
- def add_string(item, *labels)
25
- check_acts_as_listable_new_item(item)
26
- acts_as_listable_items[item] = ::EacRubyUtils::Listable::StringList.new(
27
- self, item, labels
28
- )
18
+ %w[integer string symbol].each do |list_type|
19
+ define_method "add_#{list_type}" do |item, *labels|
20
+ add(::EacRubyUtils::Listable.const_get("#{list_type}_list".camelize), item, labels)
21
+ end
29
22
  end
30
23
 
31
24
  def method_missing(name, *args, &block)
@@ -43,6 +36,11 @@ module EacRubyUtils
43
36
 
44
37
  private
45
38
 
39
+ def add(list_class, item, labels)
40
+ check_acts_as_listable_new_item(item)
41
+ acts_as_listable_items[item] = list_class.new(self, item, labels)
42
+ end
43
+
46
44
  def check_acts_as_listable_new_item(item)
47
45
  return unless acts_as_listable_items.key?(item)
48
46
 
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'list'
4
+
5
+ module EacRubyUtils
6
+ module Listable
7
+ class SymbolList < ::EacRubyUtils::Listable::List
8
+ protected
9
+
10
+ def parse_labels(labels)
11
+ if labels.first.is_a?(Hash)
12
+ Hash[labels.first.map { |k, v| [k.to_sym, v.to_sym] }]
13
+ else
14
+ Hash[labels.map { |v| [v.to_sym, v.to_sym] }]
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/common_concern'
4
+ require 'eac_ruby_utils/console/speaker'
5
+
6
+ class Module
7
+ def common_concern(&after_callback)
8
+ ::EacRubyUtils::CommonConcern.new(&after_callback).setup(self)
9
+ end
10
+ end
@@ -4,6 +4,6 @@ require 'eac_ruby_utils/patch'
4
4
 
5
5
  class Module
6
6
  def patch(patch_module)
7
- ::Eac::Ruby::Utils.patch(self, patch_module)
7
+ ::EacRubyUtils.patch(self, patch_module)
8
8
  end
9
9
  end
@@ -3,7 +3,7 @@
3
3
  require 'eac_ruby_utils/require_sub'
4
4
 
5
5
  class Module
6
- def require_sub(file_path)
7
- ::EacRubyUtils.require_sub(file_path)
6
+ def require_sub(file_path, options = {})
7
+ ::EacRubyUtils.require_sub(file_path, { base: self }.merge(options))
8
8
  end
9
9
  end
@@ -5,7 +5,7 @@ require 'active_support/core_ext/object/blank'
5
5
  class Object
6
6
  # @return +block.call(self)+ if +self+ is present, +default_value+ otherwise.
7
7
  def if_present(default_value = nil)
8
- return default_value unless present?
8
+ return default_value if blank?
9
9
 
10
10
  block_given? ? yield(self) : self
11
11
  end
@@ -33,9 +33,7 @@ module EacRubyUtils
33
33
  root.write_entry(self.class.parse_entry_key(entry_key), entry_value, [])
34
34
  end
35
35
 
36
- def to_h
37
- root.to_h
38
- end
36
+ delegate :to_h, to: :root
39
37
 
40
38
  private
41
39