ehbrs-tools 0.9.0 → 0.13.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/gems.rb +37 -0
- 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/self.rb +19 -0
- data/lib/ehbrs/runner/self/test.rb +30 -0
- data/lib/ehbrs/runner/videos/series.rb +21 -0
- data/lib/ehbrs/runner/videos/series/rename.rb +75 -0
- data/lib/ehbrs/tools/version.rb +1 -1
- data/lib/ehbrs/videos/series.rb +11 -0
- data/lib/ehbrs/videos/series/rename.rb +13 -0
- data/lib/ehbrs/videos/series/rename/directory_group.rb +28 -0
- data/lib/ehbrs/videos/series/rename/file.rb +114 -0
- data/lib/ehbrs/videos/series/rename/file/basename_parser.rb +44 -0
- data/lib/ehbrs/videos/series/rename/file/options.rb +30 -0
- data/lib/ehbrs/videos/series/rename/line_result.rb +26 -0
- data/lib/ehbrs/videos/series/rename/line_result_group.rb +39 -0
- data/lib/ehbrs/videos/series/rename/results_builder.rb +32 -0
- data/lib/ehbrs/videos/series/rename/season_group.rb +39 -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/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 +51 -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/runner.rb +25 -5
- data/vendor/eac_cli/lib/eac_cli/runner/context.rb +18 -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/eac_ruby_utils.gemspec +1 -1
- 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/extname.rb +30 -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/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/struct.rb +47 -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/extname_spec.rb +18 -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
- metadata +103 -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,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,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacRubyUtils
|
4
|
+
class Inflector
|
5
|
+
class << self
|
6
|
+
VARIABLE_NAME_PATTERN = /[_a-z][_a-z0-9]*/i.freeze
|
7
|
+
|
8
|
+
def variableize(string)
|
9
|
+
r = string.gsub(/[^_a-z0-9]/i, '_').gsub(/_+/, '_').gsub(/_\z/, '').gsub(/\A_/, '').downcase
|
10
|
+
m = VARIABLE_NAME_PATTERN.match(r)
|
11
|
+
return r if m
|
12
|
+
|
13
|
+
raise ::ArgumentError, "Invalid variable name \"#{r}\" was generated " \
|
14
|
+
"from string \"#{string}\""
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -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
|
@@ -29,6 +33,11 @@ module EacRubyUtils
|
|
29
33
|
find_list_by_method(name) || super
|
30
34
|
end
|
31
35
|
|
36
|
+
def hash_keys_validate!(hash, error_class = ::StandardError)
|
37
|
+
hash.keys.each { |key| value_validate!(key, error_class) }
|
38
|
+
hash
|
39
|
+
end
|
40
|
+
|
32
41
|
def i18n_key
|
33
42
|
"eac_ruby_utils.listable.#{class_i18n_key}.#{item}"
|
34
43
|
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
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
@@ -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
|
8
|
+
return default_value if blank?
|
9
9
|
|
10
10
|
block_given? ? yield(self) : self
|
11
11
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/core_ext/object/blank'
|
4
|
+
|
5
|
+
class Object
|
6
|
+
# @return +block.call(self.method_name)+ if +self+ responds to +method_name+, +default_value+
|
7
|
+
# otherwise.
|
8
|
+
def if_respond(method_name, default_value = nil)
|
9
|
+
return default_value unless respond_to?(method_name)
|
10
|
+
|
11
|
+
value = send(method_name)
|
12
|
+
|
13
|
+
block_given? ? yield(value) : value
|
14
|
+
end
|
15
|
+
|
16
|
+
# @return +yield+ if +self+ is blank.
|
17
|
+
def if_blank
|
18
|
+
return yield if blank? && block_given?
|
19
|
+
|
20
|
+
self
|
21
|
+
end
|
22
|
+
end
|
@@ -1,11 +1,81 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'active_support/inflector'
|
4
|
+
require 'eac_ruby_utils/listable'
|
5
|
+
|
3
6
|
module EacRubyUtils
|
4
7
|
class << self
|
5
|
-
def require_sub(file)
|
8
|
+
def require_sub(file, options = {})
|
9
|
+
::EacRubyUtils::RequireSub.new(file, options).apply
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class RequireSub
|
14
|
+
include ::EacRubyUtils::Listable
|
15
|
+
lists.add_symbol :option, :base, :include_modules, :require_dependency
|
16
|
+
|
17
|
+
attr_reader :file, :options
|
18
|
+
|
19
|
+
def initialize(file, options = {})
|
20
|
+
@file = file
|
21
|
+
@options = self.class.lists.option.hash_keys_validate!(options)
|
22
|
+
end
|
23
|
+
|
24
|
+
def apply
|
25
|
+
require_sub_files
|
26
|
+
include_modules
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def active_support_require(path)
|
32
|
+
return false unless options[OPTION_REQUIRE_DEPENDENCY]
|
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
|
+
|
48
|
+
def include_modules
|
49
|
+
return unless options[OPTION_INCLUDE_MODULES]
|
50
|
+
|
51
|
+
base.constants.each do |constant_name|
|
52
|
+
constant = base.const_get(constant_name)
|
53
|
+
next unless constant.is_a?(::Module) && !constant.is_a?(::Class)
|
54
|
+
|
55
|
+
base.include(constant)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def base
|
60
|
+
options[OPTION_BASE] || raise('Option :base not setted')
|
61
|
+
end
|
62
|
+
|
63
|
+
def base?
|
64
|
+
options[OPTION_BASE] ? true : false
|
65
|
+
end
|
66
|
+
|
67
|
+
def kernel_require(path)
|
68
|
+
::Kernel.require(path)
|
69
|
+
end
|
70
|
+
|
71
|
+
def require_sub_files
|
6
72
|
Dir["#{File.dirname(file)}/#{::File.basename(file, '.*')}/*.rb"].sort.each do |path|
|
7
|
-
|
73
|
+
require_sub_file(path)
|
8
74
|
end
|
9
75
|
end
|
76
|
+
|
77
|
+
def require_sub_file(path)
|
78
|
+
active_support_require(path) || autoload_require(path) || kernel_require(path)
|
79
|
+
end
|
10
80
|
end
|
11
81
|
end
|
@@ -0,0 +1,47 @@
|
|
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
|
+
private
|
31
|
+
|
32
|
+
attr_accessor :data
|
33
|
+
|
34
|
+
def parse_key(key)
|
35
|
+
m = /\A(.+)\?\z/.match(key.to_s)
|
36
|
+
[(m ? m[1] : key.to_s).to_sym, m ? true : false]
|
37
|
+
end
|
38
|
+
|
39
|
+
def property_method?(key)
|
40
|
+
property_methods.include?(key.to_sym)
|
41
|
+
end
|
42
|
+
|
43
|
+
def property_methods
|
44
|
+
data.keys.flat_map { |k| [k.to_sym, "#{k}?".to_sym] }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
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
|