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,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,46 @@
|
|
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_get(object)
|
15
|
+
super || {}
|
16
|
+
end
|
17
|
+
|
18
|
+
def immutable_value_set(object, key, value)
|
19
|
+
duplicate_object(object) do |old_value|
|
20
|
+
(old_value || {}).merge(key => value)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def apply_get(klass)
|
27
|
+
accessor = self
|
28
|
+
klass.send(:define_method, ::ActiveSupport::Inflector.pluralize(name)) do
|
29
|
+
accessor.immutable_value_get(self)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def apply_set(klass)
|
34
|
+
accessor = self
|
35
|
+
klass.send(:define_method, name) do |*args|
|
36
|
+
case args.count
|
37
|
+
when 1 then next accessor.immutable_value_get(self, args[0])
|
38
|
+
when 2 then next accessor.immutable_value_set(self, *args[0..1])
|
39
|
+
else
|
40
|
+
raise ::ArgumentError, "wrong number of arguments (given #{args.count}, expected 1..2)"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
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,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
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'eac_ruby_utils/inflector'
|
4
|
+
|
3
5
|
module EacRubyUtils
|
4
6
|
module Listable
|
5
7
|
class Value
|
@@ -16,8 +18,7 @@ module EacRubyUtils
|
|
16
18
|
end
|
17
19
|
|
18
20
|
def constant_name
|
19
|
-
"#{@list.item}_#{@key}"
|
20
|
-
.gsub(/(?:\A_|_\z)/, '').upcase
|
21
|
+
::EacRubyUtils::Inflector.variableize("#{@list.item}_#{@key}").upcase
|
21
22
|
end
|
22
23
|
|
23
24
|
def label
|
@@ -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
|