eac_ruby_utils 0.54.0 → 0.57.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/eac_ruby_utils/common_concern.rb +2 -50
- data/lib/eac_ruby_utils/common_concern/class_setup.rb +52 -0
- data/lib/eac_ruby_utils/common_concern/module_setup.rb +41 -0
- data/lib/eac_ruby_utils/common_constructor.rb +2 -99
- data/lib/eac_ruby_utils/common_constructor/class_initialize.rb +29 -0
- data/lib/eac_ruby_utils/common_constructor/instance_initialize.rb +53 -0
- data/lib/eac_ruby_utils/common_constructor/super_args.rb +54 -0
- data/lib/eac_ruby_utils/console/docopt_runner/_subcommands.rb +10 -1
- data/lib/eac_ruby_utils/envs/command.rb +4 -6
- data/lib/eac_ruby_utils/envs/command/concat.rb +33 -0
- data/lib/eac_ruby_utils/envs/command/envvars.rb +24 -0
- data/lib/eac_ruby_utils/envs/command/extra_options.rb +0 -21
- data/lib/eac_ruby_utils/patches/module/template.rb +10 -0
- data/lib/eac_ruby_utils/patches/object/template.rb +1 -8
- data/lib/eac_ruby_utils/patches/pathname/basename_sub.rb +2 -2
- data/lib/eac_ruby_utils/struct.rb +7 -1
- data/lib/eac_ruby_utils/version.rb +1 -1
- data/lib/eac_ruby_utils/yaml.rb +8 -0
- metadata +10 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 65af57191dbd9317c68eb8e171e53e4c39877f88d7ce212e0701703b6ff83d11
|
4
|
+
data.tar.gz: c6caa9d9461c8055f1977cfb9ea4446bc2cef0fd2c1c0e919fcde296512aff30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e1e8ed1d73a37aff540712171468c9f03107cf956a1d52ef0b66a4518e679bc0f156ba06027afd0a450a94995445f6806432f2295f774d81442f76467b34180e
|
7
|
+
data.tar.gz: cbd75d3662cc207ac95750b3248d1904c96886c62b55494dedfbd1de22238359801cc8d49c01e51c075a376a95da445022def8546e3672401dc41796d136e3cd
|
@@ -1,8 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
4
|
-
require 'eac_ruby_utils/simple_cache'
|
5
|
-
require 'eac_ruby_utils/patches/object/if_present'
|
3
|
+
require 'eac_ruby_utils/common_concern/module_setup'
|
6
4
|
|
7
5
|
module EacRubyUtils
|
8
6
|
class CommonConcern
|
@@ -16,53 +14,7 @@ module EacRubyUtils
|
|
16
14
|
end
|
17
15
|
|
18
16
|
def setup(a_module)
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
class Setup
|
23
|
-
include ::EacRubyUtils::SimpleCache
|
24
|
-
attr_reader :a_module, :common_concern
|
25
|
-
|
26
|
-
def initialize(common_concern, a_module)
|
27
|
-
@common_concern = common_concern
|
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_concern.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
|
17
|
+
::EacRubyUtils::CommonConcern::ModuleSetup.new(self, a_module).run
|
66
18
|
end
|
67
19
|
end
|
68
20
|
end
|
@@ -0,0 +1,52 @@
|
|
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 ClassSetup
|
10
|
+
include ::EacRubyUtils::SimpleCache
|
11
|
+
attr_reader :a_class, :module_setup, :include_method
|
12
|
+
|
13
|
+
def initialize(module_setup, a_class, include_method)
|
14
|
+
@module_setup = module_setup
|
15
|
+
@a_class = a_class
|
16
|
+
@include_method = include_method
|
17
|
+
end
|
18
|
+
|
19
|
+
def run
|
20
|
+
%w[class_methods instance_methods after_callback].each do |suffix|
|
21
|
+
send("setup_#{suffix}")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def setup_class_methods
|
26
|
+
class_methods_module.if_present { |v| a_class.extend v }
|
27
|
+
end
|
28
|
+
|
29
|
+
def setup_instance_methods
|
30
|
+
instance_methods_module.if_present { |v| a_class.send(include_method, v) }
|
31
|
+
end
|
32
|
+
|
33
|
+
def setup_after_callback
|
34
|
+
module_setup.common_concern.after_callback.if_present do |v|
|
35
|
+
a_class.instance_eval(&v)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def class_methods_module_uncached
|
40
|
+
module_setup.a_module.const_get(CLASS_METHODS_MODULE_NAME)
|
41
|
+
rescue NameError
|
42
|
+
nil
|
43
|
+
end
|
44
|
+
|
45
|
+
def instance_methods_module_uncached
|
46
|
+
module_setup.a_module.const_get(INSTANCE_METHODS_MODULE_NAME)
|
47
|
+
rescue NameError
|
48
|
+
nil
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/concern'
|
4
|
+
require 'eac_ruby_utils/common_concern/class_setup'
|
5
|
+
require 'eac_ruby_utils/simple_cache'
|
6
|
+
require 'eac_ruby_utils/patches/object/if_present'
|
7
|
+
|
8
|
+
module EacRubyUtils
|
9
|
+
class CommonConcern
|
10
|
+
class ModuleSetup
|
11
|
+
include ::EacRubyUtils::SimpleCache
|
12
|
+
attr_reader :a_module, :common_concern
|
13
|
+
|
14
|
+
def initialize(common_concern, a_module)
|
15
|
+
@common_concern = common_concern
|
16
|
+
@a_module = a_module
|
17
|
+
end
|
18
|
+
|
19
|
+
def run
|
20
|
+
a_module.extend(::ActiveSupport::Concern)
|
21
|
+
include_or_prepend(:included, :include)
|
22
|
+
include_or_prepend(:prepended, :prepend)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def include_or_prepend(module_method, class_setup_method)
|
28
|
+
setup = self
|
29
|
+
a_module.send(module_method, *a_module_method_args(module_method)) do
|
30
|
+
::EacRubyUtils::CommonConcern::ClassSetup.new(setup, self, class_setup_method).run
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def a_module_method_args(module_method)
|
35
|
+
method_arity = a_module.method(module_method).arity
|
36
|
+
method_arity = -method_arity - 1 if method_arity.negative?
|
37
|
+
method_arity.times.map { |_n| a_module }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'active_support/callbacks'
|
4
4
|
require 'eac_ruby_utils/arguments_consumer'
|
5
|
+
require 'eac_ruby_utils/common_constructor/class_initialize'
|
5
6
|
require 'ostruct'
|
6
7
|
|
7
8
|
module EacRubyUtils
|
@@ -76,111 +77,13 @@ module EacRubyUtils
|
|
76
77
|
end
|
77
78
|
|
78
79
|
def setup_class_initialize(klass)
|
79
|
-
common_constructor = self
|
80
80
|
klass.include(::ActiveSupport::Callbacks)
|
81
81
|
klass.define_callbacks :initialize
|
82
|
-
|
83
|
-
Initialize.new(common_constructor, args, self).run
|
84
|
-
super(*SuperArgs.new(common_constructor, args, self).result)
|
85
|
-
end
|
82
|
+
::EacRubyUtils::CommonConstructor::ClassInitialize.new(self, klass).run
|
86
83
|
end
|
87
84
|
|
88
85
|
def super_args
|
89
86
|
options[:super_args]
|
90
87
|
end
|
91
|
-
|
92
|
-
class Initialize
|
93
|
-
attr_reader :common_constructor, :args, :object
|
94
|
-
|
95
|
-
def initialize(common_constructor, args, object)
|
96
|
-
@common_constructor = common_constructor
|
97
|
-
@args = args
|
98
|
-
@object = object
|
99
|
-
end
|
100
|
-
|
101
|
-
def run
|
102
|
-
validate_args_count
|
103
|
-
object.run_callbacks :initialize do
|
104
|
-
object_attributes_set
|
105
|
-
object_after_callback
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
private
|
110
|
-
|
111
|
-
def arg_value(arg_name)
|
112
|
-
arg_index = common_constructor.args.index(arg_name)
|
113
|
-
if arg_index < args.count
|
114
|
-
args[arg_index]
|
115
|
-
else
|
116
|
-
common_constructor.default_values[arg_index - common_constructor.args_count_min]
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
def object_after_callback
|
121
|
-
return unless common_constructor.after_set_block
|
122
|
-
|
123
|
-
object.instance_eval(&common_constructor.after_set_block)
|
124
|
-
end
|
125
|
-
|
126
|
-
def object_attributes_set
|
127
|
-
common_constructor.args.each do |arg_name|
|
128
|
-
object.send("#{arg_name}=", arg_value(arg_name))
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
def validate_args_count
|
133
|
-
return if common_constructor.args_count.include?(args.count)
|
134
|
-
|
135
|
-
raise ArgumentError, "#{object.class}.initialize: wrong number of arguments" \
|
136
|
-
" (given #{args.count}, expected #{common_constructor.args_count})"
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
class SuperArgs
|
141
|
-
attr_reader :common_constructor, :args, :object
|
142
|
-
|
143
|
-
def initialize(common_constructor, args, object)
|
144
|
-
@common_constructor = common_constructor
|
145
|
-
@args = args
|
146
|
-
@object = object
|
147
|
-
end
|
148
|
-
|
149
|
-
def auto_result
|
150
|
-
r = []
|
151
|
-
sub_args.each do |name, value|
|
152
|
-
i = super_arg_index(name)
|
153
|
-
r[i] = value if i
|
154
|
-
end
|
155
|
-
r
|
156
|
-
end
|
157
|
-
|
158
|
-
def result
|
159
|
-
result_from_options || auto_result
|
160
|
-
end
|
161
|
-
|
162
|
-
def result_from_options
|
163
|
-
return unless common_constructor.super_args
|
164
|
-
|
165
|
-
object.instance_exec(&common_constructor.super_args)
|
166
|
-
end
|
167
|
-
|
168
|
-
def sub_args
|
169
|
-
common_constructor.args.each_with_index.map do |name, index|
|
170
|
-
[name, args[index]]
|
171
|
-
end.to_h
|
172
|
-
end
|
173
|
-
|
174
|
-
def super_arg_index(name)
|
175
|
-
super_method.parameters.each_with_index do |arg, index|
|
176
|
-
return index if arg[1] == name
|
177
|
-
end
|
178
|
-
nil
|
179
|
-
end
|
180
|
-
|
181
|
-
def super_method
|
182
|
-
object.class.superclass ? object.class.superclass.instance_method(:initialize) : nil
|
183
|
-
end
|
184
|
-
end
|
185
88
|
end
|
186
89
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/common_constructor/instance_initialize'
|
4
|
+
require 'eac_ruby_utils/common_constructor/super_args'
|
5
|
+
|
6
|
+
module EacRubyUtils
|
7
|
+
class CommonConstructor
|
8
|
+
class ClassInitialize
|
9
|
+
attr_reader :common_constructor, :klass
|
10
|
+
|
11
|
+
def initialize(common_constructor, klass)
|
12
|
+
@common_constructor = common_constructor
|
13
|
+
@klass = klass
|
14
|
+
end
|
15
|
+
|
16
|
+
def run
|
17
|
+
class_initialize = self
|
18
|
+
klass.send(:define_method, :initialize) do |*args|
|
19
|
+
::EacRubyUtils::CommonConstructor::InstanceInitialize.new(
|
20
|
+
class_initialize.common_constructor, args, self
|
21
|
+
).run
|
22
|
+
super(*::EacRubyUtils::CommonConstructor::SuperArgs.new(
|
23
|
+
class_initialize, args, self
|
24
|
+
).result)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacRubyUtils
|
4
|
+
class CommonConstructor
|
5
|
+
class InstanceInitialize
|
6
|
+
attr_reader :common_constructor, :args, :object
|
7
|
+
|
8
|
+
def initialize(common_constructor, args, object)
|
9
|
+
@common_constructor = common_constructor
|
10
|
+
@args = args
|
11
|
+
@object = object
|
12
|
+
end
|
13
|
+
|
14
|
+
def run
|
15
|
+
validate_args_count
|
16
|
+
object.run_callbacks :initialize do
|
17
|
+
object_attributes_set
|
18
|
+
object_after_callback
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def arg_value(arg_name)
|
25
|
+
arg_index = common_constructor.args.index(arg_name)
|
26
|
+
if arg_index < args.count
|
27
|
+
args[arg_index]
|
28
|
+
else
|
29
|
+
common_constructor.default_values[arg_index - common_constructor.args_count_min]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def object_after_callback
|
34
|
+
return unless common_constructor.after_set_block
|
35
|
+
|
36
|
+
object.instance_eval(&common_constructor.after_set_block)
|
37
|
+
end
|
38
|
+
|
39
|
+
def object_attributes_set
|
40
|
+
common_constructor.args.each do |arg_name|
|
41
|
+
object.send("#{arg_name}=", arg_value(arg_name))
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def validate_args_count
|
46
|
+
return if common_constructor.args_count.include?(args.count)
|
47
|
+
|
48
|
+
raise ArgumentError, "#{object.class}.initialize: wrong number of arguments" \
|
49
|
+
" (given #{args.count}, expected #{common_constructor.args_count})"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/core_ext/module/delegation'
|
4
|
+
|
5
|
+
module EacRubyUtils
|
6
|
+
class CommonConstructor
|
7
|
+
class SuperArgs
|
8
|
+
attr_reader :class_initialize, :args, :object
|
9
|
+
delegate :common_constructor, to: :class_initialize
|
10
|
+
|
11
|
+
def initialize(class_initialize, args, object)
|
12
|
+
@class_initialize = class_initialize
|
13
|
+
@args = args
|
14
|
+
@object = object
|
15
|
+
end
|
16
|
+
|
17
|
+
def auto_result
|
18
|
+
r = []
|
19
|
+
sub_args.each do |name, value|
|
20
|
+
i = super_arg_index(name)
|
21
|
+
r[i] = value if i
|
22
|
+
end
|
23
|
+
r
|
24
|
+
end
|
25
|
+
|
26
|
+
def result
|
27
|
+
result_from_options || auto_result
|
28
|
+
end
|
29
|
+
|
30
|
+
def result_from_options
|
31
|
+
return unless common_constructor.super_args
|
32
|
+
|
33
|
+
object.instance_exec(&common_constructor.super_args)
|
34
|
+
end
|
35
|
+
|
36
|
+
def sub_args
|
37
|
+
common_constructor.args.each_with_index.map do |name, index|
|
38
|
+
[name, args[index]]
|
39
|
+
end.to_h
|
40
|
+
end
|
41
|
+
|
42
|
+
def super_arg_index(name)
|
43
|
+
super_method.parameters.each_with_index do |arg, index|
|
44
|
+
return index if arg[1] == name
|
45
|
+
end
|
46
|
+
nil
|
47
|
+
end
|
48
|
+
|
49
|
+
def super_method
|
50
|
+
class_initialize.klass.superclass&.instance_method(:initialize)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -38,7 +38,7 @@ module EacRubyUtils
|
|
38
38
|
def run_with_subcommand
|
39
39
|
if subcommand_name
|
40
40
|
check_valid_subcommand
|
41
|
-
|
41
|
+
subcommand_run
|
42
42
|
else
|
43
43
|
run_without_subcommand
|
44
44
|
end
|
@@ -52,6 +52,15 @@ module EacRubyUtils
|
|
52
52
|
)
|
53
53
|
end
|
54
54
|
|
55
|
+
def subcommand_run
|
56
|
+
if !subcommand.is_a?(::EacRubyUtils::Console::DocoptRunner) &&
|
57
|
+
subcommand.respond_to?(:run_run)
|
58
|
+
subcommand.run_run
|
59
|
+
else
|
60
|
+
subcommand.run
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
55
64
|
def target_doc
|
56
65
|
super.gsub(SUBCOMMANDS_MACRO,
|
57
66
|
"#{target_doc_subcommand_arg} [#{SUBCOMMAND_ARGS_ARG}...]") +
|
@@ -1,8 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
4
|
-
require 'eac_ruby_utils/console/speaker'
|
5
|
-
require 'eac_ruby_utils/envs/command/extra_options'
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
6
4
|
require 'eac_ruby_utils/envs/process'
|
7
5
|
require 'eac_ruby_utils/envs/spawn'
|
8
6
|
require 'pp'
|
@@ -11,8 +9,8 @@ require 'shellwords'
|
|
11
9
|
module EacRubyUtils
|
12
10
|
module Envs
|
13
11
|
class Command
|
14
|
-
|
15
|
-
|
12
|
+
require_sub __FILE__, include_modules: true
|
13
|
+
enable_console_speaker
|
16
14
|
|
17
15
|
def initialize(env, command, extra_options = {})
|
18
16
|
@env = env
|
@@ -47,7 +45,7 @@ module EacRubyUtils
|
|
47
45
|
c = c.map { |x| escape(x) }.join(' ') if c.is_a?(Enumerable)
|
48
46
|
append_command_options(
|
49
47
|
@env.command_line(
|
50
|
-
append_chdir(
|
48
|
+
append_chdir(append_concat(append_envvars(c)))
|
51
49
|
),
|
52
50
|
options
|
53
51
|
)
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/struct'
|
4
|
+
|
5
|
+
module EacRubyUtils
|
6
|
+
module Envs
|
7
|
+
class Command
|
8
|
+
module Concat
|
9
|
+
def concat(operator, other_command)
|
10
|
+
duplicate_by_extra_options(concat: ::EacRubyUtils::Struct.new(
|
11
|
+
operator: operator, command: other_command
|
12
|
+
))
|
13
|
+
end
|
14
|
+
|
15
|
+
def or(other_command)
|
16
|
+
concat('||', other_command)
|
17
|
+
end
|
18
|
+
|
19
|
+
def pipe(other_command)
|
20
|
+
concat('|', other_command)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def append_concat(command)
|
26
|
+
extra_options[:concat].if_present(command) do |v|
|
27
|
+
"#{command} #{v.operator} #{v.command.command}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacRubyUtils
|
4
|
+
module Envs
|
5
|
+
class Command
|
6
|
+
module Envvars
|
7
|
+
def envvar(name, value)
|
8
|
+
duplicate_by_extra_options(envvars: envvars.merge(name => value))
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def append_envvars(command)
|
14
|
+
e = envvars.map { |k, v| "#{Shellwords.escape(k)}=#{Shellwords.escape(v)}" }.join(' ')
|
15
|
+
e.present? ? "#{e} #{command}" : command
|
16
|
+
end
|
17
|
+
|
18
|
+
def envvars
|
19
|
+
extra_options[:envvars] ||= {}.with_indifferent_access
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -12,39 +12,18 @@ module EacRubyUtils
|
|
12
12
|
duplicate_by_extra_options(chdir: dir)
|
13
13
|
end
|
14
14
|
|
15
|
-
def envvar(name, value)
|
16
|
-
duplicate_by_extra_options(envvars: envvars.merge(name => value))
|
17
|
-
end
|
18
|
-
|
19
15
|
def status_result(status_code, result)
|
20
16
|
duplicate_by_extra_options(status_results: status_results.merge(status_code => result))
|
21
17
|
end
|
22
18
|
|
23
|
-
def pipe(other_command)
|
24
|
-
duplicate_by_extra_options(pipe: other_command)
|
25
|
-
end
|
26
|
-
|
27
19
|
private
|
28
20
|
|
29
21
|
attr_reader :extra_options
|
30
22
|
|
31
|
-
def envvars
|
32
|
-
extra_options[:envvars] ||= {}.with_indifferent_access
|
33
|
-
end
|
34
|
-
|
35
23
|
def status_results
|
36
24
|
extra_options[:status_results] ||= {}.with_indifferent_access
|
37
25
|
end
|
38
26
|
|
39
|
-
def append_envvars(command)
|
40
|
-
e = envvars.map { |k, v| "#{Shellwords.escape(k)}=#{Shellwords.escape(v)}" }.join(' ')
|
41
|
-
e.present? ? "#{e} #{command}" : command
|
42
|
-
end
|
43
|
-
|
44
|
-
def append_pipe(command)
|
45
|
-
extra_options[:pipe].present? ? "#{command} | #{extra_options[:pipe].command}" : command
|
46
|
-
end
|
47
|
-
|
48
27
|
def append_chdir(command)
|
49
28
|
extra_options[:chdir].present? ? "(cd '#{extra_options[:chdir]}' ; #{command} )" : command
|
50
29
|
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/core_ext/string/inflections'
|
4
|
+
require 'eac_ruby_utils/templates/searcher'
|
5
|
+
|
6
|
+
class Module
|
7
|
+
def template
|
8
|
+
@template ||= ::EacRubyUtils::Templates::Searcher.default.template(name.underscore)
|
9
|
+
end
|
10
|
+
end
|
@@ -1,15 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
4
|
-
require 'eac_ruby_utils/templates/searcher'
|
3
|
+
require 'eac_ruby_utils/patches/module/template'
|
5
4
|
|
6
5
|
class Object
|
7
|
-
class << self
|
8
|
-
def template
|
9
|
-
@template ||= ::EacRubyUtils::Templates::Searcher.default.template(name.underscore)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
6
|
def template
|
14
7
|
self.class.template
|
15
8
|
end
|
@@ -1,12 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'active_support/hash_with_indifferent_access'
|
4
|
+
require 'active_support/core_ext/module/delegation'
|
4
5
|
require 'active_support/core_ext/object/blank'
|
5
6
|
|
6
7
|
module EacRubyUtils
|
7
8
|
class Struct
|
8
9
|
def initialize(initial_data = {})
|
9
|
-
self.data =
|
10
|
+
self.data = initial_data.symbolize_keys
|
10
11
|
end
|
11
12
|
|
12
13
|
def [](key)
|
@@ -19,6 +20,11 @@ module EacRubyUtils
|
|
19
20
|
bool ? fetch(key).present? : data.fetch(key)
|
20
21
|
end
|
21
22
|
|
23
|
+
def merge(other)
|
24
|
+
other = self.class.new(other) unless other.is_a?(self.class)
|
25
|
+
self.class.new(to_h.merge(other.to_h))
|
26
|
+
end
|
27
|
+
|
22
28
|
def method_missing(method_name, *arguments, &block)
|
23
29
|
property_method?(method_name) ? fetch(method_name) : super
|
24
30
|
end
|
data/lib/eac_ruby_utils/yaml.rb
CHANGED
@@ -14,10 +14,18 @@ module EacRubyUtils
|
|
14
14
|
::YAML.dump(sanitize(object))
|
15
15
|
end
|
16
16
|
|
17
|
+
def dump_file(path, object)
|
18
|
+
::File.write(path.to_s, dump(object))
|
19
|
+
end
|
20
|
+
|
17
21
|
def load(string)
|
18
22
|
::YAML.safe_load(string, permitted_classes)
|
19
23
|
end
|
20
24
|
|
25
|
+
def load_file(path)
|
26
|
+
load(::File.read(path.to_s))
|
27
|
+
end
|
28
|
+
|
21
29
|
def permitted_classes
|
22
30
|
DEFAULT_PERMITTED_CLASSES
|
23
31
|
end
|
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.57.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:
|
11
|
+
date: 2021-01-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -114,7 +114,12 @@ files:
|
|
114
114
|
- lib/eac_ruby_utils/boolean.rb
|
115
115
|
- lib/eac_ruby_utils/by_reference.rb
|
116
116
|
- lib/eac_ruby_utils/common_concern.rb
|
117
|
+
- lib/eac_ruby_utils/common_concern/class_setup.rb
|
118
|
+
- lib/eac_ruby_utils/common_concern/module_setup.rb
|
117
119
|
- lib/eac_ruby_utils/common_constructor.rb
|
120
|
+
- lib/eac_ruby_utils/common_constructor/class_initialize.rb
|
121
|
+
- lib/eac_ruby_utils/common_constructor/instance_initialize.rb
|
122
|
+
- lib/eac_ruby_utils/common_constructor/super_args.rb
|
118
123
|
- lib/eac_ruby_utils/configs.rb
|
119
124
|
- lib/eac_ruby_utils/configs/base.rb
|
120
125
|
- lib/eac_ruby_utils/configs/file.rb
|
@@ -140,6 +145,8 @@ files:
|
|
140
145
|
- lib/eac_ruby_utils/envs.rb
|
141
146
|
- lib/eac_ruby_utils/envs/base_env.rb
|
142
147
|
- lib/eac_ruby_utils/envs/command.rb
|
148
|
+
- lib/eac_ruby_utils/envs/command/concat.rb
|
149
|
+
- lib/eac_ruby_utils/envs/command/envvars.rb
|
143
150
|
- lib/eac_ruby_utils/envs/command/extra_options.rb
|
144
151
|
- lib/eac_ruby_utils/envs/executable.rb
|
145
152
|
- lib/eac_ruby_utils/envs/file.rb
|
@@ -202,6 +209,7 @@ files:
|
|
202
209
|
- lib/eac_ruby_utils/patches/module/patch.rb
|
203
210
|
- lib/eac_ruby_utils/patches/module/require_sub.rb
|
204
211
|
- lib/eac_ruby_utils/patches/module/simple_cache.rb
|
212
|
+
- lib/eac_ruby_utils/patches/module/template.rb
|
205
213
|
- lib/eac_ruby_utils/patches/object.rb
|
206
214
|
- lib/eac_ruby_utils/patches/object/asserts.rb
|
207
215
|
- lib/eac_ruby_utils/patches/object/debug.rb
|