eac_ruby_utils 0.111.0 → 0.113.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e7deaaf568625e32fc58c45b43ef41e125924595707b3a2ca2ea394d9dc4393
|
4
|
+
data.tar.gz: 4af93c26f87f2918f36cc18b2ad5e3cefa8d6fe6a21bb09282f0112bd2138182
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8144e44599f8dc4b5299a3353e79fc51fa558bcb085e1d8a46d0f40182d06b9c0481f56a4a8b464bddf00a52c67c97d3846875489f90f24d0eba8e87b5ed4384
|
7
|
+
data.tar.gz: 657df0404c6f3060e756198aeeb1181b210b7d18564e4b58437a5d79601e3c62d1f2d5bdb686b221b434c2ad81322817798ea329b77b94c2b110c189631055e0
|
@@ -7,35 +7,46 @@ module EacRubyUtils
|
|
7
7
|
module Immutable
|
8
8
|
class HashAccessor < ::EacRubyUtils::Immutable::BaseAccessor
|
9
9
|
def apply(klass)
|
10
|
-
|
11
|
-
|
10
|
+
apply_plural(klass)
|
11
|
+
apply_singular(klass)
|
12
12
|
end
|
13
13
|
|
14
14
|
def immutable_value_get(object)
|
15
15
|
super || {}
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
def immutable_value_get_single(object, key)
|
19
|
+
immutable_value_get(object)[key]
|
20
|
+
end
|
21
|
+
|
22
|
+
def immutable_value_set(object, new_hash)
|
23
|
+
duplicate_object(object) { |_old_value| new_hash }
|
24
|
+
end
|
25
|
+
|
26
|
+
def immutable_value_set_single(object, key, value)
|
27
|
+
immutable_value_set(object, immutable_value_get(object).merge(key => value))
|
22
28
|
end
|
23
29
|
|
24
30
|
private
|
25
31
|
|
26
|
-
def
|
32
|
+
def apply_plural(klass)
|
27
33
|
accessor = self
|
28
|
-
klass.send(:define_method, ::ActiveSupport::Inflector.pluralize(name)) do
|
29
|
-
|
34
|
+
klass.send(:define_method, ::ActiveSupport::Inflector.pluralize(name)) do |*args|
|
35
|
+
case args.count
|
36
|
+
when 0 then next accessor.immutable_value_get(self)
|
37
|
+
when 1 then next accessor.immutable_value_set(self, args[0])
|
38
|
+
else
|
39
|
+
raise ::ArgumentError, "wrong number of arguments (given #{args.count}, expected 0..1)"
|
40
|
+
end
|
30
41
|
end
|
31
42
|
end
|
32
43
|
|
33
|
-
def
|
44
|
+
def apply_singular(klass)
|
34
45
|
accessor = self
|
35
46
|
klass.send(:define_method, name) do |*args|
|
36
47
|
case args.count
|
37
|
-
when 1 then next accessor.
|
38
|
-
when 2 then next accessor.
|
48
|
+
when 1 then next accessor.immutable_value_get_single(self, args[0])
|
49
|
+
when 2 then next accessor.immutable_value_set_single(self, *args[0..1])
|
39
50
|
else
|
40
51
|
raise ::ArgumentError, "wrong number of arguments (given #{args.count}, expected 1..2)"
|
41
52
|
end
|
@@ -15,13 +15,17 @@ module EacRubyUtils
|
|
15
15
|
}.freeze
|
16
16
|
|
17
17
|
include ::EacRubyUtils::Listable
|
18
|
-
lists.add_symbol :option, :base, :include_modules, :require_dependency
|
18
|
+
lists.add_symbol :option, :base, :include_modules, :require_dependency, :require_mode
|
19
|
+
lists.add_symbol :require_mode, :active_support, :autoload, :kernel
|
19
20
|
|
20
21
|
attr_reader :file, :options
|
21
22
|
|
22
23
|
def initialize(file, options = {})
|
23
24
|
@file = file
|
24
25
|
@options = self.class.lists.option.hash_keys_validate!(options)
|
26
|
+
return unless options[OPTION_REQUIRE_MODE]
|
27
|
+
|
28
|
+
self.class.lists.require_mode.value_validate!(options[OPTION_REQUIRE_MODE])
|
25
29
|
end
|
26
30
|
|
27
31
|
# @return [Boolean]
|
@@ -54,6 +58,15 @@ module EacRubyUtils
|
|
54
58
|
" \"#{options[OPTION_INCLUDE_MODULES]}\""
|
55
59
|
end
|
56
60
|
|
61
|
+
# @return [Symbol]
|
62
|
+
def require_mode
|
63
|
+
return options[OPTION_REQUIRE_MODE] if options[OPTION_REQUIRE_MODE]
|
64
|
+
return REQUIRE_MODE_ACTIVE_SUPPORT if active_support_require?
|
65
|
+
return REQUIRE_MODE_AUTOLOAD if base?
|
66
|
+
|
67
|
+
REQUIRE_MODE_KERNEL
|
68
|
+
end
|
69
|
+
|
57
70
|
def require_sub_files
|
58
71
|
sub_files.each(&:require_file)
|
59
72
|
end
|
@@ -38,26 +38,17 @@ module EacRubyUtils
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def require_file
|
41
|
-
|
41
|
+
send("#{owner.require_mode}_require")
|
42
42
|
end
|
43
43
|
|
44
44
|
private
|
45
45
|
|
46
46
|
def active_support_require
|
47
|
-
return false unless owner.active_support_require?
|
48
|
-
|
49
47
|
::Kernel.require_dependency(path)
|
50
|
-
true
|
51
48
|
end
|
52
49
|
|
53
50
|
def autoload_require
|
54
|
-
|
55
|
-
|
56
|
-
basename = ::File.basename(path, '.*')
|
57
|
-
return false if basename.start_with?('_')
|
58
|
-
|
59
|
-
owner.base.autoload ::ActiveSupport::Inflector.camelize(basename), path
|
60
|
-
true
|
51
|
+
owner.base.autoload ::ActiveSupport::Inflector.camelize(::File.basename(path, '.*')), path
|
61
52
|
end
|
62
53
|
|
63
54
|
def kernel_require
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eac_ruby_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.113.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Esquilo Azul Company
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
version: '2.8'
|
40
40
|
- - ">="
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: 2.8.
|
42
|
+
version: 2.8.4
|
43
43
|
type: :runtime
|
44
44
|
prerelease: false
|
45
45
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -49,7 +49,7 @@ dependencies:
|
|
49
49
|
version: '2.8'
|
50
50
|
- - ">="
|
51
51
|
- !ruby/object:Gem::Version
|
52
|
-
version: 2.8.
|
52
|
+
version: 2.8.4
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
54
|
name: bundler
|
55
55
|
requirement: !ruby/object:Gem::Requirement
|