eac_ruby_utils 0.36.1 → 0.41.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/eac_ruby_utils/envs/command.rb +1 -0
- data/lib/eac_ruby_utils/envs/command/extra_options.rb +8 -0
- data/lib/eac_ruby_utils/envs/ssh_env.rb +12 -1
- data/lib/eac_ruby_utils/fs_cache.rb +1 -0
- data/lib/eac_ruby_utils/immutable.rb +15 -0
- data/lib/eac_ruby_utils/immutable/array_accessor.rb +32 -0
- data/lib/eac_ruby_utils/immutable/base_accessor.rb +23 -0
- data/lib/eac_ruby_utils/immutable/boolean_accessor.rb +16 -0
- data/lib/eac_ruby_utils/immutable/class_methods.rb +20 -0
- data/lib/eac_ruby_utils/immutable/common_accessor.rb +30 -0
- data/lib/eac_ruby_utils/immutable/hash_accessor.rb +46 -0
- data/lib/eac_ruby_utils/immutable/instance_methods.rb +21 -0
- data/lib/eac_ruby_utils/patches/module/immutable.rb +10 -0
- data/lib/eac_ruby_utils/require_sub.rb +32 -5
- data/lib/eac_ruby_utils/templates/directory.rb +7 -1
- data/lib/eac_ruby_utils/templates/file.rb +8 -59
- data/lib/eac_ruby_utils/templates/variable_not_found_error.rb +7 -0
- data/lib/eac_ruby_utils/templates/variable_providers.rb +25 -0
- data/lib/eac_ruby_utils/templates/variable_providers/base.rb +23 -0
- data/lib/eac_ruby_utils/templates/variable_providers/entries_reader.rb +25 -0
- data/lib/eac_ruby_utils/templates/variable_providers/generic.rb +25 -0
- data/lib/eac_ruby_utils/templates/variable_providers/hash.rb +29 -0
- data/lib/eac_ruby_utils/version.rb +1 -1
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e04909bde0d65f8b8615601194b4fb9c1fb3b6b56f6bf02cd98103fe0510e7b
|
4
|
+
data.tar.gz: 902d0c69a54f0a0330c4e47afa498501b02beec6367c6d952f6d72f8388b74c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cbaf478b74fbb77fff8682b733685773ad8c3de4eac8e5fc9c2adcca81fbeac56a5e4df330c0ffb60097f1c3d75b371270814b52ca1bd54ef77fa417adf55284
|
7
|
+
data.tar.gz: 947edd1f4ba4f942ba78ed5e17f99b95d1d89f456426437efa6c3eb35128c12b312fb628f962f0e123a38d8ea37c6fa7a135d1c4c4d7d1b6f9b6449e465458ed
|
@@ -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
|
@@ -2,12 +2,14 @@
|
|
2
2
|
|
3
3
|
require 'addressable'
|
4
4
|
require 'eac_ruby_utils/envs/base_env'
|
5
|
+
require 'eac_ruby_utils/patches/object/if_present'
|
5
6
|
require 'net/ssh'
|
6
7
|
require 'shellwords'
|
7
8
|
|
8
9
|
module EacRubyUtils
|
9
10
|
module Envs
|
10
11
|
class SshEnv < ::EacRubyUtils::Envs::BaseEnv
|
12
|
+
IDENTITITY_FILE_OPTION = 'IdentityFile'
|
11
13
|
USER_PATTERN = /[a-z_][a-z0-9_-]*/.freeze
|
12
14
|
HOSTNAME_PATTERN = /[^@]+/.freeze
|
13
15
|
USER_HOSTNAME_PATTERN = /\A(?:(#{USER_PATTERN})@)?(#{HOSTNAME_PATTERN})\z/.freeze
|
@@ -51,6 +53,7 @@ module EacRubyUtils
|
|
51
53
|
def ssh_command_line
|
52
54
|
r = %w[ssh]
|
53
55
|
r += ['-p', uri.port] if uri.port.present?
|
56
|
+
ssh_identity_file.if_present { |v| r += ['-i', v] }
|
54
57
|
r += ssh_command_line_options
|
55
58
|
r << user_hostname_uri
|
56
59
|
r.map { |a| Shellwords.escape(a) }.join(' ')
|
@@ -58,7 +61,9 @@ module EacRubyUtils
|
|
58
61
|
|
59
62
|
def ssh_command_line_options
|
60
63
|
r = []
|
61
|
-
uri.query_values&.each
|
64
|
+
uri.query_values&.each do |k, v|
|
65
|
+
r += ['-o', "#{k}=#{v}"] unless k == IDENTITITY_FILE_OPTION
|
66
|
+
end
|
62
67
|
r
|
63
68
|
end
|
64
69
|
|
@@ -67,6 +72,12 @@ module EacRubyUtils
|
|
67
72
|
r = "#{uri.user}@#{r}" if uri.user.present?
|
68
73
|
r
|
69
74
|
end
|
75
|
+
|
76
|
+
def ssh_identity_file
|
77
|
+
uri.query_values.if_present do |v|
|
78
|
+
v[IDENTITITY_FILE_OPTION]
|
79
|
+
end
|
80
|
+
end
|
70
81
|
end
|
71
82
|
end
|
72
83
|
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,32 @@
|
|
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_get(object)
|
22
|
+
super || []
|
23
|
+
end
|
24
|
+
|
25
|
+
def immutable_value_set(object, value)
|
26
|
+
duplicate_object(object) do |old_value|
|
27
|
+
(old_value || []) + [value]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
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,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
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'active_support/inflector'
|
4
|
+
|
3
5
|
module EacRubyUtils
|
4
6
|
class << self
|
5
7
|
def require_sub(file, options = {})
|
@@ -26,6 +28,23 @@ module EacRubyUtils
|
|
26
28
|
|
27
29
|
private
|
28
30
|
|
31
|
+
def active_support_require(path)
|
32
|
+
return false unless options[REQUIRE_DEPENDENCY_OPTION_KEY]
|
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
|
+
|
29
48
|
def include_modules
|
30
49
|
return unless options[INCLUDE_MODULES_OPTION_KEY]
|
31
50
|
|
@@ -41,14 +60,22 @@ module EacRubyUtils
|
|
41
60
|
options[BASE_OPTION_KEY] || raise('Option :base not setted')
|
42
61
|
end
|
43
62
|
|
63
|
+
def base?
|
64
|
+
options[BASE_OPTION_KEY] ? true : false
|
65
|
+
end
|
66
|
+
|
67
|
+
def kernel_require(path)
|
68
|
+
::Kernel.require(path)
|
69
|
+
end
|
70
|
+
|
44
71
|
def require_sub_files
|
45
72
|
Dir["#{File.dirname(file)}/#{::File.basename(file, '.*')}/*.rb"].sort.each do |path|
|
46
|
-
|
47
|
-
require_dependency path
|
48
|
-
else
|
49
|
-
require path
|
50
|
-
end
|
73
|
+
require_sub_file(path)
|
51
74
|
end
|
52
75
|
end
|
76
|
+
|
77
|
+
def require_sub_file(path)
|
78
|
+
active_support_require(path) || autoload_require(path) || kernel_require(path)
|
79
|
+
end
|
53
80
|
end
|
54
81
|
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
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
5
|
+
module EacRubyUtils
|
6
|
+
module Templates
|
7
|
+
module VariableProviders
|
8
|
+
require_sub __FILE__
|
9
|
+
|
10
|
+
PROVIDERS = %w[entries_reader hash generic].map do |name|
|
11
|
+
"eac_ruby_utils/templates/variable_providers/#{name}".camelize.constantize
|
12
|
+
end
|
13
|
+
|
14
|
+
class << self
|
15
|
+
def build(variables_source)
|
16
|
+
PROVIDERS.each do |provider|
|
17
|
+
return provider.new(variables_source) if provider.accept?(variables_source)
|
18
|
+
end
|
19
|
+
|
20
|
+
raise "Variables provider not found for #{variables_source}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/templates/variable_not_found_error'
|
4
|
+
|
5
|
+
module EacRubyUtils
|
6
|
+
module Templates
|
7
|
+
module VariableProviders
|
8
|
+
class Base
|
9
|
+
attr_reader :source
|
10
|
+
|
11
|
+
def initialize(source)
|
12
|
+
@source = source
|
13
|
+
end
|
14
|
+
|
15
|
+
def variable_value(name)
|
16
|
+
return variable_fetch(name) if variable_exist?(name)
|
17
|
+
|
18
|
+
raise VariableNotFoundError, "Variable \"#{name}\" not found in #{source}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/templates/variable_providers/base'
|
4
|
+
|
5
|
+
module EacRubyUtils
|
6
|
+
module Templates
|
7
|
+
module VariableProviders
|
8
|
+
class EntriesReader < ::EacRubyUtils::Templates::VariableProviders::Base
|
9
|
+
class << self
|
10
|
+
def accept?(variables_source)
|
11
|
+
variables_source.respond_to?(:read_entry)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def variable_exist?(_name)
|
16
|
+
true
|
17
|
+
end
|
18
|
+
|
19
|
+
def variable_fetch(name)
|
20
|
+
source.read_entry(name)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/templates/variable_providers/base'
|
4
|
+
|
5
|
+
module EacRubyUtils
|
6
|
+
module Templates
|
7
|
+
module VariableProviders
|
8
|
+
class Generic < ::EacRubyUtils::Templates::VariableProviders::Base
|
9
|
+
class << self
|
10
|
+
def accept?(variables_source)
|
11
|
+
variables_source.is_a?(::Object)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def variable_exist?(name)
|
16
|
+
source.respond_to?(name)
|
17
|
+
end
|
18
|
+
|
19
|
+
def variable_fetch(name)
|
20
|
+
source.send(name)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/templates/variable_providers/base'
|
4
|
+
|
5
|
+
module EacRubyUtils
|
6
|
+
module Templates
|
7
|
+
module VariableProviders
|
8
|
+
class Hash < ::EacRubyUtils::Templates::VariableProviders::Base
|
9
|
+
class << self
|
10
|
+
def accept?(variables_source)
|
11
|
+
variables_source.is_a?(::Hash)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(source)
|
16
|
+
super(source.with_indifferent_access)
|
17
|
+
end
|
18
|
+
|
19
|
+
def variable_exist?(name)
|
20
|
+
source.key?(name)
|
21
|
+
end
|
22
|
+
|
23
|
+
def variable_fetch(name)
|
24
|
+
source.fetch(name)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
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.41.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: 2020-
|
11
|
+
date: 2020-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -148,6 +148,14 @@ files:
|
|
148
148
|
- lib/eac_ruby_utils/fs/traversable.rb
|
149
149
|
- lib/eac_ruby_utils/fs/traverser.rb
|
150
150
|
- lib/eac_ruby_utils/fs_cache.rb
|
151
|
+
- lib/eac_ruby_utils/immutable.rb
|
152
|
+
- lib/eac_ruby_utils/immutable/array_accessor.rb
|
153
|
+
- lib/eac_ruby_utils/immutable/base_accessor.rb
|
154
|
+
- lib/eac_ruby_utils/immutable/boolean_accessor.rb
|
155
|
+
- lib/eac_ruby_utils/immutable/class_methods.rb
|
156
|
+
- lib/eac_ruby_utils/immutable/common_accessor.rb
|
157
|
+
- lib/eac_ruby_utils/immutable/hash_accessor.rb
|
158
|
+
- lib/eac_ruby_utils/immutable/instance_methods.rb
|
151
159
|
- lib/eac_ruby_utils/listable.rb
|
152
160
|
- lib/eac_ruby_utils/listable/class_methods.rb
|
153
161
|
- lib/eac_ruby_utils/listable/instance_methods.rb
|
@@ -171,6 +179,7 @@ files:
|
|
171
179
|
- lib/eac_ruby_utils/patches/module.rb
|
172
180
|
- lib/eac_ruby_utils/patches/module/common_concern.rb
|
173
181
|
- lib/eac_ruby_utils/patches/module/console_speaker.rb
|
182
|
+
- lib/eac_ruby_utils/patches/module/immutable.rb
|
174
183
|
- lib/eac_ruby_utils/patches/module/listable.rb
|
175
184
|
- lib/eac_ruby_utils/patches/module/patch.rb
|
176
185
|
- lib/eac_ruby_utils/patches/module/require_sub.rb
|
@@ -201,6 +210,12 @@ files:
|
|
201
210
|
- lib/eac_ruby_utils/templates/directory.rb
|
202
211
|
- lib/eac_ruby_utils/templates/file.rb
|
203
212
|
- lib/eac_ruby_utils/templates/searcher.rb
|
213
|
+
- lib/eac_ruby_utils/templates/variable_not_found_error.rb
|
214
|
+
- lib/eac_ruby_utils/templates/variable_providers.rb
|
215
|
+
- lib/eac_ruby_utils/templates/variable_providers/base.rb
|
216
|
+
- lib/eac_ruby_utils/templates/variable_providers/entries_reader.rb
|
217
|
+
- lib/eac_ruby_utils/templates/variable_providers/generic.rb
|
218
|
+
- lib/eac_ruby_utils/templates/variable_providers/hash.rb
|
204
219
|
- lib/eac_ruby_utils/version.rb
|
205
220
|
- lib/eac_ruby_utils/yaml.rb
|
206
221
|
homepage:
|