ehbrs-tools 0.11.0 → 0.14.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ehbrs/executables.rb +1 -1
- data/lib/ehbrs/google.rb +9 -0
- data/lib/ehbrs/google/translate.rb +11 -0
- data/lib/ehbrs/google/translate/session.rb +61 -0
- data/lib/ehbrs/runner.rb +9 -13
- data/lib/ehbrs/runner/finances.rb +19 -0
- data/lib/ehbrs/runner/finances/bb_browser.rb +40 -0
- data/lib/ehbrs/runner/fs/used_space.rb +4 -4
- data/lib/ehbrs/runner/google.rb +19 -0
- data/lib/ehbrs/runner/google/translate.rb +92 -0
- data/lib/ehbrs/runner/videos.rb +6 -11
- data/lib/ehbrs/runner/videos/probe.rb +35 -0
- data/lib/ehbrs/tools/version.rb +1 -1
- data/lib/ehbrs/videos/file.rb +2 -1
- data/lib/ehbrs/videos/unsupported/fix_profile.rb +1 -0
- data/vendor/aranha-selenium/Gemfile +5 -0
- data/vendor/aranha-selenium/aranha-selenium.gemspec +19 -0
- data/vendor/aranha-selenium/lib/aranha/selenium.rb +8 -0
- data/vendor/aranha-selenium/lib/aranha/selenium/driver_factory.rb +47 -0
- data/vendor/aranha-selenium/lib/aranha/selenium/driver_factory/base.rb +76 -0
- data/vendor/aranha-selenium/lib/aranha/selenium/driver_factory/chrome.rb +28 -0
- data/vendor/aranha-selenium/lib/aranha/selenium/driver_factory/firefox.rb +54 -0
- data/vendor/aranha-selenium/lib/aranha/selenium/driver_factory/firefox_auto_download_mime_types +685 -0
- data/vendor/aranha-selenium/lib/aranha/selenium/session.rb +78 -0
- data/vendor/aranha-selenium/lib/aranha/selenium/version.rb +7 -0
- data/vendor/aranha-selenium/spec/rubocop_check_spec.rb +7 -0
- data/vendor/aranha-selenium/spec/spec_helper.rb +100 -0
- data/vendor/eac_cli/eac_cli.gemspec +3 -3
- data/vendor/eac_cli/lib/eac_cli/core_ext.rb +4 -0
- data/vendor/eac_cli/lib/eac_cli/default_runner.rb +6 -14
- data/vendor/eac_cli/lib/eac_cli/definition.rb +72 -0
- data/vendor/eac_cli/lib/eac_cli/definition/argument_option.rb +13 -0
- data/vendor/eac_cli/lib/eac_cli/{runner → definition}/base_option.rb +5 -1
- data/vendor/eac_cli/lib/eac_cli/definition/boolean_option.rb +13 -0
- data/vendor/eac_cli/lib/eac_cli/{runner → definition}/positional_argument.rb +5 -1
- data/vendor/eac_cli/lib/eac_cli/{runner/docopt_doc.rb → docopt/doc_builder.rb} +15 -8
- data/vendor/eac_cli/lib/eac_cli/docopt/runner_extension.rb +45 -0
- data/vendor/eac_cli/lib/eac_cli/parser.rb +14 -0
- data/vendor/eac_cli/lib/eac_cli/parser/collector.rb +56 -0
- data/vendor/eac_cli/lib/eac_cli/parser/error.rb +15 -0
- data/vendor/eac_cli/lib/eac_cli/parser/options_collection.rb +105 -0
- data/vendor/eac_cli/lib/eac_cli/parser/parse_result.rb +21 -0
- data/vendor/eac_cli/lib/eac_cli/parser/positional_collection.rb +49 -0
- data/vendor/eac_cli/lib/eac_cli/patches.rb +4 -0
- data/vendor/eac_cli/lib/eac_cli/patches/object.rb +5 -0
- data/vendor/eac_cli/lib/eac_cli/patches/object/runner_with.rb +24 -0
- data/vendor/eac_cli/lib/eac_cli/runner.rb +64 -7
- data/vendor/eac_cli/lib/eac_cli/runner/context.rb +18 -0
- data/vendor/eac_cli/lib/eac_cli/runner_with.rb +9 -0
- data/vendor/eac_cli/lib/eac_cli/runner_with/help.rb +19 -0
- data/vendor/eac_cli/lib/eac_cli/runner_with/output_file.rb +26 -0
- data/vendor/eac_cli/lib/eac_cli/version.rb +1 -1
- data/vendor/eac_cli/spec/lib/eac_cli/runner_spec.rb +70 -0
- data/vendor/eac_docker/Gemfile +5 -0
- data/vendor/eac_docker/eac_docker.gemspec +18 -0
- data/vendor/eac_docker/lib/eac_docker.rb +7 -0
- data/vendor/eac_docker/lib/eac_docker/container.rb +50 -0
- data/vendor/eac_docker/lib/eac_docker/executables.rb +18 -0
- data/vendor/eac_docker/lib/eac_docker/images.rb +9 -0
- data/vendor/eac_docker/lib/eac_docker/images/base.rb +14 -0
- data/vendor/eac_docker/lib/eac_docker/images/named.rb +30 -0
- data/vendor/eac_docker/lib/eac_docker/rspec.rb +17 -0
- data/vendor/eac_docker/lib/eac_docker/version.rb +5 -0
- data/vendor/eac_docker/spec/lib/eac_docker/executables_spec.rb +9 -0
- data/vendor/eac_docker/spec/rubocop_spec.rb +7 -0
- data/vendor/eac_docker/spec/spec_helper.rb +103 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/boolean.rb +31 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern.rb +68 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/configs.rb +4 -12
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs.rb +1 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner.rb +6 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner/_class_methods.rb +3 -3
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner/_subcommands.rb +8 -2
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/speaker.rb +1 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command.rb +1 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/extra_options.rb +8 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/ssh_env.rb +12 -9
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/ssh_env/dasho_options.rb +53 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/ssh_env/identity_file.rb +25 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/ssh_env/quiet.rb +24 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/ssh_env/terminal.rb +34 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs_cache.rb +1 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/immutable.rb +15 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/immutable/array_accessor.rb +32 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/immutable/base_accessor.rb +23 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/immutable/boolean_accessor.rb +16 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/immutable/class_methods.rb +20 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/immutable/common_accessor.rb +30 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/immutable/hash_accessor.rb +46 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/immutable/instance_methods.rb +21 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/inflector.rb +18 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/list.rb +9 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/lists.rb +10 -12
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/symbol_list.rb +19 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/value.rb +3 -2
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/common_concern.rb +10 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/immutable.rb +10 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/patch.rb +1 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/require_sub.rb +2 -2
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_present.rb +1 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_respond.rb +22 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/string.rb +4 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/string/inflector.rb +9 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash.rb +1 -3
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/require_sub.rb +72 -2
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/simple_cache.rb +6 -2
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/struct.rb +53 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/templates/directory.rb +7 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/templates/file.rb +8 -59
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/templates/variable_not_found_error.rb +7 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/templates/variable_providers.rb +25 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/templates/variable_providers/base.rb +23 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/templates/variable_providers/entries_reader.rb +25 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/templates/variable_providers/generic.rb +25 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/templates/variable_providers/hash.rb +29 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/yaml.rb +85 -2
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/common_concern_spec.rb +42 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/common_constructor_spec.rb +1 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/console/docopt_runner_spec.rb +5 -5
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/console/speaker_spec.rb +1 -1
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/envs/executable_spec.rb +4 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/fs/temp/temp_spec.rb +1 -1
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/inflector_spec.rb +15 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/listable_spec.rb +32 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/options_consumer_spec.rb +1 -1
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/hash/sym_keys_hash_spec.rb +1 -1
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/object/if_present_spec.rb +1 -1
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/object/template_spec.rb +1 -1
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/pathname/basename_sub_spec.rb +4 -4
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/require_sub_spec.rb +19 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/require_sub_spec/stubbed_module_a.rb +6 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/require_sub_spec/stubbed_not_module.rb +6 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/ruby_spec.rb +22 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/struct_spec.rb +46 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/templates/file_spec.rb +1 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/templates/searcher_spec.rb +1 -1
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/yaml_spec.rb +75 -0
- data/vendor/eac_ruby_utils/spec/locales/pt-BR.yml +17 -0
- data/vendor/ehbrs_ruby_utils/Gemfile +16 -0
- data/vendor/ehbrs_ruby_utils/ehbrs_ruby_utils.gemspec +20 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils.rb +7 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/executables.rb +28 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/version.rb +5 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos.rb +9 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container.rb +11 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container/file.rb +31 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container/info.rb +21 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/quality.rb +68 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/resolution.rb +68 -0
- data/vendor/ehbrs_ruby_utils/spec/lib/ehbrs_ruby_utils/videos/resolution_spec.rb +18 -0
- data/vendor/ehbrs_ruby_utils/spec/rubocop_check_spec.rb +7 -0
- data/vendor/ehbrs_ruby_utils/spec/spec_helper.rb +100 -0
- metadata +108 -10
- data/vendor/eac_cli/lib/eac_cli/runner/argument_option.rb +0 -13
- data/vendor/eac_cli/lib/eac_cli/runner/boolean_option.rb +0 -13
- data/vendor/eac_cli/lib/eac_cli/runner/definition.rb +0 -64
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/hash_with_indifferent_access'
|
4
|
+
require 'active_support/core_ext/object/blank'
|
5
|
+
|
6
|
+
module EacRubyUtils
|
7
|
+
class Struct
|
8
|
+
def initialize(initial_data = {})
|
9
|
+
self.data = ::ActiveSupport::HashWithIndifferentAccess.new(initial_data)
|
10
|
+
end
|
11
|
+
|
12
|
+
def [](key)
|
13
|
+
key, bool = parse_key(key)
|
14
|
+
bool ? self[key].present? : data[key]
|
15
|
+
end
|
16
|
+
|
17
|
+
def fetch(key)
|
18
|
+
key, bool = parse_key(key)
|
19
|
+
bool ? fetch(key).present? : data.fetch(key)
|
20
|
+
end
|
21
|
+
|
22
|
+
def method_missing(method_name, *arguments, &block)
|
23
|
+
property_method?(method_name) ? fetch(method_name) : super
|
24
|
+
end
|
25
|
+
|
26
|
+
def respond_to_missing?(method_name, include_private = false)
|
27
|
+
property_method?(method_name) || super
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_h
|
31
|
+
data.dup
|
32
|
+
end
|
33
|
+
|
34
|
+
delegate :to_s, to: :data
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
attr_accessor :data
|
39
|
+
|
40
|
+
def parse_key(key)
|
41
|
+
m = /\A(.+)\?\z/.match(key.to_s)
|
42
|
+
[(m ? m[1] : key.to_s).to_sym, m ? true : false]
|
43
|
+
end
|
44
|
+
|
45
|
+
def property_method?(key)
|
46
|
+
property_methods.include?(key.to_sym)
|
47
|
+
end
|
48
|
+
|
49
|
+
def property_methods
|
50
|
+
data.keys.flat_map { |k| [k.to_sym, "#{k}?".to_sym] }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
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 '
|
4
|
-
require 'eac_ruby_utils/
|
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
|
-
|
15
|
-
|
16
|
-
|
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 =
|
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
|
-
|
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
|
-
|
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,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
|
@@ -3,10 +3,93 @@
|
|
3
3
|
require 'yaml'
|
4
4
|
|
5
5
|
module EacRubyUtils
|
6
|
+
# A safe YAML loader/dumper with common types included.
|
6
7
|
class Yaml
|
7
8
|
class << self
|
8
|
-
|
9
|
-
|
9
|
+
DEFAULT_PERMITTED_CLASSES = [::Array, ::Date, ::FalseClass, ::Hash, ::NilClass, ::Numeric,
|
10
|
+
::String, ::Symbol, ::Time, ::TrueClass].freeze
|
11
|
+
|
12
|
+
def dump(object)
|
13
|
+
::YAML.dump(sanitize(object))
|
14
|
+
end
|
15
|
+
|
16
|
+
def load(string)
|
17
|
+
::YAML.safe_load(string, permitted_classes)
|
18
|
+
end
|
19
|
+
|
20
|
+
def permitted_classes
|
21
|
+
DEFAULT_PERMITTED_CLASSES
|
22
|
+
end
|
23
|
+
|
24
|
+
def sanitize(object)
|
25
|
+
Sanitizer.new(object).result
|
26
|
+
end
|
27
|
+
|
28
|
+
def yaml?(object)
|
29
|
+
return false unless object.is_a?(::String)
|
30
|
+
return false unless object.start_with?('---')
|
31
|
+
|
32
|
+
load(object)
|
33
|
+
true
|
34
|
+
rescue ::Psych::SyntaxError
|
35
|
+
false
|
36
|
+
end
|
37
|
+
|
38
|
+
class Sanitizer
|
39
|
+
attr_reader :source
|
40
|
+
|
41
|
+
RESULT_TYPES = %w[permitted enumerableable hashable].freeze
|
42
|
+
|
43
|
+
def initialize(source)
|
44
|
+
@source = source
|
45
|
+
end
|
46
|
+
|
47
|
+
def result
|
48
|
+
RESULT_TYPES.each do |type|
|
49
|
+
return send("result_#{type}") if send("result_#{type}?")
|
50
|
+
end
|
51
|
+
|
52
|
+
source.to_s
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def result_enumerableable?
|
58
|
+
source.respond_to?(:to_a) && !source.is_a?(::Hash)
|
59
|
+
end
|
60
|
+
|
61
|
+
def result_enumerableable
|
62
|
+
source.to_a.map { |child| sanitize_value(child) }
|
63
|
+
end
|
64
|
+
|
65
|
+
def result_hashable?
|
66
|
+
source.respond_to?(:to_h)
|
67
|
+
end
|
68
|
+
|
69
|
+
def result_hashable
|
70
|
+
source.to_h.map { |k, v| [k.to_sym, sanitize_value(v)] }.to_h
|
71
|
+
end
|
72
|
+
|
73
|
+
def result_nil?
|
74
|
+
source.nil?
|
75
|
+
end
|
76
|
+
|
77
|
+
def result_nil
|
78
|
+
nil
|
79
|
+
end
|
80
|
+
|
81
|
+
def result_permitted?
|
82
|
+
(::EacRubyUtils::Yaml.permitted_classes - [::Array, ::Hash])
|
83
|
+
.any? { |klass| source.is_a?(klass) }
|
84
|
+
end
|
85
|
+
|
86
|
+
def result_permitted
|
87
|
+
source
|
88
|
+
end
|
89
|
+
|
90
|
+
def sanitize_value(value)
|
91
|
+
self.class.new(value).result
|
92
|
+
end
|
10
93
|
end
|
11
94
|
end
|
12
95
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/common_concern'
|
4
|
+
|
5
|
+
RSpec.describe ::EacRubyUtils::CommonConcern do
|
6
|
+
let(:instance) do
|
7
|
+
described_class.new do
|
8
|
+
self.valor = 'changed'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
module MyModule
|
13
|
+
module ClassMethods
|
14
|
+
def my_class_method
|
15
|
+
'class'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
module InstanceMethods
|
20
|
+
def my_instance_method
|
21
|
+
'instance'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class MyClass
|
27
|
+
class << self
|
28
|
+
attr_accessor :valor
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
let(:subject) { MyClass.new }
|
33
|
+
|
34
|
+
before do
|
35
|
+
instance.setup(MyModule)
|
36
|
+
MyClass.include MyModule
|
37
|
+
end
|
38
|
+
|
39
|
+
it { expect(subject.my_instance_method).to eq('instance') }
|
40
|
+
it { expect(subject.class.my_class_method).to eq('class') }
|
41
|
+
it { expect(subject.class.valor).to eq('changed') }
|
42
|
+
end
|