ehbrs-tools 0.12.0 → 0.13.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 (42) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ehbrs/runner/finances.rb +19 -0
  3. data/lib/ehbrs/runner/finances/bb_browser.rb +40 -0
  4. data/lib/ehbrs/tools/version.rb +1 -1
  5. data/vendor/eac_docker/Gemfile +5 -0
  6. data/vendor/eac_docker/eac_docker.gemspec +18 -0
  7. data/vendor/eac_docker/lib/eac_docker.rb +7 -0
  8. data/vendor/eac_docker/lib/eac_docker/container.rb +50 -0
  9. data/vendor/eac_docker/lib/eac_docker/executables.rb +18 -0
  10. data/vendor/eac_docker/lib/eac_docker/images.rb +9 -0
  11. data/vendor/eac_docker/lib/eac_docker/images/base.rb +14 -0
  12. data/vendor/eac_docker/lib/eac_docker/images/named.rb +30 -0
  13. data/vendor/eac_docker/lib/eac_docker/rspec.rb +17 -0
  14. data/vendor/eac_docker/lib/eac_docker/version.rb +5 -0
  15. data/vendor/eac_docker/spec/lib/eac_docker/executables_spec.rb +9 -0
  16. data/vendor/eac_docker/spec/rubocop_spec.rb +7 -0
  17. data/vendor/eac_docker/spec/spec_helper.rb +103 -0
  18. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command.rb +1 -0
  19. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/extra_options.rb +8 -0
  20. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs_cache.rb +1 -0
  21. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/immutable.rb +15 -0
  22. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/immutable/array_accessor.rb +28 -0
  23. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/immutable/base_accessor.rb +23 -0
  24. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/immutable/boolean_accessor.rb +16 -0
  25. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/immutable/class_methods.rb +20 -0
  26. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/immutable/common_accessor.rb +30 -0
  27. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/immutable/hash_accessor.rb +42 -0
  28. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/immutable/instance_methods.rb +21 -0
  29. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/immutable.rb +10 -0
  30. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/require_sub.rb +32 -5
  31. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/templates/directory.rb +7 -1
  32. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/templates/file.rb +8 -59
  33. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/templates/variable_not_found_error.rb +7 -0
  34. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/templates/variable_providers.rb +25 -0
  35. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/templates/variable_providers/base.rb +23 -0
  36. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/templates/variable_providers/entries_reader.rb +25 -0
  37. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/templates/variable_providers/generic.rb +25 -0
  38. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/templates/variable_providers/hash.rb +29 -0
  39. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
  40. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/ruby_spec.rb +22 -0
  41. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/templates/file_spec.rb +1 -0
  42. metadata +33 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 01424b2d17105c7694679a4deb6dda7d0ab4b98f6ee0b32ed5d183bfdac33583
4
- data.tar.gz: 271b08e6e6cf9a3868e06d1a13520030e6f1c55d167b86781f1250e92540dee7
3
+ metadata.gz: 4a216d21cdcdb218151fbfd96d21d4b378ae35c4071d222707178c48a6f4ad69
4
+ data.tar.gz: dec260f1e8ffceb7eaa91fb4052b136d8222525c473e348abd897e86d0ba4e00
5
5
  SHA512:
6
- metadata.gz: bd53a0486dfec03c0d827ee8f759c5f28a490c93cb2320ea623f8a01ec5f9bdc106dd955f55114d098236b0418d96f62ab47cc2df8248b01da66bd87b3db52d8
7
- data.tar.gz: 31dc82bd83f87cb8ea9ab4f2e8d2eac8ceba2477bf2d200156b3c01ada3794ddb673bb1d9581fc72ed9da97c3771393b701ae65f1c3c0447b9aeb344afb11d6a
6
+ metadata.gz: 000fb54ab3abd785846e2d05802a7d12752109be7a2ac2314ea7804bcc90a4f98f3ee443dd693c6cba1687333c32d2832387f17acc9e32e44a6fb1cb22e23954
7
+ data.tar.gz: 8b060bb61da97a62b3fd1648060fb667ea9ed074fd719c194806d15469bae413031f663df10877b0099d109a4d78544f8e3148b842d36841e68f0140daa99b15
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/default_runner'
4
+ require 'eac_ruby_utils/core_ext'
5
+ require 'eac_ruby_utils/console/docopt_runner'
6
+
7
+ module Ehbrs
8
+ class Runner < ::EacRubyUtils::Console::DocoptRunner
9
+ class Finances < ::EacRubyUtils::Console::DocoptRunner
10
+ include ::EacCli::DefaultRunner
11
+ require_sub __FILE__
12
+
13
+ runner_definition do
14
+ desc 'Utilidades financeiras.'
15
+ subcommands
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/default_runner'
4
+ require 'eac_ruby_utils/core_ext'
5
+ require 'eac_ruby_utils/console/docopt_runner'
6
+ require 'ehbrs/videos/extract/package'
7
+ require 'eac_docker/images/named'
8
+
9
+ module Ehbrs
10
+ class Runner < ::EacRubyUtils::Console::DocoptRunner
11
+ class Finances < ::EacRubyUtils::Console::DocoptRunner
12
+ class BbBrowser < ::EacRubyUtils::Console::DocoptRunner
13
+ include ::EacCli::DefaultRunner
14
+ require_sub __FILE__
15
+
16
+ runner_definition do
17
+ desc 'Bankline para Banco do Brasil com módulo de segurança.'
18
+ end
19
+
20
+ def run
21
+ infov 'Docker run arguments', docker_container.run_command_args
22
+ infov 'System result', docker_container.run_command.system
23
+ end
24
+
25
+ private
26
+
27
+ def docker_image_uncached
28
+ ::EacDocker::Images::Named.new('lichti/warsaw-browser')
29
+ end
30
+
31
+ def docker_container_uncached
32
+ docker_image.container.env('DISPLAY', "unix#{ENV.fetch('DISPLAY')}")
33
+ .volume(::File.join(ENV['HOME'], 'Downloads'), '/home/bank/Downloads')
34
+ .volume('/tmp/.X11-unix', '/tmp/.X11-unix').command_arg('bb')
35
+ .temporary(true).interactive(true).tty(true)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Ehbrs
4
4
  module Tools
5
- VERSION = '0.12.0'
5
+ VERSION = '0.13.0'
6
6
  end
7
7
  end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.push File.expand_path('lib', __dir__)
4
+
5
+ require 'eac_docker/version'
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = 'eac_docker'
9
+ s.version = EacDocker::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_ruby_utils', '~> 0.36'
16
+
17
+ s.add_development_dependency 'eac_ruby_gem_support', '~> 0.1', '>= 0.1.1'
18
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacDocker
6
+ require_sub __FILE__
7
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacDocker
6
+ class Container
7
+ enable_immutable
8
+ immutable_accessor :interactive, :temporary, :tty, type: :boolean
9
+ immutable_accessor :env, type: :hash
10
+ immutable_accessor :command_arg, :volume, type: :array
11
+ common_constructor :image
12
+
13
+ def immutable_constructor_args
14
+ [image]
15
+ end
16
+
17
+ alias immutable_volume volume
18
+
19
+ def volume(left_part, right_part = null)
20
+ immutable_volume(right_part.if_present(left_part) { |v| "#{left_part}:#{v}" })
21
+ end
22
+
23
+ def run_command
24
+ ::EacDocker::Executables.docker.command('run', *run_command_args)
25
+ end
26
+
27
+ def run_command_args
28
+ run_command_boolean_args + run_command_envs_args + run_command_volumes_args + [image.id] +
29
+ command_args
30
+ end
31
+
32
+ private
33
+
34
+ def run_command_boolean_args
35
+ r = []
36
+ r << '--interactive' if interactive?
37
+ r << '--tty' if tty?
38
+ r << '--rm' if temporary?
39
+ r
40
+ end
41
+
42
+ def run_command_volumes_args
43
+ volumes.flat_map { |volume| ['--volume', volume] }
44
+ end
45
+
46
+ def run_command_envs_args
47
+ envs.flat_map { |name, value| ['--env', "#{name}=#{value}"] }
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'eac_ruby_utils/envs'
5
+
6
+ module EacDocker
7
+ module Executables
8
+ class << self
9
+ def env
10
+ ::EacRubyUtils::Envs.local
11
+ end
12
+
13
+ def docker
14
+ @docker ||= env.executable('docker', '--version')
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacDocker
6
+ module Images
7
+ require_sub __FILE__
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'eac_docker/container'
5
+
6
+ module EacDocker
7
+ module Images
8
+ class Base
9
+ def container
10
+ ::EacDocker::Container.new(self)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_docker/executables'
4
+ require 'eac_docker/images/base'
5
+ require 'eac_ruby_utils/core_ext'
6
+
7
+ module EacDocker
8
+ module Images
9
+ class Named < ::EacDocker::Images::Base
10
+ common_constructor :source_tag
11
+
12
+ def id
13
+ source_tag
14
+ end
15
+
16
+ def provide
17
+ provide_command.execute!
18
+ self
19
+ end
20
+
21
+ def provide_command
22
+ ::EacDocker::Executables.docker.command(*docker_provide_args)
23
+ end
24
+
25
+ def docker_provide_args
26
+ ['pull', source_tag]
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/rspec/conditional'
4
+ require 'eac_docker/executables'
5
+
6
+ module EacDocker
7
+ module Rspec
8
+ class << self
9
+ def configure
10
+ ::EacRubyUtils::Rspec::Conditional.default.add(:docker) do
11
+ ::EacDocker::Executables.docker.validate
12
+ end
13
+ RSpec.configure { |config| ::EacRubyUtils::Rspec::Conditional.default.configure(config) }
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacDocker
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_docker/executables'
4
+
5
+ RSpec.describe(::EacDocker::Executables, docker: true) do
6
+ it 'output version' do
7
+ expect(described_class.docker.command('--version').execute!).to be_present
8
+ end
9
+ 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, slow: true do
6
+ include_examples 'rubocop_check', ::File.expand_path('..', __dir__)
7
+ end
@@ -0,0 +1,103 @@
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
101
+
102
+ require 'eac_docker/rspec'
103
+ ::EacDocker::Rspec.configure
@@ -54,6 +54,7 @@ module EacRubyUtils
54
54
  end
55
55
 
56
56
  def execute!(options = {})
57
+ options[:exit_outputs] = status_results.merge(options[:exit_outputs].presence || {})
57
58
  er = ExecuteResult.new(execute(options), options)
58
59
  return er.result if er.success?
59
60
 
@@ -16,6 +16,10 @@ module EacRubyUtils
16
16
  duplicate_by_extra_options(envvars: envvars.merge(name => value))
17
17
  end
18
18
 
19
+ def status_result(status_code, result)
20
+ duplicate_by_extra_options(status_results: status_results.merge(status_code => result))
21
+ end
22
+
19
23
  def pipe(other_command)
20
24
  duplicate_by_extra_options(pipe: other_command)
21
25
  end
@@ -28,6 +32,10 @@ module EacRubyUtils
28
32
  extra_options[:envvars] ||= {}.with_indifferent_access
29
33
  end
30
34
 
35
+ def status_results
36
+ extra_options[:status_results] ||= {}.with_indifferent_access
37
+ end
38
+
31
39
  def append_envvars(command)
32
40
  e = envvars.map { |k, v| "#{Shellwords.escape(k)}=#{Shellwords.escape(v)}" }.join(' ')
33
41
  e.present? ? "#{e} #{command}" : command
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'eac_ruby_utils/filesystem_cache'
4
+ require 'tmpdir'
4
5
 
5
6
  module EacRubyUtils
6
7
  class << self
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/patches/module/common_concern'
4
+ require 'eac_ruby_utils/require_sub'
5
+
6
+ module EacRubyUtils
7
+ module Immutable
8
+ ::EacRubyUtils.require_sub __FILE__
9
+
10
+ common_concern do
11
+ include ::EacRubyUtils::Listable
12
+ lists.add_symbol :type, :array, :boolean, :common, :hash
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/inflector'
4
+ require 'eac_ruby_utils/immutable/base_accessor'
5
+ require 'eac_ruby_utils/patches/class/common_constructor'
6
+
7
+ module EacRubyUtils
8
+ module Immutable
9
+ class ArrayAccessor < ::EacRubyUtils::Immutable::BaseAccessor
10
+ def apply(klass)
11
+ accessor = self
12
+ klass.send(:define_method, name) do |value|
13
+ accessor.immutable_value_set(self, value)
14
+ end
15
+
16
+ klass.send(:define_method, ::ActiveSupport::Inflector.pluralize(name)) do
17
+ accessor.immutable_value_get(self)
18
+ end
19
+ end
20
+
21
+ def immutable_value_set(object, value)
22
+ duplicate_object(object) do |old_value|
23
+ (old_value || []) + [value]
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacRubyUtils
4
+ module Immutable
5
+ class BaseAccessor
6
+ common_constructor :name do
7
+ self.name = name.to_sym
8
+ end
9
+
10
+ def duplicate_object(object)
11
+ accessor_new_value = yield(immutable_value_get(object))
12
+ new_values = object.send(:immutable_values_get).merge(name => accessor_new_value)
13
+ r = object.class.new(*object.immutable_constructor_args)
14
+ r.send(:immutable_values_set, new_values)
15
+ r
16
+ end
17
+
18
+ def immutable_value_get(object)
19
+ object.send(:immutable_values_get)[name]
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/immutable/common_accessor'
4
+ require 'eac_ruby_utils/patches/class/common_constructor'
5
+
6
+ module EacRubyUtils
7
+ module Immutable
8
+ class BooleanAccessor < ::EacRubyUtils::Immutable::CommonAccessor
9
+ def apply(klass)
10
+ super
11
+ accessor = self
12
+ klass.send(:define_method, "#{name}?") { send(accessor.name) }
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacRubyUtils
4
+ module Immutable
5
+ module ClassMethods
6
+ def immutable_accessor(*accessors)
7
+ options = accessors.extract_options!
8
+ options[:type] ||= const_get('TYPE_COMMON')
9
+ accessors.each do |name|
10
+ class_name = options.fetch(:type).to_s.camelize + 'Accessor'
11
+ ::EacRubyUtils::Immutable.const_get(class_name).new(name).apply(self)
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ def imutable_single_accessor(name, options); end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/immutable/base_accessor'
4
+ require 'eac_ruby_utils/patches/class/common_constructor'
5
+
6
+ module EacRubyUtils
7
+ module Immutable
8
+ class CommonAccessor < ::EacRubyUtils::Immutable::BaseAccessor
9
+ def apply(klass)
10
+ accessor = self
11
+ klass.send(:define_method, name) do |*args|
12
+ case args.count
13
+ when 0 then next accessor.immutable_value_get(self)
14
+ when 1 then next accessor.immutable_value_set(self, args.first)
15
+ else
16
+ raise ::ArgumentError, "wrong number of arguments (given #{args.count}, expected 0..1)"
17
+ end
18
+ end
19
+ end
20
+
21
+ def immutable_value_get(object)
22
+ object.send(:immutable_values_get)[name]
23
+ end
24
+
25
+ def immutable_value_set(object, value)
26
+ duplicate_object(object) { |_old_value| value }
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/immutable/base_accessor'
4
+ require 'eac_ruby_utils/patches/class/common_constructor'
5
+
6
+ module EacRubyUtils
7
+ module Immutable
8
+ class HashAccessor < ::EacRubyUtils::Immutable::BaseAccessor
9
+ def apply(klass)
10
+ apply_get(klass)
11
+ apply_set(klass)
12
+ end
13
+
14
+ def immutable_value_set(object, key, value)
15
+ duplicate_object(object) do |old_value|
16
+ (old_value || {}).merge(key => value)
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def apply_get(klass)
23
+ accessor = self
24
+ klass.send(:define_method, ::ActiveSupport::Inflector.pluralize(name)) do
25
+ accessor.immutable_value_get(self)
26
+ end
27
+ end
28
+
29
+ def apply_set(klass)
30
+ accessor = self
31
+ klass.send(:define_method, name) do |*args|
32
+ case args.count
33
+ when 1 then next accessor.immutable_value_get(self, args[0])
34
+ when 2 then next accessor.immutable_value_set(self, *args[0..1])
35
+ else
36
+ raise ::ArgumentError, "wrong number of arguments (given #{args.count}, expected 1..2)"
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacRubyUtils
4
+ module Immutable
5
+ module InstanceMethods
6
+ def immutable_constructor_args
7
+ []
8
+ end
9
+
10
+ private
11
+
12
+ def immutable_values_get
13
+ @immutable_values || {}
14
+ end
15
+
16
+ def immutable_values_set(new_values)
17
+ @immutable_values = new_values
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/patch'
4
+ require 'eac_ruby_utils/immutable'
5
+
6
+ class Module
7
+ def enable_immutable
8
+ ::EacRubyUtils.patch(self, ::EacRubyUtils::Immutable)
9
+ end
10
+ end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'active_support/inflector'
4
+
3
5
  module EacRubyUtils
4
6
  class << self
5
7
  def require_sub(file, options = {})
@@ -26,6 +28,23 @@ module EacRubyUtils
26
28
 
27
29
  private
28
30
 
31
+ def active_support_require(path)
32
+ return false unless options[REQUIRE_DEPENDENCY_OPTION_KEY]
33
+
34
+ ::Kernel.require_dependency(path)
35
+ true
36
+ end
37
+
38
+ def autoload_require(path)
39
+ return false unless base?
40
+
41
+ basename = ::File.basename(path, '.*')
42
+ return false if basename.start_with?('_')
43
+
44
+ base.autoload ::ActiveSupport::Inflector.camelize(basename), path
45
+ true
46
+ end
47
+
29
48
  def include_modules
30
49
  return unless options[INCLUDE_MODULES_OPTION_KEY]
31
50
 
@@ -41,14 +60,22 @@ module EacRubyUtils
41
60
  options[BASE_OPTION_KEY] || raise('Option :base not setted')
42
61
  end
43
62
 
63
+ def base?
64
+ options[BASE_OPTION_KEY] ? true : false
65
+ end
66
+
67
+ def kernel_require(path)
68
+ ::Kernel.require(path)
69
+ end
70
+
44
71
  def require_sub_files
45
72
  Dir["#{File.dirname(file)}/#{::File.basename(file, '.*')}/*.rb"].sort.each do |path|
46
- if options[REQUIRE_DEPENDENCY_OPTION_KEY]
47
- require_dependency path
48
- else
49
- require path
50
- end
73
+ require_sub_file(path)
51
74
  end
52
75
  end
76
+
77
+ def require_sub_file(path)
78
+ active_support_require(path) || autoload_require(path) || kernel_require(path)
79
+ end
53
80
  end
54
81
  end
@@ -10,7 +10,7 @@ module EacRubyUtils
10
10
  attr_reader :path
11
11
 
12
12
  def initialize(path)
13
- @path = path
13
+ @path = path.is_a?(::Pathname) ? path : ::Pathname.new(path.to_s)
14
14
  end
15
15
 
16
16
  def apply(variables_source, directory)
@@ -25,6 +25,12 @@ module EacRubyUtils
25
25
  raise "Child \"#{subpath}\" from \"#{path}\" not found"
26
26
  end
27
27
 
28
+ def children
29
+ path.children.map do |path_child|
30
+ child(path_child.basename.to_path)
31
+ end
32
+ end
33
+
28
34
  private
29
35
 
30
36
  def apply_fs_object(source_relative, target)
@@ -1,32 +1,29 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'active_support/core_ext/hash/indifferent_access'
4
- require 'eac_ruby_utils/simple_cache'
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'eac_ruby_utils/templates/variable_providers'
5
5
 
6
6
  module EacRubyUtils
7
7
  module Templates
8
8
  class File
9
- include ::EacRubyUtils::SimpleCache
10
-
11
9
  VARIABLE_DELIMITER = ::Regexp.quote('%%')
12
10
  VARIABLE_PATTERN = /#{VARIABLE_DELIMITER}([a-z0-9\._]*)#{VARIABLE_DELIMITER}/i.freeze
13
11
 
14
- attr_reader :path
15
-
16
- def initialize(path)
17
- @path = path
12
+ enable_simple_cache
13
+ common_constructor :path do
14
+ self.path = path.to_pathname
18
15
  end
19
16
 
20
17
  # +variables_provider+ A [Hash] or object which responds to +read_entry(entry_name)+.
21
18
  def apply(variables_source)
22
- variables_provider = build_variables_provider(variables_source)
19
+ variables_provider = ::EacRubyUtils::Templates::VariableProviders.build(variables_source)
23
20
  variables.inject(content) do |a, e|
24
21
  a.gsub(variable_pattern(e), variables_provider.variable_value(e).to_s)
25
22
  end
26
23
  end
27
24
 
28
25
  def apply_to_file(variables_source, output_file_path)
29
- ::File.write(output_file_path, apply(variables_source))
26
+ output_file_path.to_pathname.write(apply(variables_source))
30
27
  end
31
28
 
32
29
  private
@@ -38,64 +35,16 @@ module EacRubyUtils
38
35
  end
39
36
 
40
37
  def content_uncached
41
- ::File.read(path)
38
+ path.read
42
39
  end
43
40
 
44
41
  def sanitize_variable_name(variable_name)
45
42
  variable_name.to_s.downcase
46
43
  end
47
44
 
48
- def build_variables_provider(variables_source)
49
- return HashVariablesProvider.new(variables_source) if variables_source.is_a?(::Hash)
50
- return EntriesReaderVariablesProvider.new(variables_source) if
51
- variables_source.respond_to?(:read_entry)
52
-
53
- raise "Variables provider not found for #{variables_source}"
54
- end
55
-
56
45
  def variable_pattern(name)
57
46
  /#{VARIABLE_DELIMITER}#{::Regexp.quote(name)}#{VARIABLE_DELIMITER}/i
58
47
  end
59
-
60
- class BaseVariablesProvider
61
- attr_reader :source
62
-
63
- def initialize(source)
64
- @source = source
65
- end
66
-
67
- def variable_value(name)
68
- return variable_fetch(name) if variable_exist?(name)
69
-
70
- raise VariableNotFoundError, "Variable \"#{name}\" not found in #{source}"
71
- end
72
- end
73
-
74
- class HashVariablesProvider < BaseVariablesProvider
75
- def initialize(source)
76
- super(source.with_indifferent_access)
77
- end
78
-
79
- def variable_exist?(name)
80
- source.key?(name)
81
- end
82
-
83
- def variable_fetch(name)
84
- source.fetch(name)
85
- end
86
- end
87
-
88
- class EntriesReaderVariablesProvider < BaseVariablesProvider
89
- def variable_exist?(_name)
90
- true
91
- end
92
-
93
- def variable_fetch(name)
94
- source.read_entry(name)
95
- end
96
- end
97
-
98
- class VariableNotFoundError < StandardError; end
99
48
  end
100
49
  end
101
50
  end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacRubyUtils
4
+ module Templates
5
+ class VariableNotFoundError < StandardError; end
6
+ end
7
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacRubyUtils
6
+ module Templates
7
+ module VariableProviders
8
+ require_sub __FILE__
9
+
10
+ PROVIDERS = %w[entries_reader hash generic].map do |name|
11
+ "eac_ruby_utils/templates/variable_providers/#{name}".camelize.constantize
12
+ end
13
+
14
+ class << self
15
+ def build(variables_source)
16
+ PROVIDERS.each do |provider|
17
+ return provider.new(variables_source) if provider.accept?(variables_source)
18
+ end
19
+
20
+ raise "Variables provider not found for #{variables_source}"
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/templates/variable_not_found_error'
4
+
5
+ module EacRubyUtils
6
+ module Templates
7
+ module VariableProviders
8
+ class Base
9
+ attr_reader :source
10
+
11
+ def initialize(source)
12
+ @source = source
13
+ end
14
+
15
+ def variable_value(name)
16
+ return variable_fetch(name) if variable_exist?(name)
17
+
18
+ raise VariableNotFoundError, "Variable \"#{name}\" not found in #{source}"
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/templates/variable_providers/base'
4
+
5
+ module EacRubyUtils
6
+ module Templates
7
+ module VariableProviders
8
+ class EntriesReader < ::EacRubyUtils::Templates::VariableProviders::Base
9
+ class << self
10
+ def accept?(variables_source)
11
+ variables_source.respond_to?(:read_entry)
12
+ end
13
+ end
14
+
15
+ def variable_exist?(_name)
16
+ true
17
+ end
18
+
19
+ def variable_fetch(name)
20
+ source.read_entry(name)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/templates/variable_providers/base'
4
+
5
+ module EacRubyUtils
6
+ module Templates
7
+ module VariableProviders
8
+ class Generic < ::EacRubyUtils::Templates::VariableProviders::Base
9
+ class << self
10
+ def accept?(variables_source)
11
+ variables_source.is_a?(::Object)
12
+ end
13
+ end
14
+
15
+ def variable_exist?(name)
16
+ source.respond_to?(name)
17
+ end
18
+
19
+ def variable_fetch(name)
20
+ source.send(name)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/templates/variable_providers/base'
4
+
5
+ module EacRubyUtils
6
+ module Templates
7
+ module VariableProviders
8
+ class Hash < ::EacRubyUtils::Templates::VariableProviders::Base
9
+ class << self
10
+ def accept?(variables_source)
11
+ variables_source.is_a?(::Hash)
12
+ end
13
+ end
14
+
15
+ def initialize(source)
16
+ super(source.with_indifferent_access)
17
+ end
18
+
19
+ def variable_exist?(name)
20
+ source.key?(name)
21
+ end
22
+
23
+ def variable_fetch(name)
24
+ source.fetch(name)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyUtils
4
- VERSION = '0.36.0'
4
+ VERSION = '0.40.0'
5
5
  end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/ruby'
4
+
5
+ RSpec.describe ::EacRubyUtils::Ruby do
6
+ describe '#on_clean_environment' do
7
+ let(:envvar_name) { 'BUNDLE_NOT_EXISTENT_ENV_VAR' }
8
+ let(:envvar_value) { 'any value' }
9
+
10
+ before do
11
+ ENV[envvar_name] = envvar_value
12
+ end
13
+
14
+ it do # rubocop:disable RSpec/MultipleExpectations
15
+ expect(ENV[envvar_name]).to eq(envvar_value)
16
+ described_class.on_clean_environment do
17
+ expect(ENV[envvar_name]).to eq(nil)
18
+ end
19
+ expect(ENV[envvar_name]).to eq(envvar_value)
20
+ end
21
+ end
22
+ end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'eac_ruby_utils/configs'
3
4
  require 'eac_ruby_utils/templates/file'
4
5
 
5
6
  RSpec.describe ::EacRubyUtils::Templates::File do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ehbrs-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esquilo Azul Company
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-11 00:00:00.000000000 Z
11
+ date: 2020-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: avm-tools
@@ -107,6 +107,8 @@ files:
107
107
  - lib/ehbrs/observers/base.rb
108
108
  - lib/ehbrs/observers/with_persistence.rb
109
109
  - lib/ehbrs/runner.rb
110
+ - lib/ehbrs/runner/finances.rb
111
+ - lib/ehbrs/runner/finances/bb_browser.rb
110
112
  - lib/ehbrs/runner/fs.rb
111
113
  - lib/ehbrs/runner/fs/used_space.rb
112
114
  - lib/ehbrs/runner/google.rb
@@ -201,6 +203,19 @@ files:
201
203
  - vendor/eac_cli/lib/eac_cli/version.rb
202
204
  - vendor/eac_cli/spec/rubocop_spec.rb
203
205
  - vendor/eac_cli/spec/spec_helper.rb
206
+ - vendor/eac_docker/Gemfile
207
+ - vendor/eac_docker/eac_docker.gemspec
208
+ - vendor/eac_docker/lib/eac_docker.rb
209
+ - vendor/eac_docker/lib/eac_docker/container.rb
210
+ - vendor/eac_docker/lib/eac_docker/executables.rb
211
+ - vendor/eac_docker/lib/eac_docker/images.rb
212
+ - vendor/eac_docker/lib/eac_docker/images/base.rb
213
+ - vendor/eac_docker/lib/eac_docker/images/named.rb
214
+ - vendor/eac_docker/lib/eac_docker/rspec.rb
215
+ - vendor/eac_docker/lib/eac_docker/version.rb
216
+ - vendor/eac_docker/spec/lib/eac_docker/executables_spec.rb
217
+ - vendor/eac_docker/spec/rubocop_spec.rb
218
+ - vendor/eac_docker/spec/spec_helper.rb
204
219
  - vendor/eac_ruby_utils/Gemfile
205
220
  - vendor/eac_ruby_utils/MIT-LICENCE
206
221
  - vendor/eac_ruby_utils/README.rdoc
@@ -246,6 +261,14 @@ files:
246
261
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/traversable.rb
247
262
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/traverser.rb
248
263
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/fs_cache.rb
264
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/immutable.rb
265
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/immutable/array_accessor.rb
266
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/immutable/base_accessor.rb
267
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/immutable/boolean_accessor.rb
268
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/immutable/class_methods.rb
269
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/immutable/common_accessor.rb
270
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/immutable/hash_accessor.rb
271
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/immutable/instance_methods.rb
249
272
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/listable.rb
250
273
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/class_methods.rb
251
274
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/instance_methods.rb
@@ -269,6 +292,7 @@ files:
269
292
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module.rb
270
293
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/common_concern.rb
271
294
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/console_speaker.rb
295
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/immutable.rb
272
296
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/listable.rb
273
297
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/patch.rb
274
298
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/require_sub.rb
@@ -299,6 +323,12 @@ files:
299
323
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/templates/directory.rb
300
324
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/templates/file.rb
301
325
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/templates/searcher.rb
326
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/templates/variable_not_found_error.rb
327
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/templates/variable_providers.rb
328
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/templates/variable_providers/base.rb
329
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/templates/variable_providers/entries_reader.rb
330
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/templates/variable_providers/generic.rb
331
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/templates/variable_providers/hash.rb
302
332
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb
303
333
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/yaml.rb
304
334
  - vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/arguments_consumer_spec.rb
@@ -331,6 +361,7 @@ files:
331
361
  - vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/require_sub_spec.rb
332
362
  - vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/require_sub_spec/stubbed_module_a.rb
333
363
  - vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/require_sub_spec/stubbed_not_module.rb
364
+ - vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/ruby_spec.rb
334
365
  - vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/settings_provider_spec.rb
335
366
  - vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/simple_cache_spec.rb
336
367
  - vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/templates/file_spec.rb