eac_tools 0.61.0 → 0.62.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +30 -25
  3. data/lib/eac_tools/version.rb +1 -1
  4. data/sub/avm/avm.gemspec +2 -2
  5. data/sub/avm/lib/avm/version.rb +1 -1
  6. data/sub/avm-eac_redmine_base0/avm-eac_redmine_base0.gemspec +3 -3
  7. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/base.rb +1 -1
  8. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/rest_api/entity_base.rb +35 -0
  9. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/rest_api/project.rb +26 -0
  10. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/rest_api/root.rb +21 -0
  11. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/rest_api/wiki_page.rb +54 -0
  12. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/rest_api.rb +1 -0
  13. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/runners/project/wiki_page/read.rb +27 -0
  14. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/runners/project/wiki_page/write.rb +70 -0
  15. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/runners/project/wiki_page.rb +30 -0
  16. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/runners/project.rb +26 -0
  17. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/version.rb +1 -1
  18. data/sub/avm-files/avm-files.gemspec +1 -1
  19. data/sub/avm-files/lib/avm/files/version.rb +1 -1
  20. data/sub/avm-git/avm-git.gemspec +2 -2
  21. data/sub/avm-git/lib/avm/git/version.rb +1 -1
  22. data/sub/{eac_ruby_base0/lib/eac_ruby_base0 → eac_cli/lib/eac_cli}/runner_with/confirmation.rb +3 -1
  23. data/sub/{eac_ruby_base0/lib/eac_ruby_base0 → eac_cli/lib/eac_cli}/runner_with/input.rb +1 -1
  24. data/sub/{eac_ruby_base0/lib/eac_ruby_base0 → eac_cli/lib/eac_cli}/runner_with/output.rb +1 -1
  25. data/sub/eac_cli/lib/eac_cli/version.rb +1 -1
  26. data/sub/{eac_ruby_base0/spec/lib/eac_ruby_base0 → eac_cli/spec/lib/eac_cli}/runner_with/confirmation_spec.rb +2 -2
  27. data/sub/{eac_ruby_base0/spec/lib/eac_ruby_base0 → eac_cli/spec/lib/eac_cli}/runner_with/output_spec.rb +4 -4
  28. data/sub/eac_rest/Gemfile +8 -0
  29. data/sub/eac_rest/eac_rest.gemspec +21 -0
  30. data/sub/eac_rest/lib/eac_rest/api.rb +69 -0
  31. data/sub/eac_rest/lib/eac_rest/entity.rb +66 -0
  32. data/sub/eac_rest/lib/eac_rest/error.rb +6 -0
  33. data/sub/eac_rest/lib/eac_rest/request.rb +48 -0
  34. data/sub/eac_rest/lib/eac_rest/response.rb +25 -0
  35. data/sub/eac_rest/lib/eac_rest/version.rb +5 -0
  36. data/sub/eac_rest/lib/eac_rest.rb +7 -0
  37. data/sub/eac_rest/spec/lib/eac_rest/api_spec.rb +71 -0
  38. data/sub/eac_rest/spec/lib/eac_rest/api_spec_files/get.source.yaml +5 -0
  39. data/sub/eac_rest/spec/lib/eac_rest/api_spec_files/get.target.yaml +9 -0
  40. data/sub/eac_rest/spec/lib/eac_rest/api_spec_files/get_with_auth.source.yaml +8 -0
  41. data/sub/eac_rest/spec/lib/eac_rest/api_spec_files/get_with_auth.target.yaml +10 -0
  42. data/sub/eac_rest/spec/lib/eac_rest/api_spec_files/post_array_body.source.yaml +10 -0
  43. data/sub/eac_rest/spec/lib/eac_rest/api_spec_files/post_array_body.target.yaml +11 -0
  44. data/sub/eac_rest/spec/lib/eac_rest/api_spec_files/post_string_body.source.yaml +4 -0
  45. data/sub/eac_rest/spec/lib/eac_rest/api_spec_files/post_string_body.target.yaml +11 -0
  46. data/sub/eac_rest/spec/lib/eac_rest/api_spec_files/put_hash_body.source.yaml +6 -0
  47. data/sub/eac_rest/spec/lib/eac_rest/api_spec_files/put_hash_body.target.yaml +11 -0
  48. data/sub/eac_rest/spec/lib/eac_rest/api_spec_files/put_with_file.source.yaml +5 -0
  49. data/sub/eac_rest/spec/lib/eac_rest/api_spec_files/put_with_file.target.yaml +13 -0
  50. data/sub/eac_rest/spec/lib/eac_rest/api_spec_files/root.source.yaml +2 -0
  51. data/sub/eac_rest/spec/lib/eac_rest/api_spec_files/root.target.yaml +9 -0
  52. data/sub/eac_rest/spec/rubocop_spec.rb +3 -0
  53. data/sub/eac_rest/spec/spec_helper/request_builder.rb +50 -0
  54. data/sub/eac_rest/spec/spec_helper.rb +7 -0
  55. data/sub/eac_ruby_base0/eac_ruby_base0.gemspec +2 -2
  56. data/sub/eac_ruby_base0/lib/eac_ruby_base0/version.rb +1 -1
  57. data/sub/eac_templates/lib/eac_templates/abstract/directory.rb +42 -0
  58. data/sub/eac_templates/lib/eac_templates/abstract/file.rb +25 -0
  59. data/sub/eac_templates/lib/eac_templates/abstract/fs_object.rb +94 -0
  60. data/sub/eac_templates/lib/eac_templates/abstract/fs_object_by_pathname.rb +13 -0
  61. data/sub/eac_templates/lib/eac_templates/abstract/not_found_error.rb +8 -0
  62. data/sub/eac_templates/lib/eac_templates/interface_methods.rb +3 -3
  63. data/sub/eac_templates/lib/eac_templates/modules/ancestor/directory.rb +4 -2
  64. data/sub/eac_templates/lib/eac_templates/modules/ancestor/file.rb +3 -2
  65. data/sub/eac_templates/lib/eac_templates/modules/ancestor/fs_object.rb +6 -13
  66. data/sub/eac_templates/lib/eac_templates/modules/ancestor.rb +6 -3
  67. data/sub/eac_templates/lib/eac_templates/sources/directory.rb +23 -10
  68. data/sub/eac_templates/lib/eac_templates/sources/file.rb +3 -14
  69. data/sub/eac_templates/lib/eac_templates/sources/fs_object.rb +17 -17
  70. data/sub/eac_templates/lib/eac_templates/sources/set.rb +5 -4
  71. data/sub/eac_templates/lib/eac_templates/variables/content.rb +52 -0
  72. data/sub/eac_templates/lib/eac_templates/variables/directory.rb +7 -5
  73. data/sub/eac_templates/lib/eac_templates/variables/file.rb +9 -33
  74. data/sub/eac_templates/lib/eac_templates/version.rb +1 -1
  75. data/sub/eac_templates/spec/lib/eac_templates/{patches/module/template_spec.rb → modules/base_spec.rb} +41 -20
  76. data/sub/eac_templates/spec/lib/eac_templates/modules/base_spec_files/path2/a_module/a/a_b +1 -0
  77. data/sub/eac_templates/spec/lib/eac_templates/modules/base_spec_files/path2/a_module/c +1 -0
  78. data/sub/eac_templates/spec/lib/eac_templates/modules/base_spec_files/path2/prepended_module/c +1 -0
  79. data/sub/eac_templates/spec/lib/eac_templates/modules/base_spec_files/path2/super_class/a/a_b +1 -0
  80. data/sub/eac_templates/spec/lib/eac_templates/variables/{file_spec.rb → content_spec.rb} +4 -4
  81. metadata +69 -39
  82. data/sub/eac_templates/spec/lib/eac_templates/patches/module/template_spec_files/path2/a_module/a/a_b +0 -1
  83. data/sub/eac_templates/spec/lib/eac_templates/patches/module/template_spec_files/path2/a_module/c +0 -1
  84. data/sub/eac_templates/spec/lib/eac_templates/patches/module/template_spec_files/path2/super_class/a/a_b +0 -1
  85. /data/sub/eac_templates/spec/lib/eac_templates/{patches/module/template_spec_files → modules/base_spec_files}/path1/a_module/a/a_a +0 -0
  86. /data/sub/eac_templates/spec/lib/eac_templates/{patches/module/template_spec_files → modules/base_spec_files}/path1/a_module/b +0 -0
  87. /data/sub/eac_templates/spec/lib/eac_templates/{patches/module/template_spec_files → modules/base_spec_files}/path1/super_class/a/a_b +0 -0
  88. /data/sub/eac_templates/spec/lib/eac_templates/{patches/module/template_spec_files → modules/base_spec_files}/path1/super_class/b +0 -0
  89. /data/sub/eac_templates/spec/lib/eac_templates/{patches/module/template_spec_files → modules/base_spec_files}/path2/a_module/b +0 -0
  90. /data/sub/eac_templates/spec/lib/eac_templates/{patches/module/template_spec_files → modules/base_spec_files}/path2/sub_class/b +0 -0
  91. /data/sub/eac_templates/spec/lib/eac_templates/{patches/module/template_spec_files → modules/base_spec_files}/path2/super_class/b +0 -0
  92. /data/sub/eac_templates/spec/lib/eac_templates/variables/{file_spec_files → content_spec_files}/expected_content +0 -0
  93. /data/sub/eac_templates/spec/lib/eac_templates/variables/{file_spec_files → content_spec_files}/source.template +0 -0
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
6
+
7
+ local_gemfile = ::File.join(::File.dirname(__FILE__), 'Gemfile.local')
8
+ eval_gemfile local_gemfile if ::File.exist?(local_gemfile)
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.push File.expand_path('lib', __dir__)
4
+
5
+ require 'eac_rest/version'
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = 'eac_rest'
9
+ s.version = EacRest::VERSION
10
+ s.authors = ['Eduardo H. Bogoni']
11
+ s.summary = 'A REST helper for Ruby.'
12
+
13
+ s.files = Dir['{lib}/**/*']
14
+
15
+ s.add_dependency 'eac_envs-http', '~> 0.3', '>= 0.3.1'
16
+ s.add_dependency 'eac_fs', '~> 0.16'
17
+ s.add_dependency 'eac_ruby_utils', '~> 0.112'
18
+
19
+ s.add_development_dependency 'aranha-parsers', '~> 0.15'
20
+ s.add_development_dependency 'eac_ruby_gem_support', '~> 0.5.1'
21
+ end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_rest/request'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module EacRest
7
+ # Abstract methods
8
+ # * self.issue_get_url_suffix(provider_issue_id)
9
+ class Api
10
+ DEFAULT_ROOT_ENTITY_CLASS_NAME_SUFFIX = 'Root'
11
+
12
+ require_sub __FILE__, include_modules: true
13
+ attr_accessor :ssl_verify
14
+ common_constructor :root_url, :username, :password, default: [nil, nil] do
15
+ self.ssl_verify = true
16
+ end
17
+
18
+ # @param entity_class [Class]
19
+ # @param url_suffix [String]
20
+ # @return [EacRest::Entity]
21
+ def entity(entity_class, data_or_id, options = {})
22
+ entity_class.new(self, data_or_id, options)
23
+ end
24
+
25
+ def request(service_url_suffix, headers = {}, &body_data_proc)
26
+ r = ::EacRest::Request.new(build_service_url(service_url_suffix),
27
+ body_data_proc).ssl_verify(ssl_verify)
28
+ headers.each { |name, value| r = r.header(name, value) }
29
+ r = r.autenticate(username, password) if username.present?
30
+ r
31
+ end
32
+
33
+ def request_json(service_url_suffix, headers = {}, &body_data_proc)
34
+ request(service_url_suffix, headers.merge('Accept' => 'application/json')) do |body_data|
35
+ r = ::JSON.parse(body_data)
36
+ r = body_data_proc.call(r) if body_data_proc
37
+ r
38
+ end
39
+ end
40
+
41
+ # @return [Addressable::URI]
42
+ def build_service_url(suffix)
43
+ r = ::Addressable::URI.parse(suffix)
44
+ return r if r.scheme.present?
45
+
46
+ s = build_service_url_suffix(suffix)
47
+ r = ::Addressable::URI.parse(root_url)
48
+ r.path += s.path
49
+ r.query_values = r.query_values(::Array).if_present([]) +
50
+ s.query_values(::Array).if_present([])
51
+ r
52
+ end
53
+
54
+ # @return [Addressable::URI]
55
+ def build_service_url_suffix(suffix)
56
+ ::Addressable::URI.parse(suffix)
57
+ end
58
+
59
+ # @return [EacRest::Entity]
60
+ def root_entity
61
+ @root_entity ||= root_entity_class.new(self, nil)
62
+ end
63
+
64
+ # @return [Class]
65
+ def root_entity_class
66
+ self.class.const_get(DEFAULT_ROOT_ENTITY_CLASS_NAME_SUFFIX)
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacRest
6
+ class Entity
7
+ enable_abstract_methods
8
+ enable_simple_cache
9
+ enable_listable
10
+ lists.add_symbol :option, :parent
11
+ common_constructor :api, :data_or_id, :options, default: [{}] do
12
+ self.options = ::EacRest::Entity.lists.option.hash_keys_validate!(options)
13
+ end
14
+
15
+ class << self
16
+ def from_array_data(api, array_data, *args)
17
+ array_data.map { |item_data| new(api, item_data, *args) }
18
+ end
19
+ end
20
+
21
+ # @param entity_class [Class]
22
+ # @param url_suffix [String]
23
+ # @return [EacRest::Entity]
24
+ def child_entity(entity_class, data_or_id, options = {})
25
+ api.entity(entity_class, data_or_id, options.merge(OPTION_PARENT => self))
26
+ end
27
+
28
+ # @return [Hash]
29
+ def data
30
+ if internal_data.blank?
31
+ self.internal_data = data_or_id_data? ? data_or_id : data_from_id
32
+ end
33
+
34
+ internal_data
35
+ end
36
+
37
+ # @return [Boolean]
38
+ def data_or_id_data?
39
+ data_or_id.is_a?(::Hash)
40
+ end
41
+
42
+ # @return [Hash]
43
+ def data_from_id
44
+ raise_abstract_method __method__
45
+ end
46
+
47
+ # @return [Object]
48
+ def id
49
+ data_or_id_data? ? id_from_data : data_or_id
50
+ end
51
+
52
+ # @return [Object]
53
+ def id_from_data
54
+ raise_abstract_method __method__
55
+ end
56
+
57
+ # @return [EacRest::Entity, nil]
58
+ def parent_entity
59
+ options[OPTION_PARENT]
60
+ end
61
+
62
+ private
63
+
64
+ attr_accessor :internal_data
65
+ end
66
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacRest
4
+ class Error < ::RuntimeError
5
+ end
6
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_envs/http/request'
4
+ require 'eac_rest/response'
5
+ require 'eac_ruby_utils/core_ext'
6
+
7
+ module EacRest
8
+ class Request
9
+ attr_reader :internal_request
10
+
11
+ # @param url [EacEnvs::Http::Request, String]
12
+ # @param response_body_data_proc [Proc, nil]
13
+ def initialize(url, response_body_data_proc = nil)
14
+ if url.is_a?(::EacEnvs::Http::Request)
15
+ @internal_request = url
16
+ else
17
+ @internal_request = ::EacEnvs::Http::Request.new.url(url)
18
+ response_body_data_proc.if_present do |v|
19
+ @internal_request = @internal_request.response_body_data_proc(v)
20
+ end
21
+ end
22
+ end
23
+
24
+ delegate :sanitized_verb, :url, to: :internal_request
25
+
26
+ {
27
+ auth: 0, body_data: 0, header: 1, headers: 0, ssl_verify: 0, verb: 0
28
+ }.each do |method_name, read_args_count|
29
+ define_method method_name do |*args|
30
+ if args.count <= read_args_count
31
+ internal_request.send(method_name, *args)
32
+ else
33
+ self.class.new(internal_request.send(method_name, *args))
34
+ end
35
+ end
36
+ end
37
+
38
+ # @return [EacRest::Request]
39
+ def autenticate(username, password)
40
+ self.class.new(internal_request.basic_auth(username, password))
41
+ end
42
+
43
+ # @return [EacRest::Response]
44
+ def response
45
+ ::EacRest::Response.new(self)
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_rest/error'
4
+ require 'eac_envs/http/error'
5
+ require 'eac_ruby_utils/core_ext'
6
+
7
+ module EacRest
8
+ class Response < ::StandardError
9
+ common_constructor :request
10
+ delegate :body_data_proc, to: :request
11
+
12
+ def internal_response
13
+ @internal_response ||= request.internal_request.response
14
+ end
15
+
16
+ %i[body_data body_data_or_raise body_str body_str_or_raise header headers
17
+ link links raise_unless_200 status to_s url].each do |method_name|
18
+ define_method method_name do |*args, &block|
19
+ internal_response.send(method_name, *args, &block)
20
+ rescue ::EacEnvs::Http::Error
21
+ raise ::EacRest::Error
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacRest
4
+ VERSION = '0.9.0'
5
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacRest
6
+ require_sub __FILE__
7
+ end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_rest/api'
4
+ require 'eac_envs/http/rspec/echo_server'
5
+
6
+ ::RSpec.describe ::EacRest::Api do
7
+ let(:instance) { described_class.new(http_server.root_url) }
8
+ let(:http_server) { ::EacEnvs::Http::Rspec::EchoServer.http }
9
+
10
+ around do |example|
11
+ http_server.on_active(&example)
12
+ end
13
+
14
+ before do
15
+ allow_any_instance_of(::Faraday::Multipart::Middleware).to( # rubocop:disable RSpec/AnyInstance
16
+ receive(:unique_boundary)
17
+ .and_return('-----------RubyMultipartPost-0123456789abcdef0123456789abcdef')
18
+ )
19
+ end
20
+
21
+ include_examples 'source_target_fixtures', __FILE__
22
+
23
+ def source_data(source_file)
24
+ remove_variable_values(
25
+ ::JSON.parse(
26
+ ::RequestBuilder.from_file(instance, source_file).result.response.body_str
27
+ )
28
+ )
29
+ end
30
+
31
+ def remove_variable_values(obj)
32
+ if obj.is_a?(::Hash)
33
+ remove_variable_values_from_hash(obj)
34
+ elsif obj.is_a?(::Enumerable)
35
+ remove_variable_values_from_enumerable(obj)
36
+ end
37
+ obj
38
+ end
39
+
40
+ def remove_variable_values_from_hash(hash)
41
+ %w[host hostname ip].each { |key| hash.delete(key) }
42
+ hash.each_value { |value| remove_variable_values(value) }
43
+ end
44
+
45
+ def remove_variable_values_from_enumerable(enumerable)
46
+ enumerable.each { |value| remove_variable_values(value) }
47
+ end
48
+
49
+ context 'with self signed https server' do
50
+ let(:http_server) { ::EacEnvs::Http::Rspec::EchoServer.https }
51
+ let(:instance) { described_class.new(http_server.root_url) }
52
+ let(:request_base) { instance.request('/any/path') }
53
+ let(:response_body) { request.response.body_str }
54
+
55
+ context 'when no additional flag' do
56
+ let(:request) { request_base }
57
+
58
+ it do
59
+ expect { response_body }.to(raise_error(::EacRest::Error))
60
+ end
61
+ end
62
+
63
+ context 'when ssl_verify disabled' do
64
+ let(:request) { request_base.ssl_verify(false) }
65
+
66
+ it do
67
+ expect { response_body }.not_to raise_error
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,5 @@
1
+ ---
2
+ url_suffix: '/path/to/service?field1=value1&field2=value2'
3
+ verb: :get
4
+ headers:
5
+ Accept: application/json
@@ -0,0 +1,9 @@
1
+ ---
2
+ ssl: false
3
+ method: GET
4
+ uri: "/path/to/service?field1=value1&field2=value2"
5
+ body:
6
+ headers:
7
+ user-agent: Faraday v2.7.4
8
+ accept: application/json
9
+ accept-encoding: gzip,deflate
@@ -0,0 +1,8 @@
1
+ ---
2
+ url_suffix: '/path/to/service?field1=value1&field2=value2'
3
+ auth:
4
+ username: the_user
5
+ password: the_secret
6
+ verb: :get
7
+ headers:
8
+ Accept: application/json
@@ -0,0 +1,10 @@
1
+ ---
2
+ ssl: false
3
+ method: GET
4
+ uri: "/path/to/service?field1=value1&field2=value2"
5
+ body:
6
+ headers:
7
+ user-agent: Faraday v2.7.4
8
+ accept: application/json
9
+ authorization: Basic dGhlX3VzZXI6dGhlX3NlY3JldA==
10
+ accept-encoding: gzip,deflate
@@ -0,0 +1,10 @@
1
+ ---
2
+ url_suffix: '/path/to/service'
3
+ verb: :post
4
+ body_data:
5
+ - - field1
6
+ - value1
7
+ - - field2
8
+ - value2
9
+ - - field1
10
+ - value3
@@ -0,0 +1,11 @@
1
+ ---
2
+ ssl: false
3
+ method: POST
4
+ uri: "/path/to/service"
5
+ body: field1=value1&field1=value3&field2=value2
6
+ headers:
7
+ user-agent: Faraday v2.7.4
8
+ content-type: application/x-www-form-urlencoded
9
+ accept-encoding: gzip,deflate
10
+ accept: "*/*"
11
+ content-length: '41'
@@ -0,0 +1,4 @@
1
+ ---
2
+ url_suffix: '/path/to/service'
3
+ verb: :post
4
+ body_data: field1=value1&field2=value2
@@ -0,0 +1,11 @@
1
+ ---
2
+ ssl: false
3
+ method: POST
4
+ uri: "/path/to/service"
5
+ body: field1=value1&field2=value2
6
+ headers:
7
+ user-agent: Faraday v2.7.4
8
+ content-type: application/x-www-form-urlencoded
9
+ accept-encoding: gzip,deflate
10
+ accept: "*/*"
11
+ content-length: '27'
@@ -0,0 +1,6 @@
1
+ ---
2
+ url_suffix: '/path/to/service'
3
+ verb: :put
4
+ body_data:
5
+ field1: value1
6
+ field2: value2
@@ -0,0 +1,11 @@
1
+ ---
2
+ ssl: false
3
+ method: PUT
4
+ uri: "/path/to/service"
5
+ body: field1=value1&field2=value2
6
+ headers:
7
+ user-agent: Faraday v2.7.4
8
+ content-type: application/x-www-form-urlencoded
9
+ accept-encoding: gzip,deflate
10
+ accept: "*/*"
11
+ content-length: '27'
@@ -0,0 +1,5 @@
1
+ ---
2
+ url_suffix: '/path/to/service'
3
+ verb: :put
4
+ body_data:
5
+ '@field1': value1
@@ -0,0 +1,13 @@
1
+ ---
2
+ ssl: false
3
+ method: PUT
4
+ uri: "/path/to/service"
5
+ body: "-------------RubyMultipartPost-0123456789abcdef0123456789abcdef\r\nContent-Disposition:
6
+ form-data; name=\"field1\"; filename=\"basename\"\r\nContent-Length: 6\r\nContent-Type:
7
+ text/plain\r\nContent-Transfer-Encoding: binary\r\n\r\nvalue1\r\n-------------RubyMultipartPost-0123456789abcdef0123456789abcdef--\r\n"
8
+ headers:
9
+ user-agent: Faraday v2.7.4
10
+ content-type: multipart/form-data; boundary=-----------RubyMultipartPost-0123456789abcdef0123456789abcdef
11
+ content-length: '290'
12
+ accept-encoding: gzip,deflate
13
+ accept: "*/*"
@@ -0,0 +1,2 @@
1
+ ---
2
+ url_suffix: ''
@@ -0,0 +1,9 @@
1
+ ---
2
+ ssl: false
3
+ method: GET
4
+ uri: "/"
5
+ body:
6
+ headers:
7
+ user-agent: Faraday v2.7.4
8
+ accept-encoding: gzip,deflate
9
+ accept: "*/*"
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ ::EacRubyUtils::Rspec.default_setup.describe_rubocop
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'eac_ruby_utils/fs/temp'
5
+ require 'eac_ruby_utils/yaml'
6
+
7
+ class RequestBuilder
8
+ class << self
9
+ def from_file(api, path)
10
+ new(api, ::EacRubyUtils::Yaml.load_file(path))
11
+ end
12
+ end
13
+
14
+ FILE_FIELD_PARSER = /\A@(.+)\z/.to_parser { |m| m[1] }
15
+
16
+ common_constructor :api, :data do
17
+ self.data = data.with_indifferent_access
18
+ end
19
+
20
+ def result
21
+ r = %i[verb headers].inject(selected_api.request(data.fetch(:url_suffix))) do |a, e|
22
+ data[e].if_present(a) { |v| a.send(e, v) }
23
+ end
24
+ data[:body_data].if_present(r) { |v| r.body_data(build_body_data(v)) }
25
+ end
26
+
27
+ def build_body_data(source)
28
+ return source unless source.is_a?(::Hash)
29
+
30
+ source.map { |k, v| build_body_field(k, v) }
31
+ end
32
+
33
+ def build_body_field(name, value)
34
+ FILE_FIELD_PARSER.parse(name).if_present([name, value]) do |v|
35
+ [v, file_with_value(value)]
36
+ end
37
+ end
38
+
39
+ def file_with_value(value)
40
+ r = ::EacRubyUtils::Fs::Temp.directory.join('basename')
41
+ r.write(value)
42
+ ::File.new(r.to_path)
43
+ end
44
+
45
+ def selected_api
46
+ data[:auth].if_present(api) do |v|
47
+ api.class.new(api.root_url, v.fetch(:username), v.fetch(:password))
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/rspec/default_setup'
4
+ ::EacRubyUtils::Rspec.default_setup_create(::File.expand_path('..', __dir__))
5
+
6
+ require 'eac_ruby_utils/require_sub'
7
+ ::EacRubyUtils.require_sub __FILE__
@@ -12,8 +12,8 @@ Gem::Specification.new do |s|
12
12
 
13
13
  s.files = Dir['{lib}/**/*']
14
14
 
15
- s.add_dependency 'avm-eac_ruby_base1', '~> 0.29'
16
- s.add_dependency 'eac_cli', '~> 0.30', '>= 0.30.1'
15
+ s.add_dependency 'avm-eac_ruby_base1', '~> 0.30', '>= 0.30.2'
16
+ s.add_dependency 'eac_cli', '~> 0.31'
17
17
  s.add_dependency 'eac_fs', '~> 0.16'
18
18
  s.add_dependency 'eac_ruby_utils', '~> 0.112'
19
19
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyBase0
4
- VERSION = '0.17.3'
4
+ VERSION = '0.18.0'
5
5
  end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'eac_templates/interface_methods'
5
+ require 'eac_templates/abstract/fs_object'
6
+ require 'eac_templates/variables/directory'
7
+
8
+ module EacTemplates
9
+ module Abstract
10
+ class Directory < ::EacTemplates::Abstract::FsObject
11
+ enable_abstract_methods
12
+ delegate(*::EacTemplates::InterfaceMethods::DIRECTORY - %i[child chidren], to: :applier)
13
+
14
+ # @param basename [Pathname]
15
+ # @return [EacTemplates::Abstract::FsObject
16
+ def build_child(child_basename, child_type)
17
+ child_basename = child_basename.to_pathname
18
+ child_type = type_list.value_validate!(child_type)
19
+ category_module.const_get(child_type.to_s.camelize)
20
+ .new(owner, self, child_basename, options)
21
+ end
22
+
23
+ # @param basename [Pathname]
24
+ # @return [EacTemplates::Abstract::FsObject]
25
+ def child(basename)
26
+ basename = basename.to_pathname
27
+ children.find { |c| c.basename == basename } ||
28
+ raise_not_found("No child found with basename \"#{basename}\"")
29
+ end
30
+
31
+ # @return [Enumerable<EacTemplates::Abstract::FsObject>]
32
+ def children
33
+ children_basenames.map { |c_basename, c_type| build_child(c_basename, c_type) }
34
+ end
35
+
36
+ # @return [Hash<Pathname, Symbol>]
37
+ def children_basenames
38
+ raise_abstract_method __method__
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'eac_templates/interface_methods'
5
+ require 'eac_templates/abstract/fs_object'
6
+ require 'eac_templates/variables/file'
7
+
8
+ module EacTemplates
9
+ module Abstract
10
+ class File < ::EacTemplates::Abstract::FsObject
11
+ enable_abstract_methods
12
+ delegate(*::EacTemplates::InterfaceMethods::FILE - %i[content path], to: :applier)
13
+
14
+ # @return [String]
15
+ def content
16
+ path.read
17
+ end
18
+
19
+ # @return [Pathname]
20
+ def path
21
+ raise_abstract_method __method__
22
+ end
23
+ end
24
+ end
25
+ end