ehbrs-tools 0.16.0 → 0.16.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ehbrs/runner/videos/probe.rb +3 -3
- data/lib/ehbrs/tools/version.rb +1 -1
- data/lib/ehbrs/vg/wii/wit/parsers/dump.rb +10 -5
- data/lib/ehbrs/videos/file.rb +4 -8
- data/lib/ehbrs/videos/track.rb +5 -13
- data/lib/ehbrs/videos/unsupported/checks/codec_extra_unlisted.rb +3 -1
- data/lib/ehbrs/videos/unsupported/checks/codec_extra_unsupported.rb +3 -1
- data/lib/ehbrs/videos/unsupported/checks/codec_unlisted.rb +4 -2
- data/lib/ehbrs/videos/unsupported/checks/codec_unsupported.rb +3 -1
- data/lib/ehbrs/videos/unsupported/checks/invalid_extension.rb +2 -0
- data/lib/ehbrs/videos/unsupported/fix_profile.rb +0 -13
- data/lib/ehbrs/videos/unsupported/fixes/supported_codec.rb +10 -10
- data/lib/ehbrs/videos/unsupported/profiles/base.rb +17 -3
- data/lib/ehbrs/videos/unsupported/profiles/philco.rb +5 -4
- data/vendor/aranha-parsers/Gemfile +5 -0
- data/vendor/aranha-parsers/aranha-parsers.gemspec +23 -0
- data/vendor/aranha-parsers/lib/aranha/parsers.rb +9 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/base.rb +79 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/html.rb +11 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/html/base.rb +47 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/html/item.rb +24 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/html/item_list.rb +29 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/html/node.rb +13 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/html/node/base.rb +36 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/html/node/default.rb +126 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/invalid_state_exception.rb +8 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/patches.rb +11 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/patches/ofx_parser.rb +38 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/source_address.rb +55 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/source_address/file.rb +31 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/source_address/hash_http_get.rb +25 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/source_address/hash_http_post.rb +45 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/source_address/http_get.rb +49 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/source_target_fixtures.rb +77 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/spec/source_target_fixtures_example.rb +78 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/version.rb +7 -0
- data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_address/http_get_spec.rb +21 -0
- data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_address_spec.rb +74 -0
- data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec.rb +27 -0
- data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub1.source.txt +1 -0
- data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub1.target.html +1 -0
- data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub2.source.html +1 -0
- data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub3.target.yaml +1 -0
- data/vendor/aranha-parsers/spec/lib/rubocop_check_spec.rb +7 -0
- data/vendor/aranha-parsers/spec/spec_helper.rb +8 -0
- data/vendor/eac_cli/eac_cli.gemspec +1 -1
- data/vendor/eac_cli/lib/eac_cli/definition.rb +36 -31
- data/vendor/eac_cli/lib/eac_cli/definition/alternative.rb +83 -0
- data/vendor/eac_cli/lib/eac_cli/definition/help_formatter.rb +76 -0
- data/vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb +15 -2
- data/vendor/eac_cli/lib/eac_cli/docopt/doc_builder.rb +18 -40
- data/vendor/eac_cli/lib/eac_cli/docopt/doc_builder/alternative.rb +50 -0
- data/vendor/eac_cli/lib/eac_cli/parser.rb +23 -3
- data/vendor/eac_cli/lib/eac_cli/parser/alternative.rb +92 -0
- data/vendor/eac_cli/lib/eac_cli/parser/alternative/argv.rb +17 -0
- data/vendor/eac_cli/lib/eac_cli/parser/alternative/double_dash.rb +24 -0
- data/vendor/eac_cli/lib/eac_cli/parser/alternative/options.rb +58 -0
- data/vendor/eac_cli/lib/eac_cli/parser/alternative/positionals.rb +30 -0
- data/vendor/eac_cli/lib/eac_cli/runner.rb +12 -4
- data/vendor/eac_cli/lib/eac_cli/runner/exit.rb +13 -0
- data/vendor/eac_cli/lib/eac_cli/runner_with/help.rb +18 -1
- data/vendor/eac_cli/lib/eac_cli/runner_with/output_file.rb +5 -1
- data/vendor/eac_cli/lib/eac_cli/runner_with/subcommands.rb +6 -1
- data/vendor/eac_cli/lib/eac_cli/version.rb +1 -1
- data/vendor/eac_cli/spec/lib/eac_cli/definition/alternative_spec.rb +14 -0
- data/vendor/eac_cli/spec/lib/eac_cli/docopt/runner_extension_spec.rb +10 -0
- data/vendor/eac_cli/spec/lib/eac_cli/parser/alternative_spec.rb +140 -0
- data/vendor/eac_cli/spec/lib/eac_cli/runner_spec.rb +17 -5
- data/vendor/eac_cli/spec/lib/eac_cli/runner_with/help_spec.rb +42 -0
- data/vendor/eac_cli/spec/lib/eac_cli/runner_with/output_file_spec.rb +53 -0
- data/vendor/eac_cli/spec/lib/eac_cli/runner_with/subcommands_spec.rb +29 -1
- data/vendor/eac_docker/lib/eac_docker/container.rb +24 -0
- data/vendor/eac_docker/lib/eac_docker/images/coded.rb +39 -0
- data/vendor/eac_docker/lib/eac_docker/images/templatized.rb +26 -0
- data/vendor/eac_docker/lib/eac_docker/registry.rb +17 -0
- data/vendor/eac_docker/lib/eac_docker/version.rb +1 -1
- data/vendor/eac_docker/spec/lib/eac_docker/images/coded_spec.rb +12 -0
- data/vendor/eac_docker/spec/lib/eac_docker/images/coded_spec_files/image1/Dockerfile +1 -0
- data/vendor/eac_docker/spec/lib/eac_docker/images/templatized_spec.rb +17 -0
- data/vendor/eac_docker/spec/lib/eac_docker/images/templatized_spec_files/stub_docker_image/Dockerfile +1 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/abstract_methods.rb +60 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern.rb +2 -50
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern/class_setup.rb +52 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern/module_setup.rb +31 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_constructor.rb +53 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs.rb +4 -69
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/entry_reader.rb +81 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/password_entry_reader.rb +18 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/read_entry_options.rb +7 -2
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/store_passwords_entry_reader.rb +27 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command.rb +4 -6
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/concat.rb +33 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/envvars.rb +24 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/extra_options.rb +0 -21
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/abstract_methods.rb +10 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/debug.rb +17 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/pathname/basename_sub.rb +2 -2
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/struct.rb +7 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/yaml.rb +3 -2
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/abstract_methods_spec.rb +28 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/common_concern_spec.rb +30 -17
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/common_constructor_spec.rb +66 -8
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/struct_spec.rb +12 -1
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/version.rb +1 -1
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container.rb +30 -2
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/convert_job.rb +91 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/stream.rb +51 -0
- metadata +92 -13
- data/vendor/eac_cli/lib/eac_cli/parser/options_collection.rb +0 -127
- data/vendor/eac_cli/lib/eac_cli/parser/parse_result.rb +0 -38
- data/vendor/eac_cli/lib/eac_cli/parser/positional_collection.rb +0 -77
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container/file.rb +0 -31
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container/info.rb +0 -21
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/core_ext/hash/indifferent_access'
|
4
|
+
require 'httpclient'
|
5
|
+
require 'yaml'
|
6
|
+
|
7
|
+
module Aranha
|
8
|
+
module Parsers
|
9
|
+
class SourceAddress
|
10
|
+
class HashHttpPost
|
11
|
+
class << self
|
12
|
+
def valid_source?(source)
|
13
|
+
source.is_a?(::Hash) &&
|
14
|
+
source.with_indifferent_access[:method].to_s.downcase.strip == 'post'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
attr_reader :source
|
19
|
+
|
20
|
+
def initialize(source)
|
21
|
+
@source = source.with_indifferent_access
|
22
|
+
end
|
23
|
+
|
24
|
+
def ==(other)
|
25
|
+
self.class == other.class && source == other.source
|
26
|
+
end
|
27
|
+
|
28
|
+
def url
|
29
|
+
source.fetch(:url)
|
30
|
+
end
|
31
|
+
|
32
|
+
def serialize
|
33
|
+
source.to_yaml
|
34
|
+
end
|
35
|
+
|
36
|
+
def content
|
37
|
+
HTTPClient.new.post_content(
|
38
|
+
source[:url],
|
39
|
+
source[:params].merge(follow_redirect: true)
|
40
|
+
)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'addressable'
|
4
|
+
require 'curb'
|
5
|
+
|
6
|
+
module Aranha
|
7
|
+
module Parsers
|
8
|
+
class SourceAddress
|
9
|
+
class HttpGet
|
10
|
+
class << self
|
11
|
+
def location_uri(source_uri, location)
|
12
|
+
::Addressable::URI.join(source_uri, location).to_s
|
13
|
+
end
|
14
|
+
|
15
|
+
def valid_source?(source)
|
16
|
+
source.to_s =~ %r{\Ahttps?://}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
attr_reader :source
|
21
|
+
|
22
|
+
def initialize(source)
|
23
|
+
@source = source.to_s
|
24
|
+
end
|
25
|
+
|
26
|
+
def ==(other)
|
27
|
+
self.class == other.class && source == other.source
|
28
|
+
end
|
29
|
+
|
30
|
+
def url
|
31
|
+
source
|
32
|
+
end
|
33
|
+
|
34
|
+
def content
|
35
|
+
c = ::Curl::Easy.new(url)
|
36
|
+
c.follow_location = true
|
37
|
+
raise "Curl perform failed (URL: #{url})" unless c.perform
|
38
|
+
return c.body_str if c.status.to_i == 200
|
39
|
+
|
40
|
+
raise "Get #{url} returned #{c.status.to_i}"
|
41
|
+
end
|
42
|
+
|
43
|
+
def serialize
|
44
|
+
url
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/core_ext/object'
|
4
|
+
require 'active_support/core_ext/string'
|
5
|
+
|
6
|
+
module Aranha
|
7
|
+
module Parsers
|
8
|
+
# Lists pairs of source/target files in a directory.
|
9
|
+
class SourceTargetFixtures
|
10
|
+
class << self
|
11
|
+
def source_target_basename(file)
|
12
|
+
m = /^(.+)\.(?:source|target)(?:\..+)?$/.match(File.basename(file))
|
13
|
+
m ? m[1] : nil
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
attr_reader :fixtures_directory
|
18
|
+
|
19
|
+
def initialize(fixtures_directory)
|
20
|
+
@fixtures_directory = fixtures_directory
|
21
|
+
end
|
22
|
+
|
23
|
+
def source_target_files
|
24
|
+
sources_targets_basenames.map do |basename|
|
25
|
+
OpenStruct.new(basename: basename, source: source_file(basename),
|
26
|
+
target: target_file(basename))
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def source_files
|
31
|
+
r = []
|
32
|
+
source_target_files.each do |st|
|
33
|
+
r << st.source if st.source
|
34
|
+
end
|
35
|
+
r
|
36
|
+
end
|
37
|
+
|
38
|
+
def target_files
|
39
|
+
r = []
|
40
|
+
source_target_files.each do |st|
|
41
|
+
r << st.target if st.target
|
42
|
+
end
|
43
|
+
r
|
44
|
+
end
|
45
|
+
|
46
|
+
def target_file(basename)
|
47
|
+
fixture_file(basename, 'target')
|
48
|
+
end
|
49
|
+
|
50
|
+
def source_file(basename)
|
51
|
+
fixture_file(basename, 'source')
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def fixture_file(basename, suffix)
|
57
|
+
prefix = "#{basename}.#{suffix}"
|
58
|
+
Dir.foreach(fixtures_directory) do |item|
|
59
|
+
next if %w[. ..].include?(item)
|
60
|
+
return File.expand_path(item, fixtures_directory) if item.starts_with?(prefix)
|
61
|
+
end
|
62
|
+
nil
|
63
|
+
end
|
64
|
+
|
65
|
+
def sources_targets_basenames
|
66
|
+
basenames = Set.new
|
67
|
+
Dir.foreach(fixtures_directory) do |item|
|
68
|
+
next if %w[. ..].include?(item)
|
69
|
+
|
70
|
+
b = self.class.source_target_basename(item)
|
71
|
+
basenames << b if b.present?
|
72
|
+
end
|
73
|
+
basenames
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'aranha/parsers/source_target_fixtures'
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
RSpec.shared_examples 'source_target_fixtures' do |spec_file| # rubocop:disable Metrics/BlockLength
|
7
|
+
let(:spec_file) { spec_file }
|
8
|
+
|
9
|
+
it 'fixtures directory should exist' do
|
10
|
+
expect(::File.directory?(fixtures_dir)).to be true
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'with fixtures directory' do
|
14
|
+
it 'has at least one file' do
|
15
|
+
expect(source_target_fixtures.source_target_files.count).to be > 0 # rubocop:disable Style/NumericPredicate
|
16
|
+
end
|
17
|
+
|
18
|
+
if ENV['WRITE_TARGET_FIXTURES']
|
19
|
+
it 'writes target data for all files' do
|
20
|
+
source_target_fixtures.source_files.each do |source_file|
|
21
|
+
sd = sort_results(source_data(source_file))
|
22
|
+
basename = ::Aranha::Parsers::SourceTargetFixtures.source_target_basename(source_file)
|
23
|
+
target_file = File.expand_path("../#{basename}.target#{target_file_extname}", source_file)
|
24
|
+
File.write(target_file, target_content(sd))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
else
|
28
|
+
it 'parses data for all files' do
|
29
|
+
source_target_fixtures.source_target_files.each do |st|
|
30
|
+
assert_source_target_complete(st)
|
31
|
+
sd = source_data(st.source)
|
32
|
+
td = target_data(st.target)
|
33
|
+
expect(sort_results(sd)).to eq(sort_results(td))
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def source_target_fixtures
|
40
|
+
@source_target_fixtures ||= ::Aranha::Parsers::SourceTargetFixtures.new(fixtures_dir)
|
41
|
+
end
|
42
|
+
|
43
|
+
def assert_source_target_complete(source_target)
|
44
|
+
expect(source_target.source).to(be_truthy, "Source not found (Target: #{source_target.target})")
|
45
|
+
expect(source_target.target).to(be_truthy, "Target not found (Source: #{source_target.source})")
|
46
|
+
end
|
47
|
+
|
48
|
+
def source_data(source_file)
|
49
|
+
instance = described_class.new(source_file)
|
50
|
+
return instance.data if instance.respond_to?(:data)
|
51
|
+
|
52
|
+
raise "#{instance} has no \"data\" method. You need to implement \"#{instance}.data\" or " \
|
53
|
+
"\"#{self}.source_data(source_file)\""
|
54
|
+
end
|
55
|
+
|
56
|
+
def fixtures_dir
|
57
|
+
::File.join(
|
58
|
+
::File.dirname(spec_file),
|
59
|
+
::File.basename(spec_file, '.*') + '_files'
|
60
|
+
)
|
61
|
+
end
|
62
|
+
|
63
|
+
def sort_results(results)
|
64
|
+
results
|
65
|
+
end
|
66
|
+
|
67
|
+
def target_data(target_file)
|
68
|
+
::YAML.load_file(target_file)
|
69
|
+
end
|
70
|
+
|
71
|
+
def target_content(data)
|
72
|
+
data.to_yaml
|
73
|
+
end
|
74
|
+
|
75
|
+
def target_file_extname
|
76
|
+
'.yaml'
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'aranha/parsers/source_address/http_get'
|
4
|
+
|
5
|
+
RSpec.describe ::Aranha::Parsers::SourceAddress::HttpGet do
|
6
|
+
SOURCE_URI = 'http://example.net/abc' # rubocop:disable RSpec/LeakyConstantDeclaration
|
7
|
+
|
8
|
+
describe '#location_uri' do
|
9
|
+
[
|
10
|
+
{ location: 'http://example.net/def', expected: 'http://example.net/def' },
|
11
|
+
{ location: '/def', expected: 'http://example.net/def' }
|
12
|
+
].each do |stub|
|
13
|
+
context "when source_uri is \"#{SOURCE_URI}\" and location is \"#{stub.fetch(:location)}\"" do
|
14
|
+
it "return #{stub.fetch(:expected)}" do
|
15
|
+
expect(described_class.location_uri(SOURCE_URI, stub.fetch(:location)))
|
16
|
+
.to eq(stub.fetch(:expected))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'aranha/parsers/source_address'
|
4
|
+
|
5
|
+
RSpec.describe ::Aranha::Parsers::SourceAddress do
|
6
|
+
describe '#detect_sub' do
|
7
|
+
{
|
8
|
+
{ method: :post, url: 'http://postdata.net', params: { key1: :value1 } } => {
|
9
|
+
klass: ::Aranha::Parsers::SourceAddress::HashHttpPost,
|
10
|
+
url: 'http://postdata.net',
|
11
|
+
serialization: <<~SERIALIZATION
|
12
|
+
--- !ruby/hash:ActiveSupport::HashWithIndifferentAccess
|
13
|
+
method: :post
|
14
|
+
url: http://postdata.net
|
15
|
+
params: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
|
16
|
+
key1: :value1
|
17
|
+
SERIALIZATION
|
18
|
+
},
|
19
|
+
{ method: :get, url: 'http://getdata.net', params: { headers: %w[abc] } } => {
|
20
|
+
klass: ::Aranha::Parsers::SourceAddress::HashHttpPost,
|
21
|
+
url: 'http://getdata.net',
|
22
|
+
serialization: <<~SERIALIZATION
|
23
|
+
--- !ruby/hash:ActiveSupport::HashWithIndifferentAccess
|
24
|
+
method: :get
|
25
|
+
url: http://getdata.net
|
26
|
+
params: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
|
27
|
+
headers:
|
28
|
+
- abc
|
29
|
+
SERIALIZATION
|
30
|
+
},
|
31
|
+
'http://postdata.net' => {
|
32
|
+
klass: ::Aranha::Parsers::SourceAddress::HttpGet,
|
33
|
+
url: 'http://postdata.net',
|
34
|
+
serialization: 'http://postdata.net'
|
35
|
+
},
|
36
|
+
'https://getdata.com.br' => {
|
37
|
+
klass: ::Aranha::Parsers::SourceAddress::HttpGet,
|
38
|
+
url: 'https://getdata.com.br',
|
39
|
+
serialization: 'https://getdata.com.br'
|
40
|
+
},
|
41
|
+
'file:///postdata.net' => {
|
42
|
+
klass: ::Aranha::Parsers::SourceAddress::File,
|
43
|
+
url: 'file:///postdata.net',
|
44
|
+
serialization: 'file:///postdata.net'
|
45
|
+
},
|
46
|
+
'/postdata.net' => {
|
47
|
+
klass: ::Aranha::Parsers::SourceAddress::File,
|
48
|
+
url: 'file:///postdata.net',
|
49
|
+
serialization: 'file:///postdata.net'
|
50
|
+
}
|
51
|
+
}.each do |source, expected|
|
52
|
+
context "when source is #{source}" do
|
53
|
+
let(:sub) { described_class.detect_sub(source) }
|
54
|
+
let(:deserialized) { described_class.deserialize(sub.serialize).sub }
|
55
|
+
|
56
|
+
it "sub is a #{expected.fetch(:klass)}" do
|
57
|
+
expect(sub).to be_a(expected.fetch(:klass))
|
58
|
+
end
|
59
|
+
|
60
|
+
it "sub #{expected.fetch(:klass)} return properly URL" do
|
61
|
+
expect(sub.url).to eq(expected.fetch(:url))
|
62
|
+
end
|
63
|
+
|
64
|
+
it "sub #{expected.fetch(:klass)} serialize properly" do
|
65
|
+
expect(sub.serialize).to eq(expected.fetch(:serialization))
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'deserialize properly' do
|
69
|
+
expect(deserialized).to eq(sub)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'aranha/parsers/source_target_fixtures'
|
4
|
+
|
5
|
+
RSpec.describe ::Aranha::Parsers::SourceTargetFixtures do
|
6
|
+
let(:fixtures_dir) { ::File.join(__dir__, 'source_target_fixtures_spec_files') }
|
7
|
+
let(:instance) { described_class.new(fixtures_dir) }
|
8
|
+
|
9
|
+
describe '#source_target_files' do
|
10
|
+
it { expect(instance.source_target_files.count).to eq(3) }
|
11
|
+
|
12
|
+
(1..3).each do |index|
|
13
|
+
basename = "stub#{index}"
|
14
|
+
let(basename) { instance.source_target_files.find { |stf| stf.basename == basename } }
|
15
|
+
|
16
|
+
it { expect(send(basename)).to be_present }
|
17
|
+
it { expect(send(basename).basename).to eq(basename) }
|
18
|
+
end
|
19
|
+
|
20
|
+
it { expect(stub1.source).to eq(::File.join(fixtures_dir, 'stub1.source.txt')) }
|
21
|
+
it { expect(stub1.target).to eq(::File.join(fixtures_dir, 'stub1.target.html')) }
|
22
|
+
it { expect(stub2.source).to eq(::File.join(fixtures_dir, 'stub2.source.html')) }
|
23
|
+
it { expect(stub2.target).to eq(nil) }
|
24
|
+
it { expect(stub3.source).to eq(nil) }
|
25
|
+
it { expect(stub3.target).to eq(::File.join(fixtures_dir, 'stub3.target.yaml')) }
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
|
|
12
12
|
|
13
13
|
s.files = Dir['{lib}/**/*', 'Gemfile']
|
14
14
|
|
15
|
-
s.add_dependency 'eac_ruby_utils', '~> 0.
|
15
|
+
s.add_dependency 'eac_ruby_utils', '~> 0.55'
|
16
16
|
|
17
17
|
s.add_development_dependency 'eac_ruby_gem_support', '~> 0.1', '>= 0.1.2'
|
18
18
|
end
|
@@ -9,72 +9,65 @@ module EacCli
|
|
9
9
|
class Definition
|
10
10
|
require_sub __FILE__
|
11
11
|
|
12
|
+
MAIN_ALTERNATIVE_KEY = :main
|
12
13
|
SUBCOMMAND_NAME_ARG = 'subcommand'
|
13
14
|
SUBCOMMAND_ARGS_ARG = 'subcommand_args'
|
14
15
|
|
15
16
|
attr_accessor :description
|
16
|
-
attr_accessor :options_argument
|
17
17
|
|
18
18
|
def initialize
|
19
19
|
self.description = '-- NO DESCRIPTION SET --'
|
20
|
-
|
20
|
+
alternatives_set[MAIN_ALTERNATIVE_KEY] = main_alternative
|
21
21
|
end
|
22
22
|
|
23
23
|
def alt(&block)
|
24
|
-
r = ::EacCli::Definition.new
|
24
|
+
r = ::EacCli::Definition::Alternative.new
|
25
25
|
r.instance_eval(&block)
|
26
|
-
|
26
|
+
alternatives_set[new_alternative_key] = r
|
27
27
|
r
|
28
28
|
end
|
29
29
|
|
30
30
|
def alternatives
|
31
|
-
|
31
|
+
alternatives_set.values
|
32
32
|
end
|
33
33
|
|
34
|
-
def
|
35
|
-
|
36
|
-
short, long, description, option_options
|
37
|
-
)
|
38
|
-
end
|
39
|
-
|
40
|
-
def bool_opt(short, long, description, option_options = {})
|
41
|
-
options << ::EacCli::Definition::BooleanOption.new(short, long, description, option_options)
|
34
|
+
def alternative(key)
|
35
|
+
alternatives_set.fetch(key)
|
42
36
|
end
|
43
37
|
|
44
38
|
def desc(description)
|
45
39
|
self.description = description
|
46
40
|
end
|
47
41
|
|
48
|
-
def
|
49
|
-
|
42
|
+
def help_formatter
|
43
|
+
@help_formatter ||= ::EacCli::Definition::HelpFormatter.new(self)
|
50
44
|
end
|
51
45
|
|
52
|
-
def
|
53
|
-
@
|
46
|
+
def main_alternative
|
47
|
+
@main_alternative ||= begin
|
48
|
+
r = ::EacCli::Definition::Alternative.new
|
49
|
+
r.options_argument(true)
|
50
|
+
r
|
51
|
+
end
|
54
52
|
end
|
55
53
|
|
56
|
-
def
|
57
|
-
|
58
|
-
|
59
|
-
pos_set << ::EacCli::Definition::PositionalArgument.new(name, arg_options)
|
54
|
+
def options_arg(options_argument)
|
55
|
+
self.options_argument = options_argument
|
60
56
|
end
|
61
57
|
|
62
|
-
def
|
63
|
-
|
58
|
+
def options_argument
|
59
|
+
main_alternative.options_argument?
|
64
60
|
end
|
65
61
|
|
66
|
-
def
|
67
|
-
|
62
|
+
def options_argument=(enable)
|
63
|
+
main_alternative.options_argument(enable)
|
68
64
|
end
|
69
65
|
|
70
|
-
|
71
|
-
|
72
|
-
pos_set << ::EacCli::Definition::PositionalArgument.new(SUBCOMMAND_ARGS_ARG,
|
73
|
-
optional: true, repeat: true)
|
74
|
-
end
|
66
|
+
delegate :arg_opt, :bool_opt, :options, :pos_arg,
|
67
|
+
:positional, :subcommands, to: :main_alternative
|
75
68
|
|
76
69
|
def subcommands?
|
77
|
-
|
70
|
+
alternatives.any?(&:subcommands?)
|
78
71
|
end
|
79
72
|
|
80
73
|
def options_first(enable = true)
|
@@ -87,6 +80,18 @@ module EacCli
|
|
87
80
|
|
88
81
|
private
|
89
82
|
|
83
|
+
def alternatives_set
|
84
|
+
@alternatives_set ||= ::ActiveSupport::HashWithIndifferentAccess.new
|
85
|
+
end
|
86
|
+
|
87
|
+
def new_alternative_key
|
88
|
+
@last_key ||= 0
|
89
|
+
loop do
|
90
|
+
@last_key += 1
|
91
|
+
break @last_key unless alternatives_set.key?(@last_key)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
90
95
|
def pos_set
|
91
96
|
@pos_set ||= []
|
92
97
|
end
|