avm-tools 0.64.2 → 0.69.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. checksums.yaml +4 -4
  2. data/lib/avm/eac_rails_base0/apache_host.rb +17 -0
  3. data/lib/avm/eac_rails_base0/deploy.rb +50 -0
  4. data/lib/avm/eac_rails_base0/instance.rb +14 -0
  5. data/lib/avm/eac_redmine_base0/deploy.rb +2 -2
  6. data/lib/avm/eac_redmine_base0/instance.rb +2 -2
  7. data/lib/avm/eac_webapp_base0/apache_host.rb +103 -0
  8. data/lib/avm/eac_webapp_base0/deploy.rb +102 -0
  9. data/lib/avm/eac_webapp_base0/deploy/appended_directories.rb +25 -0
  10. data/lib/avm/eac_webapp_base0/deploy/file_unit.rb +41 -0
  11. data/lib/avm/eac_webapp_base0/deploy/git_info.rb +49 -0
  12. data/lib/avm/eac_webapp_base0/deploy/version.rb +20 -0
  13. data/lib/avm/eac_webapp_base0/instance.rb +50 -0
  14. data/lib/avm/eac_webapp_base0/runner/apache_host.rb +39 -0
  15. data/lib/avm/eac_webapp_base0/runner/data.rb +25 -0
  16. data/lib/avm/eac_webapp_base0/runner/data/dump.rb +69 -0
  17. data/lib/avm/eac_webapp_base0/runner/data/load.rb +66 -0
  18. data/lib/avm/eac_webapp_base0/runner/deploy.rb +59 -0
  19. data/lib/avm/instances/configuration/_locale.rb +16 -0
  20. data/lib/avm/local_projects/instance.rb +28 -1
  21. data/lib/avm/patches/i18n.rb +22 -0
  22. data/lib/avm/patches/object/i18n.rb +17 -0
  23. data/lib/avm/patches/object/template.rb +3 -3
  24. data/lib/avm/projects/stereotype.rb +3 -2
  25. data/lib/avm/projects/stereotypes/git_subrepo/warp.rb +2 -2
  26. data/lib/avm/projects/stereotypes/rails_application.rb +2 -0
  27. data/lib/avm/projects/stereotypes/rails_application/local_project_mixin.rb +18 -0
  28. data/lib/avm/projects/stereotypes/rails_application/update.rb +14 -0
  29. data/lib/avm/projects/stereotypes/ruby_gem/local_project_mixin.rb +9 -0
  30. data/lib/avm/projects/stereotypes/ruby_gem/version_bump.rb +61 -0
  31. data/lib/avm/self.rb +5 -1
  32. data/lib/avm/stereotypes/eac_wordpress_base0/apache_host.rb +2 -2
  33. data/lib/avm/stereotypes/eac_wordpress_base0/deploy.rb +2 -2
  34. data/lib/avm/stereotypes/eac_wordpress_base0/instance.rb +2 -2
  35. data/lib/avm/tools/runner/eac_rails_base0.rb +2 -2
  36. data/lib/avm/tools/runner/eac_rails_base0/apache_host.rb +3 -26
  37. data/lib/avm/tools/runner/eac_rails_base0/data.rb +2 -2
  38. data/lib/avm/tools/runner/eac_rails_base0/deploy.rb +3 -3
  39. data/lib/avm/tools/runner/eac_redmine_base0/data.rb +1 -1
  40. data/lib/avm/tools/runner/eac_redmine_base0/data/dump.rb +2 -2
  41. data/lib/avm/tools/runner/eac_redmine_base0/deploy.rb +2 -2
  42. data/lib/avm/tools/runner/eac_redmine_base0/project_rename.rb +1 -0
  43. data/lib/avm/tools/runner/eac_wordpress_base0/apache_host.rb +3 -25
  44. data/lib/avm/tools/runner/eac_wordpress_base0/data.rb +2 -2
  45. data/lib/avm/tools/runner/eac_wordpress_base0/deploy.rb +2 -2
  46. data/lib/avm/tools/runner/local_project.rb +5 -0
  47. data/lib/avm/tools/runner/local_project/ruby.rb +24 -0
  48. data/lib/avm/tools/runner/local_project/ruby/bundler.rb +25 -0
  49. data/lib/avm/tools/runner/local_project/ruby/bundler/gemfile_lock.rb +138 -0
  50. data/lib/avm/tools/runner/local_project/test.rb +34 -0
  51. data/lib/avm/tools/runner/local_project/update.rb +1 -2
  52. data/lib/avm/tools/runner/local_project/version_bump.rb +89 -0
  53. data/lib/avm/tools/version.rb +1 -1
  54. data/lib/avm/version.rb +45 -0
  55. data/lib/eac_launcher/git/sub_warp_base.rb +1 -1
  56. data/lib/eac_launcher/publish/base.rb +1 -1
  57. data/template/avm/{stereotypes/eac_rails_base0 → eac_rails_base0}/deploy/config/database.yml.template +0 -0
  58. data/template/avm/{stereotypes/eac_webapp_base0 → eac_webapp_base0}/apache_host/no_ssl.conf +0 -0
  59. data/vendor/eac_cli/Gemfile +5 -0
  60. data/vendor/eac_cli/eac_cli.gemspec +18 -0
  61. data/vendor/eac_cli/lib/eac_cli.rb +7 -0
  62. data/vendor/eac_cli/lib/eac_cli/default_runner.rb +22 -0
  63. data/vendor/eac_cli/lib/eac_cli/definition.rb +72 -0
  64. data/vendor/eac_cli/lib/eac_cli/definition/argument_option.rb +13 -0
  65. data/vendor/eac_cli/lib/eac_cli/definition/base_option.rb +26 -0
  66. data/vendor/eac_cli/lib/eac_cli/definition/boolean_option.rb +13 -0
  67. data/vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb +27 -0
  68. data/vendor/eac_cli/lib/eac_cli/docopt/doc_builder.rb +77 -0
  69. data/vendor/eac_cli/lib/eac_cli/docopt/runner_extension.rb +45 -0
  70. data/vendor/eac_cli/lib/eac_cli/parser.rb +14 -0
  71. data/vendor/eac_cli/lib/eac_cli/parser/collector.rb +56 -0
  72. data/vendor/eac_cli/lib/eac_cli/parser/error.rb +15 -0
  73. data/vendor/eac_cli/lib/eac_cli/parser/options_collection.rb +105 -0
  74. data/vendor/eac_cli/lib/eac_cli/parser/parse_result.rb +21 -0
  75. data/vendor/eac_cli/lib/eac_cli/parser/positional_collection.rb +49 -0
  76. data/vendor/eac_cli/lib/eac_cli/runner.rb +87 -0
  77. data/vendor/eac_cli/lib/eac_cli/runner/context.rb +18 -0
  78. data/vendor/eac_cli/lib/eac_cli/version.rb +5 -0
  79. data/vendor/eac_cli/spec/lib/eac_cli/runner_spec.rb +70 -0
  80. data/vendor/eac_cli/spec/rubocop_spec.rb +7 -0
  81. data/vendor/eac_cli/spec/spec_helper.rb +100 -0
  82. data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/gem.rb +15 -1
  83. data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/gem/version_file.rb +40 -0
  84. data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/tests/multiple.rb +5 -34
  85. data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/tests/multiple/decorated_gem.rb +42 -0
  86. data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/tests/multiple/result.rb +25 -0
  87. data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/version.rb +1 -1
  88. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern.rb +4 -4
  89. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner.rb +6 -0
  90. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner/_class_methods.rb +1 -1
  91. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner/_subcommands.rb +8 -2
  92. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/inflector.rb +18 -0
  93. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/value.rb +3 -2
  94. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_respond.rb +22 -0
  95. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/string.rb +4 -0
  96. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/string/inflector.rb +9 -0
  97. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/struct.rb +47 -0
  98. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
  99. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/inflector_spec.rb +15 -0
  100. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/struct_spec.rb +46 -0
  101. metadata +64 -19
  102. data/lib/avm/local_projects/jobs/update.rb +0 -29
  103. data/lib/avm/stereotypes/eac_rails_base0/apache_host.rb +0 -19
  104. data/lib/avm/stereotypes/eac_rails_base0/deploy.rb +0 -52
  105. data/lib/avm/stereotypes/eac_rails_base0/instance.rb +0 -16
  106. data/lib/avm/stereotypes/eac_webapp_base0/apache_host.rb +0 -97
  107. data/lib/avm/stereotypes/eac_webapp_base0/deploy.rb +0 -104
  108. data/lib/avm/stereotypes/eac_webapp_base0/deploy/appended_directories.rb +0 -27
  109. data/lib/avm/stereotypes/eac_webapp_base0/deploy/file_unit.rb +0 -43
  110. data/lib/avm/stereotypes/eac_webapp_base0/deploy/git_info.rb +0 -51
  111. data/lib/avm/stereotypes/eac_webapp_base0/deploy/version.rb +0 -22
  112. data/lib/avm/stereotypes/eac_webapp_base0/instance.rb +0 -52
  113. data/lib/avm/stereotypes/eac_webapp_base0/runner/data.rb +0 -27
  114. data/lib/avm/stereotypes/eac_webapp_base0/runner/data/dump.rb +0 -71
  115. data/lib/avm/stereotypes/eac_webapp_base0/runner/data/load.rb +0 -68
  116. data/lib/avm/stereotypes/eac_webapp_base0/runner/deploy.rb +0 -61
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacCli
6
+ class Parser
7
+ class ParseResult
8
+ common_constructor :definition, :argv
9
+
10
+ def result
11
+ ::EacCli::Parser::Collector.to_data(definition) do |collector|
12
+ ::EacCli::Parser::PositionalCollection.new(
13
+ definition,
14
+ ::EacCli::Parser::OptionsCollection.new(definition, argv, collector).arguments,
15
+ collector
16
+ )
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'eac_cli/parser/error'
5
+
6
+ module EacCli
7
+ class Parser
8
+ class PositionalCollection
9
+ common_constructor(:definition, :argv, :collector) { collect }
10
+
11
+ private
12
+
13
+ def collected
14
+ @collected ||= ::Set.new
15
+ end
16
+
17
+ def collect
18
+ argv.each { |argv_value| colect_argv_value(argv_value) }
19
+ return unless pending_required_positional?
20
+
21
+ raise ::EacCli::Parser::Error.new(
22
+ definition, argv, 'No value for required positional ' \
23
+ "\"#{current_positional.identifier}\""
24
+ )
25
+ end
26
+
27
+ def colect_argv_value(argv_value)
28
+ collector.collect(current_positional, argv_value)
29
+ collected << current_positional
30
+ positional_enumerator.next unless current_positional.repeat?
31
+ end
32
+
33
+ def pending_required_positional?
34
+ !(current_positional.blank? || current_positional.optional? ||
35
+ collected.include?(current_positional))
36
+ end
37
+
38
+ def positional_enumerator
39
+ @positional_enumerator ||= definition.positional.each
40
+ end
41
+
42
+ def current_positional
43
+ positional_enumerator.peek
44
+ rescue ::StopIteration
45
+ nil
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/definition'
4
+ require 'eac_cli/docopt/runner_extension'
5
+ require 'eac_cli/parser'
6
+ require 'eac_ruby_utils/core_ext'
7
+
8
+ module EacCli
9
+ module Runner
10
+ require_sub __FILE__
11
+ extend ::ActiveSupport::Concern
12
+
13
+ class << self
14
+ def alias_runner_class_methods(klass, from_suffix, to_suffix)
15
+ %i[create run].each do |method|
16
+ alias_class_method(klass, build_method_name(method, from_suffix),
17
+ build_method_name(method, to_suffix))
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def alias_class_method(klass, from, to)
24
+ sklass = klass.singleton_class
25
+ return unless sklass.method_defined?(from)
26
+
27
+ sklass.alias_method to, from
28
+ end
29
+
30
+ def build_method_name(name, suffix)
31
+ ss = suffix.if_present('') { |s| "#{s}_" }
32
+ "#{ss}#{name}"
33
+ end
34
+ end
35
+
36
+ the_module = self
37
+ included do
38
+ the_module.alias_runner_class_methods(self, '', 'original')
39
+
40
+ extend AfterClassMethods
41
+ include InstanceMethods
42
+ ::EacCli::Docopt::RunnerExtension.check(self)
43
+ end
44
+
45
+ module AfterClassMethods
46
+ def create(*runner_context_args)
47
+ r = new
48
+ r.runner_context = ::EacCli::Runner::Context.new(*runner_context_args)
49
+ r
50
+ end
51
+
52
+ def run(*runner_context_args)
53
+ r = create(*runner_context_args)
54
+ r.parsed
55
+ r.run
56
+ r
57
+ end
58
+
59
+ def runner_definition(&block)
60
+ @runner_definition ||= super_runner_definition
61
+ @runner_definition.instance_eval(&block) if block
62
+ @runner_definition
63
+ end
64
+
65
+ def super_runner_definition
66
+ superclass.try(:runner_definition).if_present(&:dup) || ::EacCli::Definition.new
67
+ end
68
+ end
69
+
70
+ module InstanceMethods
71
+ def runner_context
72
+ return @runner_context if @runner_context
73
+
74
+ raise 'Context was required, but was not set yet'
75
+ end
76
+
77
+ def runner_context=(new_runner_context)
78
+ @runner_context = new_runner_context
79
+ @parsed = nil
80
+ end
81
+
82
+ def parsed
83
+ @parsed ||= ::EacCli::Parser.new(self.class.runner_definition).parse(runner_context.argv)
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacCli
6
+ module Runner
7
+ class Context
8
+ attr_reader :argv, :parent, :program_name
9
+
10
+ def initialize(*context_args)
11
+ options = context_args.extract_options!
12
+ @argv = (context_args[0] || options.delete(:argv) || ARGV).dup.freeze
13
+ @parent = context_args[1] || options.delete(:parent)
14
+ @program_name = options.delete(:program_name)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacCli
4
+ VERSION = '0.6.1'
5
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/console/docopt_runner'
4
+ require 'eac_cli/runner'
5
+
6
+ RSpec.describe ::EacCli::Runner do
7
+ let(:stub_runner) do
8
+ r = Class.new(::EacRubyUtils::Console::DocoptRunner) do
9
+ def run; end
10
+ end
11
+ r.include described_class
12
+ r.runner_definition do
13
+ desc 'A stub runner.'
14
+ arg_opt '-o', '--opt1', 'A argument option'
15
+ pos_arg 'pos1'
16
+ end
17
+ r
18
+ end
19
+
20
+ let(:instance) { stub_runner.new(argv: %w[-o aaa bbb]) }
21
+
22
+ before { instance.run }
23
+
24
+ it { expect(instance.options.fetch('--opt1')).to eq('aaa') }
25
+ it { expect(instance.options.fetch('<pos1>')).to eq('bbb') }
26
+
27
+ context 'without docopt runner' do
28
+ let(:runner_class) do
29
+ the_module = described_class
30
+ ::Class.new do
31
+ include the_module
32
+
33
+ runner_definition do
34
+ arg_opt '-o', '--opt1', 'A arg option.'
35
+ bool_opt '-o', '--opt2', 'A boolean option'
36
+ pos_arg :pos1
37
+ pos_arg :pos2, repeat: true, optional: true
38
+ end
39
+
40
+ def run; end
41
+ end
42
+ end
43
+
44
+ context 'when all args are supplied' do
45
+ let(:instance) { runner_class.create(%w[--opt1 aaa --opt2 bbb ccc ddd]) }
46
+
47
+ it { expect(instance.parsed.opt1).to eq('aaa') }
48
+ it { expect(instance.parsed.opt2?).to eq(true) }
49
+ it { expect(instance.parsed.pos1).to eq('bbb') }
50
+ it { expect(instance.parsed.pos2).to eq(%w[ccc ddd]) }
51
+ end
52
+
53
+ context 'when only required args are supplied' do
54
+ let(:instance) { runner_class.create(%w[bbb]) }
55
+
56
+ it { expect(instance.parsed.opt1).to be_nil }
57
+ it { expect(instance.parsed.opt2?).to eq(false) }
58
+ it { expect(instance.parsed.pos1).to eq('bbb') }
59
+ it { expect(instance.parsed.pos2).to eq([]) }
60
+ end
61
+
62
+ context 'when required args are not supplied' do
63
+ let(:instance) { runner_class.create(%w[]) }
64
+
65
+ it do
66
+ expect { instance.parsed }.to raise_error(::EacCli::Parser::Error)
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_gem_support/spec/examples/rubocop_check'
4
+
5
+ RSpec.describe ::RuboCop, slow: true do
6
+ include_examples 'rubocop_check', ::File.expand_path('..', __dir__)
7
+ end
@@ -0,0 +1,100 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This file was generated by the `rspec --init` command. Conventionally, all
4
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
6
+ # this file to always be loaded, without a need to explicitly require it in any
7
+ # files.
8
+ #
9
+ # Given that it is always loaded, you are encouraged to keep this file as
10
+ # light-weight as possible. Requiring heavyweight dependencies from this file
11
+ # will add to the boot time of your test suite on EVERY test run, even for an
12
+ # individual file that may not need all of that loaded. Instead, consider making
13
+ # a separate helper file that requires the additional dependencies and performs
14
+ # the additional setup, and require it from the spec files that actually need
15
+ # it.
16
+ #
17
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
18
+ RSpec.configure do |config|
19
+ # rspec-expectations config goes here. You can use an alternate
20
+ # assertion/expectation library such as wrong or the stdlib/minitest
21
+ # assertions if you prefer.
22
+ config.expect_with :rspec do |expectations|
23
+ # This option will default to `true` in RSpec 4. It makes the `description`
24
+ # and `failure_message` of custom matchers include text for helper methods
25
+ # defined using `chain`, e.g.:
26
+ # be_bigger_than(2).and_smaller_than(4).description
27
+ # # => "be bigger than 2 and smaller than 4"
28
+ # ...rather than:
29
+ # # => "be bigger than 2"
30
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
31
+ end
32
+
33
+ # rspec-mocks config goes here. You can use an alternate test double
34
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
35
+ config.mock_with :rspec do |mocks|
36
+ # Prevents you from mocking or stubbing a method that does not exist on
37
+ # a real object. This is generally recommended, and will default to
38
+ # `true` in RSpec 4.
39
+ mocks.verify_partial_doubles = true
40
+ end
41
+
42
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
43
+ # have no way to turn it off -- the option exists only for backwards
44
+ # compatibility in RSpec 3). It causes shared context metadata to be
45
+ # inherited by the metadata hash of host groups and examples, rather than
46
+ # triggering implicit auto-inclusion in groups with matching metadata.
47
+ config.shared_context_metadata_behavior = :apply_to_host_groups
48
+
49
+ # The settings below are suggested to provide a good initial experience
50
+ # with RSpec, but feel free to customize to your heart's content.
51
+ # # This allows you to limit a spec run to individual examples or groups
52
+ # # you care about by tagging them with `:focus` metadata. When nothing
53
+ # # is tagged with `:focus`, all examples get run. RSpec also provides
54
+ # # aliases for `it`, `describe`, and `context` that include `:focus`
55
+ # # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
56
+ # config.filter_run_when_matching :focus
57
+ #
58
+ # # Allows RSpec to persist some state between runs in order to support
59
+ # # the `--only-failures` and `--next-failure` CLI options. We recommend
60
+ # # you configure your source control system to ignore this file.
61
+ # config.example_status_persistence_file_path = "spec/examples.txt"
62
+ #
63
+ # # Limits the available syntax to the non-monkey patched syntax that is
64
+ # # recommended. For more details, see:
65
+ # # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
66
+ # # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
67
+ # # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
68
+ # config.disable_monkey_patching!
69
+ #
70
+ # # This setting enables warnings. It's recommended, but in some cases may
71
+ # # be too noisy due to issues in dependencies.
72
+ # config.warnings = true
73
+ #
74
+ # # Many RSpec users commonly either run the entire suite or an individual
75
+ # # file, and it's useful to allow more verbose output when running an
76
+ # # individual spec file.
77
+ # if config.files_to_run.one?
78
+ # # Use the documentation formatter for detailed output,
79
+ # # unless a formatter has already been configured
80
+ # # (e.g. via a command-line flag).
81
+ # config.default_formatter = "doc"
82
+ # end
83
+ #
84
+ # # Print the 10 slowest examples and example groups at the
85
+ # # end of the spec run, to help surface which specs are running
86
+ # # particularly slow.
87
+ # config.profile_examples = 10
88
+ #
89
+ # # Run specs in random order to surface order dependencies. If you find an
90
+ # # order dependency and want to debug it, you can fix the order by providing
91
+ # # the seed, which is printed after each run.
92
+ # # --seed 1234
93
+ # config.order = :random
94
+ #
95
+ # # Seed global randomization in this process using the `--seed` CLI option.
96
+ # # Setting this allows you to use `--seed` to deterministically reproduce
97
+ # # test failures related to randomization by passing the same `--seed` value
98
+ # # as the one that triggered the failure.
99
+ # Kernel.srand config.seed
100
+ end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'eac_ruby_utils/core_ext'
4
4
  require 'eac_ruby_utils/envs'
5
+ require 'rubygems'
5
6
 
6
7
  module EacRubyGemsUtils
7
8
  class Gem
@@ -22,6 +23,11 @@ module EacRubyGemsUtils
22
23
  ::EacRubyGemsUtils::Gem::Command.new(self, %w[bundle] + args).envvar_gemfile
23
24
  end
24
25
 
26
+ # @return A [Pathname] array with relative paths from root listed in gemspec's .file directive.
27
+ def files
28
+ gemspec.files.map(&:to_pathname)
29
+ end
30
+
25
31
  def gemfile_lock_gem_version(gem_name)
26
32
  gemfile_lock_content.specs.find { |gem| gem.name == gem_name }.if_present(&:version)
27
33
  end
@@ -54,7 +60,7 @@ module EacRubyGemsUtils
54
60
  end
55
61
 
56
62
  def version
57
- /VERSION\s*=\s*[\'\"]([^\'\"]+)[\'\"]/.if_match(version_file.read) { |m| m[1] }
63
+ version_file.value
58
64
  end
59
65
 
60
66
  private
@@ -67,6 +73,10 @@ module EacRubyGemsUtils
67
73
  gemfile_path.basename_sub { |b| "#{b}.lock" }
68
74
  end
69
75
 
76
+ def gemspec_uncached
77
+ ::Gem::Specification.load(gemspec_path.to_path)
78
+ end
79
+
70
80
  def gemspec_path_uncached
71
81
  ::Pathname.glob("#{root.to_path}/*#{GEMSPEC_EXTNAME}").first
72
82
  end
@@ -76,6 +86,10 @@ module EacRubyGemsUtils
76
86
  end
77
87
 
78
88
  def version_file_uncached
89
+ ::EacRubyGemsUtils::Gem::VersionFile.new(version_file_path)
90
+ end
91
+
92
+ def version_file_path_uncached
79
93
  root.join('lib', *namespace_parts, 'version.rb')
80
94
  end
81
95
  end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacRubyGemsUtils
6
+ class Gem
7
+ class VersionFile
8
+ common_constructor :path
9
+
10
+ VERSION_LINE_PATTERN = /\A(\s*)VERSION\s*=\s*[\'\"]([^\'\"]+)[\'\"](\s*)\z/.freeze
11
+
12
+ def value
13
+ path.read.each_line do |line|
14
+ VERSION_LINE_PATTERN.if_match(line.rstrip, false) do |m|
15
+ ::Gem::Version.new(m[2])
16
+ end
17
+ end
18
+ end
19
+
20
+ def value=(new_value)
21
+ path.write(new_value_content(new_value))
22
+ end
23
+
24
+ private
25
+
26
+ def new_value_content(new_value)
27
+ path.read.each_line
28
+ .map { |line| new_value_line(line, new_value) }
29
+ .join
30
+ end
31
+
32
+ def new_value_line(line, new_value)
33
+ m = VERSION_LINE_PATTERN.match(line)
34
+ return line unless m
35
+
36
+ "#{m[1]}VERSION = '#{new_value}'#{m[3]}"
37
+ end
38
+ end
39
+ end
40
+ end