ehbrs-tools 0.7.0 → 0.13.0
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 +7 -1
- data/lib/ehbrs/fs.rb +9 -0
- data/lib/ehbrs/fs/compressed_package.rb +48 -0
- 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/finances.rb +19 -0
- data/lib/ehbrs/runner/finances/bb_browser.rb +40 -0
- 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/extract.rb +71 -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/vg/wii/game_file.rb +13 -0
- data/lib/ehbrs/videos/extract.rb +11 -0
- data/lib/ehbrs/videos/extract/package.rb +75 -0
- data/lib/ehbrs/videos/extract/package_file.rb +54 -0
- 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_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/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/_class_methods.rb +1 -1
- 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/executable.rb +2 -2
- 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 +28 -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 +42 -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/listable/list.rb +4 -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/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/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/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/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 +101 -2
@@ -20,5 +20,5 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.add_dependency 'colorize', '~> 0.8.1'
|
21
21
|
s.add_dependency 'docopt', '~> 0.6.1'
|
22
22
|
s.add_dependency 'net-ssh', '~> 4.2'
|
23
|
-
s.add_development_dependency 'eac_ruby_gem_support', '~> 0.1'
|
23
|
+
s.add_development_dependency 'eac_ruby_gem_support', '~> 0.1', '>= 0.1.1'
|
24
24
|
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/concern'
|
4
|
+
require 'eac_ruby_utils/simple_cache'
|
5
|
+
require 'eac_ruby_utils/patches/object/if_present'
|
6
|
+
|
7
|
+
module EacRubyUtils
|
8
|
+
class CommonConcern
|
9
|
+
CLASS_METHODS_MODULE_NAME = 'ClassMethods'
|
10
|
+
INSTANCE_METHODS_MODULE_NAME = 'InstanceMethods'
|
11
|
+
|
12
|
+
attr_reader :after_callback
|
13
|
+
|
14
|
+
def initialize(&after_callback)
|
15
|
+
@after_callback = after_callback
|
16
|
+
end
|
17
|
+
|
18
|
+
def setup(a_module)
|
19
|
+
Setup.new(self, a_module).run
|
20
|
+
end
|
21
|
+
|
22
|
+
class Setup
|
23
|
+
include ::EacRubyUtils::SimpleCache
|
24
|
+
attr_reader :a_module, :common_constructor
|
25
|
+
|
26
|
+
def initialize(common_constructor, a_module)
|
27
|
+
@common_constructor = common_constructor
|
28
|
+
@a_module = a_module
|
29
|
+
end
|
30
|
+
|
31
|
+
def run
|
32
|
+
setup = self
|
33
|
+
a_module.extend(::ActiveSupport::Concern)
|
34
|
+
a_module.included do
|
35
|
+
%w[class_methods instance_methods after_callback].each do |suffix|
|
36
|
+
setup.send("setup_#{suffix}", self)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def setup_class_methods(base)
|
42
|
+
class_methods_module.if_present { |v| base.extend v }
|
43
|
+
end
|
44
|
+
|
45
|
+
def setup_instance_methods(base)
|
46
|
+
instance_methods_module.if_present { |v| base.include v }
|
47
|
+
end
|
48
|
+
|
49
|
+
def setup_after_callback(base)
|
50
|
+
common_constructor.after_callback.if_present do |v|
|
51
|
+
base.instance_eval(&v)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def class_methods_module_uncached
|
56
|
+
a_module.const_get(CLASS_METHODS_MODULE_NAME)
|
57
|
+
rescue NameError
|
58
|
+
nil
|
59
|
+
end
|
60
|
+
|
61
|
+
def instance_methods_module_uncached
|
62
|
+
a_module.const_get(INSTANCE_METHODS_MODULE_NAME)
|
63
|
+
rescue NameError
|
64
|
+
nil
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -20,17 +20,11 @@ module EacRubyUtils
|
|
20
20
|
load
|
21
21
|
end
|
22
22
|
|
23
|
-
|
24
|
-
file.clear
|
25
|
-
end
|
23
|
+
delegate :clear, to: :file
|
26
24
|
|
27
|
-
|
28
|
-
file.save
|
29
|
-
end
|
25
|
+
delegate :save, to: :file
|
30
26
|
|
31
|
-
|
32
|
-
file.load
|
33
|
-
end
|
27
|
+
delegate :load, to: :file
|
34
28
|
|
35
29
|
def []=(entry_key, entry_value)
|
36
30
|
write_entry(entry_key, entry_value)
|
@@ -48,9 +42,7 @@ module EacRubyUtils
|
|
48
42
|
file.read(entry_key)
|
49
43
|
end
|
50
44
|
|
51
|
-
|
52
|
-
file.autosave?
|
53
|
-
end
|
45
|
+
delegate :autosave?, to: :file
|
54
46
|
|
55
47
|
private
|
56
48
|
|
@@ -85,7 +85,7 @@ module EacRubyUtils
|
|
85
85
|
def looped_entry_value_from_input(entry_key, options)
|
86
86
|
loop do
|
87
87
|
entry_value = entry_value_from_input(entry_key, options)
|
88
|
-
next
|
88
|
+
next if entry_value.blank?
|
89
89
|
next if options[:validator] && !options[:validator].call(entry_value)
|
90
90
|
|
91
91
|
return entry_value
|
@@ -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
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacRubyUtils
|
4
|
+
module Fs
|
5
|
+
class << self
|
6
|
+
# A [File.extname] which find multiple extensions (Ex.: .tar.gz).
|
7
|
+
def extname(path, limit = -1)
|
8
|
+
recursive_extension(::File.basename(path), limit)
|
9
|
+
end
|
10
|
+
|
11
|
+
# Shortcut to +extname(2)+.
|
12
|
+
def extname2(path)
|
13
|
+
extname(path, 2)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def recursive_extension(basename, limit)
|
19
|
+
return '' if limit.zero?
|
20
|
+
|
21
|
+
m = /\A(.+)(\.[a-z][a-z0-9]*)\z/i.match(basename)
|
22
|
+
if m
|
23
|
+
"#{recursive_extension(m[1], limit - 1)}#{m[2]}"
|
24
|
+
else
|
25
|
+
''
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -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
|
@@ -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
|
|