avm-tools 0.77.0 → 0.78.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3345f4afdd4f7bb8cb968848675bc6b1d5c91e5833b17e90c43a01eae82a95c3
4
- data.tar.gz: 5e032e2b459e3c1fe3bf5c42e054d89491736c8e181b17a988a079068728b526
3
+ metadata.gz: 31676da0253c7ec8dc92aee2619723858f021faedb659e4f6128a7552eaad975
4
+ data.tar.gz: b6c14df8700750c9e0a39c9b8de6ee78e5864bdbf8ff2c21c7c59f029257437f
5
5
  SHA512:
6
- metadata.gz: eccb5df2cf88efda09388fdcbf6a363ad32d49772980b57a58865d5b322c49848cfbaacbd572d4c7c9f9fa2af486ee5efb32b6632b91ead052546e76aa3be51d
7
- data.tar.gz: a28d9a27d6c22363d021dad5c1bee61cff8785139c9f69cf131762a6702f988d478ae15880845eb6294941b99e0e391496f4298e99864455543ebad80f8e8866
6
+ metadata.gz: 989f01a3eb81d88b99186f3471f7437cdd00d7f6d182a68cb2f1080461f08cbadb84bb30782e8bab731eecd75782cc7728d175920cb28f8544e31f88e435ef02
7
+ data.tar.gz: 2b51fd22a6aec3d7955f75c3f4d1c68fc5a60c2c8c2dbc13e25cdaff6396df1ba655e1ef5183ab3081e18f17b642a5cf832f7583e80997c6bfb121c90fd0c0a4
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/core_ext'
4
+ require 'eac_git/local'
5
+ require 'eac_ruby_utils/console/docopt_runner'
6
+
7
+ module Avm
8
+ module Tools
9
+ class Runner < ::EacRubyUtils::Console::DocoptRunner
10
+ class Git < ::EacRubyUtils::Console::DocoptRunner
11
+ class Subrepo < ::EacRubyUtils::Console::DocoptRunner
12
+ class Clone
13
+ runner_with :help do
14
+ desc 'Clone git-subrepo repositories.'
15
+ arg_opt '-b', '--branch', 'Branch.'
16
+ arg_opt '-d', '--parent-dir', 'Target path\'s parent directory.'
17
+ pos_arg :url
18
+ pos_arg :target_path, optional: true
19
+ end
20
+
21
+ def run
22
+ start_banner
23
+ clean
24
+ clone
25
+ end
26
+
27
+ private
28
+
29
+ def start_banner
30
+ infov 'URL', url
31
+ infov 'Subpath', target_path
32
+ infov 'Branch', branch
33
+ end
34
+
35
+ def clean
36
+ infom 'Cleaning...'
37
+ git.command('subrepo', 'clean', '--all', '--force').system!
38
+ end
39
+
40
+ def clone
41
+ infom 'Cloning...'
42
+ infov 'Clone arguments', clone_args
43
+ git.command(*clone_args).system!
44
+ end
45
+
46
+ delegate :branch, :url, to: :parsed
47
+
48
+ def git_uncached
49
+ ::EacGit::Local.new('.')
50
+ end
51
+
52
+ def clone_args
53
+ ['subrepo'] + branch.if_present([]) { |v| ['--branch', v] } +
54
+ if ::File.exist?(target_path)
55
+ ['init', target_path, '--remote', url]
56
+ else
57
+ ['clone', url, target_path, '--message', clone_message, '--force']
58
+ end
59
+ end
60
+
61
+ def clone_message
62
+ "Subrepo \"#{target_path}\" (#{url})."
63
+ end
64
+
65
+ def repos_name_from_url
66
+ %r{/([^/]+)\z}.if_match(url, false) { |m| m[1].gsub(/\.git\z/, '') }
67
+ end
68
+
69
+ def target_path
70
+ parsed.target_path || target_path_from_parent_dir ||
71
+ fatal_error('No target path specified')
72
+ end
73
+
74
+ def target_path_from_parent_dir
75
+ return nil unless parsed.parent_dir && repos_name_from_url
76
+
77
+ ::File.join(parsed.parent_dir, repos_name_from_url)
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Avm
4
4
  module Tools
5
- VERSION = '0.77.0'
5
+ VERSION = '0.78.0'
6
6
  end
7
7
  end
@@ -2,12 +2,16 @@
2
2
 
3
3
  require 'eac_cli/runner'
4
4
  require 'eac_ruby_utils/core_ext'
5
+ require 'eac_ruby_utils/abstract_methods'
5
6
 
6
7
  module EacCli
7
8
  module RunnerWith
8
9
  module OutputFile
9
10
  common_concern do
10
11
  include ::EacCli::Runner
12
+ include ::EacRubyUtils::AbstractMethods
13
+
14
+ abstract_methods :output_content
11
15
 
12
16
  runner_definition do
13
17
  arg_opt '-o', '--output-file', 'Output to file.'
@@ -18,7 +22,7 @@ module EacCli
18
22
  if parsed.output_file.present?
19
23
  ::File.write(parsed.output_file, output_content)
20
24
  else
21
- out output_content
25
+ $stdout.write(output_content)
22
26
  end
23
27
  end
24
28
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacCli
4
- VERSION = '0.12.1'
4
+ VERSION = '0.12.2'
5
5
  end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/runner_with/output_file'
4
+ require 'eac_ruby_utils/fs/temp'
5
+
6
+ RSpec.describe ::EacCli::RunnerWith::OutputFile do
7
+ let(:runner) do
8
+ the_module = described_class
9
+ Class.new do
10
+ include the_module
11
+
12
+ runner_definition do
13
+ desc 'A stub root runner.'
14
+ pos_arg :input_text
15
+ end
16
+
17
+ def run
18
+ run_output
19
+ end
20
+
21
+ def output_content
22
+ parsed.input_text
23
+ end
24
+ end
25
+ end
26
+
27
+ let(:stub_text) { 'STUB_TEXT' }
28
+ let(:instance) { runner.create(argv: runner_argv) }
29
+
30
+ context 'without --output-file option' do
31
+ let(:runner_argv) { [stub_text] }
32
+
33
+ it do
34
+ expect { instance.run }.to output(stub_text).to_stdout_from_any_process
35
+ end
36
+ end
37
+
38
+ context 'with --output-file option' do
39
+ let(:output_file) { ::EacRubyUtils::Fs::Temp.file }
40
+ let(:runner_argv) { ['--output-file', output_file.to_path, stub_text] }
41
+
42
+ before do
43
+ instance.run
44
+ end
45
+
46
+ after do
47
+ output_file.remove
48
+ end
49
+
50
+ it { expect(output_file).to exist }
51
+ it { expect(output_file.read).to eq(stub_text) }
52
+ end
53
+ end
@@ -29,10 +29,11 @@ module EacRubyUtils
29
29
 
30
30
  module ClassMethods
31
31
  def abstract_methods(*methods_names)
32
- @abstract_methods ||= Set.new
33
- @abstract_methods += methods_names.map(&:to_sym)
34
-
35
- @abstract_methods.to_enum
32
+ methods_names.each do |method_name|
33
+ define_method method_name do
34
+ raise_abstract_method(method_name)
35
+ end
36
+ end
36
37
  end
37
38
  end
38
39
 
@@ -61,6 +61,8 @@ module EacRubyUtils
61
61
  setup_class_attr_readers(klass)
62
62
  setup_class_attr_writers(klass)
63
63
  setup_class_initialize(klass)
64
+
65
+ klass
64
66
  end
65
67
 
66
68
  def setup_class_attr_readers(klass)
@@ -79,9 +81,14 @@ module EacRubyUtils
79
81
  klass.define_callbacks :initialize
80
82
  klass.send(:define_method, :initialize) do |*args|
81
83
  Initialize.new(common_constructor, args, self).run
84
+ super(*SuperArgs.new(common_constructor, args, self).result)
82
85
  end
83
86
  end
84
87
 
88
+ def super_args
89
+ options[:super_args]
90
+ end
91
+
85
92
  class Initialize
86
93
  attr_reader :common_constructor, :args, :object
87
94
 
@@ -129,5 +136,51 @@ module EacRubyUtils
129
136
  " (given #{args.count}, expected #{common_constructor.args_count})"
130
137
  end
131
138
  end
139
+
140
+ class SuperArgs
141
+ attr_reader :common_constructor, :args, :object
142
+
143
+ def initialize(common_constructor, args, object)
144
+ @common_constructor = common_constructor
145
+ @args = args
146
+ @object = object
147
+ end
148
+
149
+ def auto_result
150
+ r = []
151
+ sub_args.each do |name, value|
152
+ i = super_arg_index(name)
153
+ r[i] = value if i
154
+ end
155
+ r
156
+ end
157
+
158
+ def result
159
+ result_from_options || auto_result
160
+ end
161
+
162
+ def result_from_options
163
+ return unless common_constructor.super_args
164
+
165
+ object.instance_exec(&common_constructor.super_args)
166
+ end
167
+
168
+ def sub_args
169
+ common_constructor.args.each_with_index.map do |name, index|
170
+ [name, args[index]]
171
+ end.to_h
172
+ end
173
+
174
+ def super_arg_index(name)
175
+ super_method.parameters.each_with_index do |arg, index|
176
+ return index if arg[1] == name
177
+ end
178
+ nil
179
+ end
180
+
181
+ def super_method
182
+ object.class.superclass ? object.class.superclass.instance_method(:initialize) : nil
183
+ end
184
+ end
132
185
  end
133
186
  end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/abstract_methods'
4
+
5
+ class Module
6
+ def enable_abstract_methods(*methods)
7
+ include ::EacRubyUtils::AbstractMethods
8
+ abstract_methods(*methods)
9
+ end
10
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyUtils
4
- VERSION = '0.52.0'
4
+ VERSION = '0.54.0'
5
5
  end
@@ -3,34 +3,92 @@
3
3
  require 'eac_ruby_utils/common_constructor'
4
4
 
5
5
  RSpec.describe ::EacRubyUtils::CommonConstructor do
6
- ARG_LIST = %i[a b c d].freeze
6
+ ARG_LIST = %i[a b c d].freeze # rubocop:disable RSpec/LeakyConstantDeclaration
7
+
7
8
  let(:instance) do
8
9
  described_class.new(*ARG_LIST, default: %w[Vcc Vd]) do
9
10
  @z = 'Vz'
10
11
  end
11
12
  end
12
13
 
13
- class MyClass
14
- attr_reader :z
14
+ let(:a_class) do
15
+ ::Class.new do
16
+ attr_reader :z
17
+ end
15
18
  end
16
19
 
17
- let(:subject) { MyClass.new('Va', 'Vb', 'Vc') }
20
+ let(:a_class_instance) { a_class.new('Va', 'Vb', 'Vc') }
18
21
 
19
22
  before do
20
- instance.setup_class(::MyClass)
23
+ instance.setup_class(a_class)
21
24
  end
22
25
 
23
- it { expect(subject.z).to eq('Vz') }
26
+ it { expect(a_class_instance.z).to eq('Vz') }
24
27
 
25
28
  ARG_LIST.each do |attr|
26
29
  expected_value = "V#{attr}"
27
30
  it "attribute \"#{attr}\" equal to \"#{expected_value}\"" do
28
- expect(subject.send(attr)).to eq(expected_value)
31
+ expect(a_class_instance.send(attr)).to eq(expected_value)
29
32
  end
30
33
 
31
34
  [false, true].each do |include_all|
32
35
  it "respond_to?('#{attr}', #{include_all}) == #{include_all}" do
33
- expect(subject.respond_to?("#{attr}=", include_all)).to eq(include_all)
36
+ expect(a_class_instance.respond_to?("#{attr}=", include_all)).to eq(include_all)
37
+ end
38
+ end
39
+ end
40
+
41
+ context 'with super class' do
42
+ let(:super_class) do
43
+ ::Class.new do
44
+ attr_reader :super_a, :super_b
45
+
46
+ def initialize(a, b) # rubocop:disable Naming/MethodParameterName
47
+ @super_a = a
48
+ @super_b = b
49
+ end
50
+ end
51
+ end
52
+
53
+ let(:sub_class) do
54
+ sub_constructor.setup_class(::Class.new(super_class))
55
+ end
56
+
57
+ let(:sub_object) { sub_class.new(1, 2, 3, 4) }
58
+
59
+ context 'with super_args parameter' do
60
+ let(:sub_constructor) do
61
+ described_class.new(:c, :a, :b, :d, super_args: -> { [c, a] })
62
+ end
63
+
64
+ it { expect(sub_object.a).to eq(2) }
65
+ it { expect(sub_object.b).to eq(3) }
66
+ it { expect(sub_object.c).to eq(1) }
67
+ it { expect(sub_object.d).to eq(4) }
68
+ it { expect(sub_object.super_a).to eq(1) }
69
+ it { expect(sub_object.super_b).to eq(2) }
70
+ end
71
+
72
+ context 'without super_args parameter' do
73
+ let(:sub_constructor) do
74
+ described_class.new(:c, :a, :b, :d)
75
+ end
76
+
77
+ it { expect(sub_object.a).to eq(2) }
78
+ it { expect(sub_object.b).to eq(3) }
79
+ it { expect(sub_object.c).to eq(1) }
80
+ it { expect(sub_object.d).to eq(4) }
81
+ it { expect(sub_object.super_a).to eq(2) }
82
+ it { expect(sub_object.super_b).to eq(3) }
83
+ end
84
+
85
+ context 'with undefined super arguments' do
86
+ let(:sub_constructor) do
87
+ described_class.new(:x, :y, :w, :a)
88
+ end
89
+
90
+ it do
91
+ expect { sub_object }.to raise_error(::ArgumentError)
34
92
  end
35
93
  end
36
94
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avm-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.77.0
4
+ version: 0.78.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esquilo Azul Company
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-12-03 00:00:00.000000000 Z
11
+ date: 2020-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aranha-parsers
@@ -507,6 +507,7 @@ files:
507
507
  - lib/avm/tools/runner/git/revisions_test.rb
508
508
  - lib/avm/tools/runner/git/subrepo.rb
509
509
  - lib/avm/tools/runner/git/subrepo/check.rb
510
+ - lib/avm/tools/runner/git/subrepo/clone.rb
510
511
  - lib/avm/tools/runner/instance.rb
511
512
  - lib/avm/tools/runner/instance/info.rb
512
513
  - lib/avm/tools/runner/launcher.rb
@@ -629,6 +630,7 @@ files:
629
630
  - vendor/eac_cli/spec/lib/eac_cli/docopt/runner_extension_spec.rb
630
631
  - vendor/eac_cli/spec/lib/eac_cli/parser/alternative_spec.rb
631
632
  - vendor/eac_cli/spec/lib/eac_cli/runner_spec.rb
633
+ - vendor/eac_cli/spec/lib/eac_cli/runner_with/output_file_spec.rb
632
634
  - vendor/eac_cli/spec/lib/eac_cli/runner_with/subcommands_spec.rb
633
635
  - vendor/eac_cli/spec/rubocop_spec.rb
634
636
  - vendor/eac_cli/spec/spec_helper.rb
@@ -980,6 +982,7 @@ files:
980
982
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/hash/options_consumer.rb
981
983
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/hash/sym_keys_hash.rb
982
984
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module.rb
985
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/abstract_methods.rb
983
986
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/common_concern.rb
984
987
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/console_speaker.rb
985
988
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/immutable.rb