eac_tools 0.70.0 → 0.72.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +39 -38
  3. data/lib/eac_tools/version.rb +1 -1
  4. data/sub/avm/avm.gemspec +1 -1
  5. data/sub/avm/lib/avm/applications/base.rb +1 -0
  6. data/sub/avm/lib/avm/instances/base/processes.rb +3 -3
  7. data/sub/avm/lib/avm/instances/process.rb +11 -1
  8. data/sub/avm/lib/avm/registry/applications.rb +7 -0
  9. data/sub/avm/lib/avm/registry/config_objects.rb +18 -0
  10. data/sub/avm/lib/avm/registry.rb +3 -2
  11. data/sub/avm/lib/avm/version.rb +1 -1
  12. data/sub/avm-eac_rails_base1/avm-eac_rails_base1.gemspec +2 -2
  13. data/sub/avm-eac_rails_base1/lib/avm/eac_rails_base1/instances/processes/daemon.rb +4 -0
  14. data/sub/avm-eac_rails_base1/lib/avm/eac_rails_base1/version.rb +1 -1
  15. data/sub/avm-eac_webapp_base0/avm-eac_webapp_base0.gemspec +1 -1
  16. data/sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/instances/processes/web_server.rb +4 -0
  17. data/sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/version.rb +1 -1
  18. data/sub/avm-tools/avm-tools.gemspec +3 -3
  19. data/sub/avm-tools/lib/avm/tools/runner/applications/list.rb +31 -0
  20. data/sub/avm-tools/lib/avm/tools/runner/applications.rb +16 -0
  21. data/sub/avm-tools/lib/avm/tools/version.rb +1 -1
  22. data/sub/eac_config/eac_config.gemspec +2 -2
  23. data/sub/eac_config/lib/eac_config/entries.rb +35 -0
  24. data/sub/eac_config/lib/eac_config/entry_path.rb +27 -0
  25. data/sub/eac_config/lib/eac_config/envvars_node.rb +6 -0
  26. data/sub/eac_config/lib/eac_config/node.rb +7 -1
  27. data/sub/eac_config/lib/eac_config/node_entry.rb +1 -0
  28. data/sub/eac_config/lib/eac_config/version.rb +1 -1
  29. data/sub/eac_config/lib/eac_config/yaml_file_node/self_entries.rb +72 -0
  30. data/sub/eac_config/lib/eac_config/yaml_file_node.rb +3 -0
  31. data/sub/eac_config/spec/lib/eac_config/yaml_file_node_spec.rb +62 -26
  32. data/sub/eac_config/spec/lib/eac_config/yaml_file_node_spec_files/storage1.yaml +5 -1
  33. data/sub/eac_config/spec/lib/eac_config/yaml_file_node_spec_files/storage1_1.yaml +2 -0
  34. data/sub/eac_config/spec/lib/eac_config/yaml_file_node_spec_files/storage1_2/storage1_2_1.yaml +2 -0
  35. data/sub/eac_config/spec/lib/eac_config/yaml_file_node_spec_files/storage1_2.yaml +6 -0
  36. data/sub/eac_envs-http/eac_envs-http.gemspec +3 -3
  37. data/sub/eac_envs-http/lib/eac_envs/http/response/body.rb +5 -0
  38. data/sub/eac_envs-http/lib/eac_envs/http/version.rb +1 -1
  39. data/sub/eac_envs-http/spec/lib/eac_envs/http/request_spec_files/get.target.yaml +1 -1
  40. data/sub/eac_envs-http/spec/lib/eac_envs/http/request_spec_files/get_with_auth.target.yaml +1 -1
  41. data/sub/eac_envs-http/spec/lib/eac_envs/http/request_spec_files/post_array_body.target.yaml +1 -1
  42. data/sub/eac_envs-http/spec/lib/eac_envs/http/request_spec_files/post_string_body.target.yaml +1 -1
  43. data/sub/eac_envs-http/spec/lib/eac_envs/http/request_spec_files/put_hash_body.target.yaml +1 -1
  44. data/sub/eac_envs-http/spec/lib/eac_envs/http/request_spec_files/put_with_file.target.yaml +1 -1
  45. data/sub/eac_envs-http/spec/lib/eac_envs/http/request_spec_files/root.target.yaml +1 -1
  46. data/sub/eac_envs-http/spec/spec_helper/request_builder.rb +1 -0
  47. data/sub/eac_rest/eac_rest.gemspec +2 -2
  48. data/sub/eac_rest/lib/eac_rest/api.rb +1 -1
  49. data/sub/eac_rest/lib/eac_rest/version.rb +1 -1
  50. data/sub/eac_rest/spec/lib/eac_rest/api_spec_files/get.target.yaml +1 -1
  51. data/sub/eac_rest/spec/lib/eac_rest/api_spec_files/get_with_auth.target.yaml +1 -1
  52. data/sub/eac_rest/spec/lib/eac_rest/api_spec_files/post_array_body.target.yaml +1 -1
  53. data/sub/eac_rest/spec/lib/eac_rest/api_spec_files/post_string_body.target.yaml +1 -1
  54. data/sub/eac_rest/spec/lib/eac_rest/api_spec_files/put_hash_body.target.yaml +1 -1
  55. data/sub/eac_rest/spec/lib/eac_rest/api_spec_files/put_with_file.target.yaml +1 -1
  56. data/sub/eac_rest/spec/lib/eac_rest/api_spec_files/root.target.yaml +1 -1
  57. data/sub/eac_rest/spec/spec_helper/request_builder.rb +2 -1
  58. data/sub/eac_ruby_utils/lib/eac_ruby_utils/acts_as_instance_method.rb +34 -0
  59. data/sub/eac_ruby_utils/lib/eac_ruby_utils/gems_registry.rb +0 -1
  60. data/sub/eac_ruby_utils/lib/eac_ruby_utils/method_class.rb +7 -15
  61. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/module/acts_as_instance_method.rb +10 -0
  62. data/sub/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
  63. data/sub/eac_ruby_utils/lib/eac_ruby_utils/wildcards.rb +26 -0
  64. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/wildcards_spec.rb +27 -0
  65. metadata +29 -20
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_config/entry_path'
4
+ require 'eac_config/yaml_file_node/entry'
5
+ require 'eac_ruby_utils/core_ext'
6
+ require 'eac_ruby_utils/wildcards'
7
+
8
+ module EacConfig
9
+ class YamlFileNode
10
+ class SelfEntries
11
+ acts_as_instance_method
12
+ common_constructor :node, :path do
13
+ self.path = ::EacConfig::EntryPath.assert(path)
14
+ end
15
+
16
+ # @return [Array<EacConfig::YamlFileNode>]
17
+ def result
18
+ head_node.result.map { |found_path| ::EacConfig::YamlFileNode::Entry.new(node, found_path) }
19
+ end
20
+
21
+ private
22
+
23
+ # @return [DataNode]
24
+ def head_node
25
+ DataNode.new(node.data, ::EacConfig::EntryPath.new, path)
26
+ end
27
+
28
+ class DataNode
29
+ common_constructor :data_node, :path_from, :path_to do
30
+ self.data_node = data_node.stringify_keys if data_node.is_a?(::Hash)
31
+ end
32
+
33
+ # @return [DataNode]
34
+ def child(child_key)
35
+ self.class.new(data_node.fetch(child_key), path_from.with_last(child_key),
36
+ path_to.without_first)
37
+ end
38
+
39
+ def children
40
+ return [] unless data_node.is_a?(::Hash)
41
+
42
+ data_node.keys.select { |k| key_matcher.match?(k) }.map { |k| child(k) }
43
+ end
44
+
45
+ # @return [Symbol]
46
+ def key
47
+ path_to.first
48
+ end
49
+
50
+ # @return [EacRubyUtils::Wildcards]
51
+ def key_matcher
52
+ @key_matcher ||= ::EacRubyUtils::Wildcards.new(key)
53
+ end
54
+
55
+ # @return [Array<EacConfig::EntryPath>]
56
+ def result
57
+ (path_to.empty? ? result_from_self : result_from_children)
58
+ end
59
+
60
+ # @return [Array<EacConfig::EntryPath>]
61
+ def result_from_self
62
+ [path_from]
63
+ end
64
+
65
+ # @return [Array<EacConfig::EntryPath>]
66
+ def result_from_children
67
+ children.flat_map(&:result)
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -20,6 +20,7 @@ module EacConfig
20
20
  common_constructor :path do
21
21
  self.path = path.to_pathname
22
22
  end
23
+ compare_by :path
23
24
 
24
25
  def persist_data(new_data)
25
26
  path.parent.mkpath
@@ -47,5 +48,7 @@ module EacConfig
47
48
 
48
49
  r.is_a?(::Hash) ? r : {}
49
50
  end
51
+
52
+ require_sub __FILE__, require_mode: :kernel
50
53
  end
51
54
  end
@@ -12,41 +12,77 @@ RSpec.describe ::EacConfig::YamlFileNode do
12
12
  end
13
13
 
14
14
  let(:fixtures_dir) { ::Pathname.new(__dir__).join('yaml_file_node_spec_files') }
15
- let(:target_dir) { temp_copy(fixtures_dir) }
16
- let(:yaml_file_path) do
17
- r = target_dir.join('storage1.yaml')
18
- r.write(r.read.gsub('%%STORAGE1_2_ABSOLUTE_PATH%%',
19
- target_dir.join('storage1_2.yaml').expand_path.to_path))
20
- r
15
+ let(:instance) { storage1 }
16
+
17
+ storages.each do |storage|
18
+ let(storage.key) { described_class.new(fixtures_dir.join(storage.subpath)) }
21
19
  end
22
- let(:instance) { described_class.new(yaml_file_path) }
23
20
 
24
- context 'with common entry' do
25
- let(:entry) { instance.entry('common') }
21
+ describe '#entry' do
22
+ context 'with common entry' do
23
+ let(:entry) { instance.entry('common') }
26
24
 
27
- it { expect(entry.value).to eq('AAA') }
28
- it { expect(entry.found_node).to eq(instance) }
29
- it { expect(entry).to be_found }
30
- end
25
+ it { expect(entry.value).to eq('AAA') }
26
+ it { expect(entry.found_node).to eq(instance) }
27
+ it { expect(entry).to be_found }
28
+ end
31
29
 
32
- storages.each do |storage|
33
- context "with entry in loaded path \"#{storage.subpath}\"" do
34
- let(:entry) { instance.entry(storage.key) }
35
- let(:storage_node) { described_class.new(target_dir.join(storage.subpath)) }
30
+ storages.each do |storage|
31
+ context "with entry in loaded path \"#{storage.subpath}\"" do
32
+ let(:entry) { instance.entry(storage.key) }
33
+ let(:storage_node) { send(storage.key) }
34
+
35
+ it { expect(entry).to be_a(::EacConfig::Entry) }
36
+ it { expect(entry).to be_found }
37
+ it { expect(entry.value).to eq(storage.key) }
38
+ it { expect(entry.found_node.url).to eq(storage_node.url) }
39
+ end
40
+ end
41
+
42
+ context 'with not existing entry' do
43
+ let(:entry) { instance.entry('no_exist') }
36
44
 
37
45
  it { expect(entry).to be_a(::EacConfig::Entry) }
38
- it { expect(entry).to be_found }
39
- it { expect(entry.value).to eq(storage.key) }
40
- it { expect(entry.found_node.url).to eq(storage_node.url) }
46
+ it { expect(entry.value).to eq(nil) }
47
+ it { expect(entry.found_node).to eq(nil) }
48
+ it { expect(entry).not_to be_found }
41
49
  end
42
50
  end
43
51
 
44
- context 'with not existing entry' do
45
- let(:entry) { instance.entry('no_exist') }
52
+ describe '#entries' do
53
+ context 'when search path is "common"' do
54
+ let(:path) { 'common' }
55
+ let(:actual) { instance.entries(path).node_entries }
56
+ let(:expected) { [::EacConfig::YamlFileNode::Entry.new(storage1, path)] }
57
+
58
+ it { expect(actual).to eq(expected) }
59
+ end
60
+
61
+ context 'when search path is "same.path"' do
62
+ let(:path) { 'same.path' }
63
+ let(:actual) { instance.entries(path).node_entries }
64
+ let(:expected) do
65
+ [storage1_1, storage1_2_1].map do |n|
66
+ ::EacConfig::YamlFileNode::Entry.new(n, 'same.path')
67
+ end
68
+ end
46
69
 
47
- it { expect(entry).to be_a(::EacConfig::Entry) }
48
- it { expect(entry.value).to eq(nil) }
49
- it { expect(entry.found_node).to eq(nil) }
50
- it { expect(entry).not_to be_found }
70
+ it { expect(actual).to eq(expected) }
71
+ end
72
+
73
+ context 'when search path is "*.search_me"' do
74
+ let(:path) { '*.search_me' }
75
+ let(:actual) { instance.entries(path).node_entries }
76
+ let(:expected) do
77
+ [
78
+ [storage1, 'storage1_a'], [storage1, 'storage1_b'],
79
+ [storage1_2, 'storage1_2_a'], [storage1_2, 'storage1_2_b'], [storage1_2, 'storage1_2_c']
80
+ ].map do |args|
81
+ ::EacConfig::YamlFileNode::Entry.new(args[0], args[1] + '.search_me')
82
+ end
83
+ end
84
+
85
+ it { expect(actual).to eq(expected) }
86
+ end
51
87
  end
52
88
  end
@@ -2,5 +2,9 @@
2
2
  common: AAA
3
3
  load_path:
4
4
  - storage1_1.yaml
5
- - %%STORAGE1_2_ABSOLUTE_PATH%%
5
+ - storage1_2.yaml
6
6
  storage1: storage1
7
+ storage1_a:
8
+ search_me: 1_a
9
+ storage1_b:
10
+ search_me: 1_b
@@ -1,2 +1,4 @@
1
1
  ---
2
2
  storage1_1: storage1_1
3
+ same:
4
+ path: SAME_PATH_1_1
@@ -1,2 +1,4 @@
1
1
  ---
2
2
  storage1_2_1: storage1_2_1
3
+ same:
4
+ path: SAME_PATH_1_2_1
@@ -2,3 +2,9 @@
2
2
  load_path:
3
3
  - ./storage1_2/storage1_2_1.yaml
4
4
  storage1_2: storage1_2
5
+ storage1_2_a:
6
+ search_me: 1_2_a
7
+ storage1_2_b:
8
+ search_me: 1_2_a
9
+ storage1_2_c:
10
+ search_me: 1_2_a
@@ -13,12 +13,12 @@ Gem::Specification.new do |s|
13
13
  s.files = Dir['{lib}/**/*']
14
14
 
15
15
  s.add_dependency 'eac_fs', '~> 0.16'
16
- s.add_dependency 'eac_ruby_utils', '~> 0.116'
17
- s.add_dependency 'faraday', '~> 2.7', '>= 2.7.4'
16
+ s.add_dependency 'eac_ruby_utils', '~> 0.117', '>= 0.117.1'
17
+ s.add_dependency 'faraday', '~> 2.7', '>= 2.7.6'
18
18
  s.add_dependency 'faraday-follow_redirects', '~> 0.3'
19
19
  s.add_dependency 'faraday-gzip', '~> 0.1'
20
20
  s.add_dependency 'faraday-multipart', '~> 1.0', '>= 1.0.4'
21
- s.add_dependency 'faraday-retry', '~> 2.1'
21
+ s.add_dependency 'faraday-retry', '~> 2.2'
22
22
 
23
23
  s.add_development_dependency 'aranha-parsers', '~> 0.17'
24
24
  s.add_development_dependency 'eac_ruby_gem_support', '~> 0.5', '>= 0.5.1'
@@ -34,6 +34,11 @@ module EacEnvs
34
34
  body_str
35
35
  end
36
36
 
37
+ # @param path [Pathname]
38
+ def write_body(path)
39
+ ::File.open(path, 'wb') { |fp| fp.write(performed.body) }
40
+ end
41
+
37
42
  private
38
43
 
39
44
  def body_data_from_application_json
@@ -2,6 +2,6 @@
2
2
 
3
3
  module EacEnvs
4
4
  module Http
5
- VERSION = '0.3.2'
5
+ VERSION = '0.4.0'
6
6
  end
7
7
  end
@@ -4,6 +4,6 @@ method: GET
4
4
  uri: "/path/to/service?field1=value1&field2=value2"
5
5
  body:
6
6
  headers:
7
- user-agent: Faraday v2.7.4
7
+ user-agent: EacEnvs::Http
8
8
  accept: application/json
9
9
  accept-encoding: gzip,deflate
@@ -4,7 +4,7 @@ method: GET
4
4
  uri: "/path/to/service?field1=value1&field2=value2"
5
5
  body:
6
6
  headers:
7
- user-agent: Faraday v2.7.4
7
+ user-agent: EacEnvs::Http
8
8
  accept: application/json
9
9
  authorization: Basic dGhlX3VzZXI6dGhlX3NlY3JldA==
10
10
  accept-encoding: gzip,deflate
@@ -4,7 +4,7 @@ method: POST
4
4
  uri: "/path/to/service"
5
5
  body: field1=value1&field1=value3&field2=value2
6
6
  headers:
7
- user-agent: Faraday v2.7.4
7
+ user-agent: EacEnvs::Http
8
8
  content-type: application/x-www-form-urlencoded
9
9
  accept-encoding: gzip,deflate
10
10
  accept: "*/*"
@@ -4,7 +4,7 @@ method: POST
4
4
  uri: "/path/to/service"
5
5
  body: field1=value1&field2=value2
6
6
  headers:
7
- user-agent: Faraday v2.7.4
7
+ user-agent: EacEnvs::Http
8
8
  content-type: application/x-www-form-urlencoded
9
9
  accept-encoding: gzip,deflate
10
10
  accept: "*/*"
@@ -4,7 +4,7 @@ method: PUT
4
4
  uri: "/path/to/service"
5
5
  body: field1=value1&field2=value2
6
6
  headers:
7
- user-agent: Faraday v2.7.4
7
+ user-agent: EacEnvs::Http
8
8
  content-type: application/x-www-form-urlencoded
9
9
  accept-encoding: gzip,deflate
10
10
  accept: "*/*"
@@ -6,7 +6,7 @@ body: "-------------RubyMultipartPost-0123456789abcdef0123456789abcdef\r\nConten
6
6
  form-data; name=\"field1\"; filename=\"basename\"\r\nContent-Length: 6\r\nContent-Type:
7
7
  text/plain\r\nContent-Transfer-Encoding: binary\r\n\r\nvalue1\r\n-------------RubyMultipartPost-0123456789abcdef0123456789abcdef--\r\n"
8
8
  headers:
9
- user-agent: Faraday v2.7.4
9
+ user-agent: EacEnvs::Http
10
10
  content-type: multipart/form-data; boundary=-----------RubyMultipartPost-0123456789abcdef0123456789abcdef
11
11
  content-length: '290'
12
12
  accept-encoding: gzip,deflate
@@ -4,6 +4,6 @@ method: GET
4
4
  uri: "/"
5
5
  body:
6
6
  headers:
7
- user-agent: Faraday v2.7.4
7
+ user-agent: EacEnvs::Http
8
8
  accept-encoding: gzip,deflate
9
9
  accept: "*/*"
@@ -26,6 +26,7 @@ class RequestBuilder
26
26
  r = %i[verb headers].inject(new_request) do |a, e|
27
27
  data[e].if_present(a) { |v| a.send(e, v) }
28
28
  end
29
+ r = r.header('user-agent', 'EacEnvs::Http')
29
30
  result_body_data(result_auth(r))
30
31
  end
31
32
 
@@ -12,9 +12,9 @@ Gem::Specification.new do |s|
12
12
 
13
13
  s.files = Dir['{lib}/**/*']
14
14
 
15
- s.add_dependency 'eac_envs-http', '~> 0.3', '>= 0.3.1'
15
+ s.add_dependency 'eac_envs-http', '~> 0.4'
16
16
  s.add_dependency 'eac_fs', '~> 0.16'
17
- s.add_dependency 'eac_ruby_utils', '~> 0.112'
17
+ s.add_dependency 'eac_ruby_utils', '~> 0.117', '>= 0.117.1'
18
18
 
19
19
  s.add_development_dependency 'aranha-parsers', '~> 0.15'
20
20
  s.add_development_dependency 'eac_ruby_gem_support', '~> 0.5.1'
@@ -32,7 +32,7 @@ module EacRest
32
32
 
33
33
  def request_json(service_url_suffix, headers = {}, &body_data_proc)
34
34
  request(service_url_suffix, headers.merge('Accept' => 'application/json')) do |body_data|
35
- r = ::JSON.parse(body_data)
35
+ r = body_data.is_a?(::Enumerable) ? body_data : ::JSON.parse(body_data)
36
36
  r = body_data_proc.call(r) if body_data_proc
37
37
  r
38
38
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRest
4
- VERSION = '0.9.0'
4
+ VERSION = '0.9.1'
5
5
  end
@@ -4,6 +4,6 @@ method: GET
4
4
  uri: "/path/to/service?field1=value1&field2=value2"
5
5
  body:
6
6
  headers:
7
- user-agent: Faraday v2.7.4
7
+ user-agent: EacRest
8
8
  accept: application/json
9
9
  accept-encoding: gzip,deflate
@@ -4,7 +4,7 @@ method: GET
4
4
  uri: "/path/to/service?field1=value1&field2=value2"
5
5
  body:
6
6
  headers:
7
- user-agent: Faraday v2.7.4
7
+ user-agent: EacRest
8
8
  accept: application/json
9
9
  authorization: Basic dGhlX3VzZXI6dGhlX3NlY3JldA==
10
10
  accept-encoding: gzip,deflate
@@ -4,7 +4,7 @@ method: POST
4
4
  uri: "/path/to/service"
5
5
  body: field1=value1&field1=value3&field2=value2
6
6
  headers:
7
- user-agent: Faraday v2.7.4
7
+ user-agent: EacRest
8
8
  content-type: application/x-www-form-urlencoded
9
9
  accept-encoding: gzip,deflate
10
10
  accept: "*/*"
@@ -4,7 +4,7 @@ method: POST
4
4
  uri: "/path/to/service"
5
5
  body: field1=value1&field2=value2
6
6
  headers:
7
- user-agent: Faraday v2.7.4
7
+ user-agent: EacRest
8
8
  content-type: application/x-www-form-urlencoded
9
9
  accept-encoding: gzip,deflate
10
10
  accept: "*/*"
@@ -4,7 +4,7 @@ method: PUT
4
4
  uri: "/path/to/service"
5
5
  body: field1=value1&field2=value2
6
6
  headers:
7
- user-agent: Faraday v2.7.4
7
+ user-agent: EacRest
8
8
  content-type: application/x-www-form-urlencoded
9
9
  accept-encoding: gzip,deflate
10
10
  accept: "*/*"
@@ -6,7 +6,7 @@ body: "-------------RubyMultipartPost-0123456789abcdef0123456789abcdef\r\nConten
6
6
  form-data; name=\"field1\"; filename=\"basename\"\r\nContent-Length: 6\r\nContent-Type:
7
7
  text/plain\r\nContent-Transfer-Encoding: binary\r\n\r\nvalue1\r\n-------------RubyMultipartPost-0123456789abcdef0123456789abcdef--\r\n"
8
8
  headers:
9
- user-agent: Faraday v2.7.4
9
+ user-agent: EacRest
10
10
  content-type: multipart/form-data; boundary=-----------RubyMultipartPost-0123456789abcdef0123456789abcdef
11
11
  content-length: '290'
12
12
  accept-encoding: gzip,deflate
@@ -4,6 +4,6 @@ method: GET
4
4
  uri: "/"
5
5
  body:
6
6
  headers:
7
- user-agent: Faraday v2.7.4
7
+ user-agent: EacRest
8
8
  accept-encoding: gzip,deflate
9
9
  accept: "*/*"
@@ -17,10 +17,11 @@ class RequestBuilder
17
17
  self.data = data.with_indifferent_access
18
18
  end
19
19
 
20
- def result
20
+ def result # rubocop:disable Metrics/AbcSize
21
21
  r = %i[verb headers].inject(selected_api.request(data.fetch(:url_suffix))) do |a, e|
22
22
  data[e].if_present(a) { |v| a.send(e, v) }
23
23
  end
24
+ r = r.header('user-agent', 'EacRest')
24
25
  data[:body_data].if_present(r) { |v| r.body_data(build_body_data(v)) }
25
26
  end
26
27
 
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/core_ext/module/introspection'
4
+ require 'eac_ruby_utils/patches/class/common_constructor'
5
+ require 'eac_ruby_utils/patches/module/module_parent'
6
+ require 'eac_ruby_utils/patches/string/inflector'
7
+
8
+ module EacRubyUtils
9
+ class ActsAsInstanceMethod
10
+ common_constructor :method_class
11
+
12
+ # @param sender_module [Module, nil]
13
+ # @return [self]
14
+ def setup(sender_module = nil)
15
+ sender_module ||= default_sender_module
16
+ the_setup = self
17
+ sender_module.define_method(method_name) do |*args, &block|
18
+ the_setup.method_class.new(self, *args, &block).result
19
+ end
20
+
21
+ self
22
+ end
23
+
24
+ # @return [String]
25
+ def method_name
26
+ method_class.name.demodulize.underscore.variableize
27
+ end
28
+
29
+ # @return [Module]
30
+ def default_sender_module
31
+ method_class.module_parent
32
+ end
33
+ end
34
+ end
@@ -29,7 +29,6 @@ module EacRubyUtils
29
29
  # @return [Array<EacRubyUtils::GemsRegistry::Gem>]
30
30
  def all_gems
31
31
  ::Gem::Specification.map { |gemspec| ::EacRubyUtils::GemsRegistry::Gem.new(self, gemspec) }
32
- .sort
33
32
  end
34
33
  end
35
34
  end
@@ -1,10 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'active_support/core_ext/module/introspection'
3
+ require 'eac_ruby_utils/acts_as_instance_method'
4
4
  require 'eac_ruby_utils/patches/class/common_constructor'
5
5
  require 'eac_ruby_utils/patches/module/common_concern'
6
- require 'eac_ruby_utils/patches/module/module_parent'
7
- require 'eac_ruby_utils/patches/string/inflector'
8
6
 
9
7
  module EacRubyUtils
10
8
  module MethodClass
@@ -12,24 +10,18 @@ module EacRubyUtils
12
10
  ::EacRubyUtils::MethodClass::Setup.new(self)
13
11
  end
14
12
 
15
- class Setup
16
- common_constructor :method_class, :static_method, default: [false] do
13
+ class Setup < ::EacRubyUtils::ActsAsInstanceMethod
14
+ common_constructor :method_class, :static_method, default: [false],
15
+ super_args: -> { [method_class] } do
17
16
  perform
18
17
  end
19
18
 
20
19
  def perform
21
- the_setup = self
22
- sender_module.define_method(method_name) do |*args, &block|
23
- the_setup.method_class.new(self, *args, &block).result
24
- end
20
+ setup
25
21
  end
26
22
 
27
- def method_name
28
- method_class.name.demodulize.underscore.variableize
29
- end
30
-
31
- def sender_module
32
- r = method_class.module_parent
23
+ def default_sender_module
24
+ r = super
33
25
  r = r.singleton_class if static_method
34
26
  r
35
27
  end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/acts_as_instance_method'
4
+
5
+ class Module
6
+ # @return [EacRubyUtils::ActsAsInstanceMethod]
7
+ def acts_as_instance_method
8
+ ::EacRubyUtils::ActsAsInstanceMethod.new(self).setup
9
+ end
10
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyUtils
4
- VERSION = '0.117.1'
4
+ VERSION = '0.119.0'
5
5
  end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacRubyUtils
4
+ # The `Wildcards` class provides pattern matching with wildcards using regular expressions.
5
+ class Wildcards
6
+ # Initializes a new instance of the `Wildcards` class with the specified pattern.
7
+ #
8
+ # @param pattern [String] The pattern to match against.
9
+ def initialize(pattern)
10
+ @pattern = pattern
11
+ end
12
+
13
+ # Matches the given string against the pattern.
14
+ #
15
+ # @param string [String] The string to match.
16
+ # @return [Boolean] Returns `true` if the string matches the pattern, otherwise `false`.
17
+ delegate :match?, to: :regex
18
+
19
+ private
20
+
21
+ # @return [Regexp]
22
+ def regex
23
+ ::Regexp.new("^#{::Regexp.escape(@pattern).gsub('\*', '.*').gsub('\?', '.?')}$")
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/wildcards'
4
+
5
+ ::RSpec.describe ::EacRubyUtils::Wildcards do
6
+ describe '#match' do
7
+ {
8
+ 'h*llo' => { 'hello' => true, 'hallo' => true, 'hxllo' => true, 'hillo' => true },
9
+ 'w?rld' => { 'world' => true, 'warld' => true, 'wzzrld' => false },
10
+ 'h*l?o' => { 'hello' => true, 'hallo' => true, 'hxxllo' => true, 'hilbbo' => false },
11
+ '' => { '' => true, 'hello' => false },
12
+ 'hello' => { '' => false, 'hello' => true }
13
+ }.each do |pattern, examples|
14
+ context "when pattern is '#{pattern}'" do
15
+ let(:instance) { described_class.new(pattern) }
16
+
17
+ examples.each do |string, expected_result|
18
+ context "when string is \"#{string}\"" do # rubocop:disable RSpec/NestedGroups
19
+ it do
20
+ expect(instance.match?(string)).to eq(expected_result)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end