avm-tools 0.70.0 → 0.73.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/lib/avm/data/instance/files_unit.rb +1 -0
  3. data/lib/avm/eac_rails_base0/instance.rb +2 -2
  4. data/lib/avm/eac_redmine_base0/instance.rb +2 -2
  5. data/lib/avm/git/auto_commit_path.rb +4 -2
  6. data/lib/avm/instances/application.rb +4 -0
  7. data/lib/avm/instances/base.rb +2 -1
  8. data/lib/avm/instances/base/auto_values.rb +2 -1
  9. data/lib/avm/instances/base/auto_values/access.rb +5 -4
  10. data/lib/avm/instances/base/auto_values/admin.rb +2 -2
  11. data/lib/avm/instances/base/auto_values/database.rb +1 -1
  12. data/lib/avm/instances/base/auto_values/filesystem.rb +6 -2
  13. data/lib/avm/instances/base/auto_values/mailer.rb +34 -0
  14. data/lib/avm/instances/base/auto_values/ruby.rb +1 -1
  15. data/lib/avm/instances/base/auto_values/system.rb +2 -2
  16. data/lib/avm/instances/entry.rb +7 -1
  17. data/lib/avm/instances/entry_keys.rb +42 -7
  18. data/lib/avm/patches/i18n.rb +1 -1
  19. data/lib/avm/patches/object/template.rb +1 -1
  20. data/lib/avm/rails/instance.rb +19 -0
  21. data/lib/avm/self.rb +0 -4
  22. data/lib/avm/self/root.rb +13 -0
  23. data/lib/avm/tools/runner/eac_rails_base0/rails_server.rb +41 -0
  24. data/lib/avm/tools/runner/instance.rb +28 -0
  25. data/lib/avm/tools/runner/instance/info.rb +44 -0
  26. data/lib/avm/tools/version.rb +1 -1
  27. data/template/avm/eac_rails_base0/deploy/config/envvars.d/email.yml.template +11 -0
  28. data/vendor/eac_cli/lib/eac_cli/runner.rb +1 -1
  29. data/vendor/eac_cli/lib/eac_cli/runner/context.rb +19 -2
  30. data/vendor/eac_cli/lib/eac_cli/version.rb +1 -1
  31. data/vendor/eac_ruby_base0/lib/eac_ruby_base0/runner.rb +12 -0
  32. data/vendor/eac_ruby_base0/lib/eac_ruby_base0/version.rb +1 -1
  33. data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/gem.rb +2 -1
  34. data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/gem/command.rb +1 -1
  35. data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/tests/multiple/decorated_gem.rb +10 -6
  36. data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/version.rb +1 -1
  37. data/vendor/eac_ruby_gems_utils/spec/{rubocop_check_spec.rb → code/rubocop_check_spec.rb} +0 -0
  38. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/blank_not_blank.rb +19 -0
  39. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/configs/base.rb +43 -0
  40. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/configs/file.rb +12 -31
  41. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs.rb +4 -1
  42. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash.rb +21 -58
  43. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash/entry_key_error.rb +8 -0
  44. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash/node.rb +67 -0
  45. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash/path_search.rb +39 -0
  46. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/ruby/command.rb +2 -1
  47. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
  48. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/blank_not_blank_spec.rb +16 -0
  49. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/configs_spec.rb +15 -0
  50. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/paths_hash_spec.rb +52 -13
  51. metadata +16 -4
  52. data/lib/avm/stereotypes/rails/instance.rb +0 -20
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/instances/entry_keys'
4
+ require 'eac_cli/core_ext'
5
+ require 'eac_ruby_utils/console/docopt_runner'
6
+
7
+ module Avm
8
+ module Tools
9
+ class Runner < ::EacRubyUtils::Console::DocoptRunner
10
+ class Instance < ::EacRubyUtils::Console::DocoptRunner
11
+ class Info < ::EacRubyUtils::Console::DocoptRunner
12
+ runner_with
13
+
14
+ runner_definition do
15
+ desc 'Show info about a instance.'
16
+ end
17
+
18
+ def run
19
+ base_banner
20
+ entry_keys_banner
21
+ end
22
+
23
+ private
24
+
25
+ def base_banner
26
+ infov 'ID', instance.id
27
+ infov 'Application ID', instance.application.id
28
+ infov 'Suffix', instance.suffix
29
+ end
30
+
31
+ def entry_keys_banner
32
+ ::Avm::Instances::EntryKeys.all.each do |key|
33
+ infov key, instance.read_entry_optional(key)
34
+ end
35
+ end
36
+
37
+ def instance
38
+ context(:instance)
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Avm
4
4
  module Tools
5
- VERSION = '0.70.0'
5
+ VERSION = '0.73.0'
6
6
  end
7
7
  end
@@ -0,0 +1,11 @@
1
+ ---
2
+ action_mailer_smtp_address: '%%MAILER.SMTP.ADDRESS%%'
3
+ action_mailer_smtp_port: '%%MAILER.SMTP.PORT%%'
4
+ action_mailer_smtp_domain: '%%MAILER.SMTP.DOMAIN%%'
5
+ action_mailer_smtp_username: '%%MAILER.SMTP.USERNAME%%'
6
+ action_mailer_smtp_password: '%%MAILER.SMTP.PASSWORD%%'
7
+ action_mailer_smtp_authentication: '%%MAILER.SMTP.AUTHENTICATION%%'
8
+ action_mailer_smtp_enable_starttls_auto: '%%MAILER.SMTP.STARTTLS_AUTO%%'
9
+ action_mailer_default_options_from: '%%MAILER.FROM%%'
10
+ action_mailer_default_options_reply_to: '%%MAILER.REPLY_TO%%'
11
+ action_mailer_default_url_host: '%%WEB.URL%%'
@@ -45,7 +45,7 @@ module EacCli
45
45
  module AfterClassMethods
46
46
  def create(*runner_context_args)
47
47
  r = new
48
- r.runner_context = ::EacCli::Runner::Context.new(*runner_context_args)
48
+ r.runner_context = ::EacCli::Runner::Context.new(r, *runner_context_args)
49
49
  r
50
50
  end
51
51
 
@@ -5,13 +5,30 @@ require 'eac_ruby_utils/core_ext'
5
5
  module EacCli
6
6
  module Runner
7
7
  class Context
8
- attr_reader :argv, :parent, :program_name
8
+ attr_reader :argv, :parent, :program_name, :runner
9
9
 
10
- def initialize(*context_args)
10
+ def initialize(runner, *context_args)
11
11
  options = context_args.extract_options!
12
12
  @argv = (context_args[0] || options.delete(:argv) || ARGV).dup.freeze
13
13
  @parent = context_args[1] || options.delete(:parent)
14
14
  @program_name = options.delete(:program_name)
15
+ @runner = runner
16
+ end
17
+
18
+ # Call a method in the runner or in one of it ancestors.
19
+ def call(method_name, *args)
20
+ return runner.send(method_name, *args) if runner.respond_to?(method_name)
21
+ return parent_call(method_name, *args) if parent.present?
22
+
23
+ raise ::NameError, "No method \"#{method_name}\" found in #{runner} or in its ancestors"
24
+ end
25
+
26
+ protected
27
+
28
+ def parent_call(method_name, *args)
29
+ return parent.context(method_name, *args) if parent.respond_to?(:context)
30
+
31
+ parent.runner_context.call(method_name, *args)
15
32
  end
16
33
  end
17
34
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacCli
4
- VERSION = '0.8.0'
4
+ VERSION = '0.9.0'
5
5
  end
@@ -10,6 +10,7 @@ module EacRubyBase0
10
10
  include ::EacCli::DefaultRunner
11
11
  runner_definition do
12
12
  bool_opt '-q', '--quiet', 'Quiet mode.'
13
+ bool_opt '-I', '--no-input', 'Fail if a input is requested.'
13
14
  subcommands
14
15
  alt do
15
16
  bool_opt '-V', '--version', 'Show version.'
@@ -20,6 +21,7 @@ module EacRubyBase0
20
21
  def run
21
22
  on_speaker_node do |node|
22
23
  node.stderr = ::StringIO.new if options.fetch('--quiet')
24
+ node.stdin = FailIfRequestInput.new if options.fetch('--no-input')
23
25
  if options.fetch('--version')
24
26
  show_version
25
27
  else
@@ -35,5 +37,15 @@ module EacRubyBase0
35
37
  def show_version
36
38
  out("#{application_version}\n")
37
39
  end
40
+
41
+ class FailIfRequestInput
42
+ enable_console_speaker
43
+
44
+ %w[gets noecho].each do |method|
45
+ define_method(method) do
46
+ raise "Input method requested (\"#{method}\") and option --no-input is set"
47
+ end
48
+ end
49
+ end
38
50
  end
39
51
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyBase0
4
- VERSION = '0.1.1'
4
+ VERSION = '0.2.0'
5
5
  end
@@ -11,8 +11,9 @@ module EacRubyGemsUtils
11
11
 
12
12
  GEMSPEC_EXTNAME = '.gemspec'
13
13
 
14
- common_constructor :root do
14
+ common_constructor :root, :host_env, default: [nil] do
15
15
  @root = ::Pathname.new(root).expand_path
16
+ self.host_env ||= ::EacRubyUtils::Envs.local
16
17
  end
17
18
 
18
19
  def to_s
@@ -11,7 +11,7 @@ module EacRubyGemsUtils
11
11
 
12
12
  def initialize(gem, command_args, extra_options = {})
13
13
  @gem = gem
14
- super(command_args, extra_options)
14
+ super(command_args, extra_options.merge(host_env: gem.host_env))
15
15
  end
16
16
 
17
17
  # Changes current directory to the gem's directory.
@@ -12,14 +12,12 @@ module EacRubyGemsUtils
12
12
  log('running "bundle install"...')
13
13
  return if bundle('install').execute.fetch(:exit_code).zero?
14
14
 
15
- if can_remove_gemfile_lock?
16
- log('"bundle install" failed, removing Gemfile.lock and trying again...')
17
- gemfile_lock_path.unlink if gemfile_lock_path.exist?
18
- bundle('install').execute!
19
- else
15
+ unless can_remove_gemfile_lock?
20
16
  raise '"bundle install" failed and the Gemfile.lock is part of gem' \
21
- '(Should be changed by developer)'
17
+ '(Should be changed by developer)'
22
18
  end
19
+
20
+ prepare_with_removable_gemfile_lock
23
21
  end
24
22
 
25
23
  def tests
@@ -33,6 +31,12 @@ module EacRubyGemsUtils
33
31
  infov self, message
34
32
  end
35
33
 
34
+ def prepare_with_removable_gemfile_lock
35
+ log('"bundle install" failed, removing Gemfile.lock and trying again...')
36
+ gemfile_lock_path.unlink if gemfile_lock_path.exist?
37
+ bundle('install').execute!
38
+ end
39
+
36
40
  def can_remove_gemfile_lock?
37
41
  !files.include?(gemfile_lock_path.relative_path_from(root))
38
42
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyGemsUtils
4
- VERSION = '0.7.2'
4
+ VERSION = '0.8.0'
5
5
  end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/core_ext/object/blank'
4
+ require 'singleton'
5
+
6
+ module EacRubyUtils
7
+ # A blank string which returns +false+ for +blank?+ method.
8
+ class BlankNotBlank < String
9
+ include ::Singleton
10
+
11
+ def initialize
12
+ super('')
13
+ end
14
+
15
+ def blank?
16
+ false
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/blank_not_blank'
4
+ require 'eac_ruby_utils/core_ext'
5
+ require 'eac_ruby_utils/paths_hash'
6
+
7
+ module EacRubyUtils
8
+ class Configs
9
+ class Base
10
+ enable_simple_cache
11
+
12
+ common_constructor :data, default: [{}] do
13
+ self.data = ::EacRubyUtils::PathsHash.new(data)
14
+ end
15
+
16
+ def []=(entry_key, entry_value)
17
+ write(entry_key, entry_value)
18
+ end
19
+
20
+ def [](entry_key)
21
+ read(entry_key)
22
+ end
23
+
24
+ def clear
25
+ replace({})
26
+ end
27
+
28
+ def read(entry_key)
29
+ return nil unless data.key?(entry_key)
30
+
31
+ data.fetch(entry_key).if_present(::EacRubyUtils::BlankNotBlank.instance)
32
+ end
33
+
34
+ def replace(new_data)
35
+ self.data = ::EacRubyUtils::PathsHash.new(new_data)
36
+ end
37
+
38
+ def write(entry_key, entry_value)
39
+ data[entry_key] = entry_value
40
+ end
41
+ end
42
+ end
43
+ end
@@ -1,27 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'active_support/core_ext/string'
3
+ require 'eac_ruby_utils/configs/base'
4
4
  require 'yaml'
5
- require 'eac_ruby_utils/patches/hash/sym_keys_hash'
6
- require 'eac_ruby_utils/paths_hash'
7
- require 'eac_ruby_utils/simple_cache'
8
5
 
9
6
  module EacRubyUtils
10
7
  class Configs
11
- class File
12
- include ::EacRubyUtils::SimpleCache
13
-
8
+ class File < ::EacRubyUtils::Configs::Base
14
9
  attr_reader :path, :options
15
10
 
16
11
  # Valid options: [:autosave]
17
12
  def initialize(path, options = {})
18
13
  @path = path
19
14
  @options = options.to_sym_keys_hash.freeze
20
- load
21
- end
22
-
23
- def clear
24
- self.data = ::EacRubyUtils::PathsHash.new({})
15
+ super(raw_data_from_file)
25
16
  end
26
17
 
27
18
  def save
@@ -30,37 +21,27 @@ module EacRubyUtils
30
21
  end
31
22
 
32
23
  def load
33
- self.data = if ::File.exist?(path) && ::File.size(path).positive?
34
- ::EacRubyUtils::PathsHash.new(YAML.load_file(path))
35
- else
36
- {}
37
- end
38
- end
39
-
40
- def []=(entry_key, entry_value)
41
- write(entry_key, entry_value)
24
+ replace(raw_data_from_file)
42
25
  end
43
26
 
44
27
  def write(entry_key, entry_value)
45
- data[entry_key] = entry_value
28
+ super
46
29
  save if autosave?
47
30
  end
48
31
 
49
- def [](entry_key)
50
- read(entry_key)
51
- end
52
-
53
- def read(entry_key)
54
- data[entry_key]
55
- end
56
-
57
32
  def autosave?
58
33
  options[:autosave] ? true : false
59
34
  end
60
35
 
61
36
  private
62
37
 
63
- attr_accessor :data
38
+ def raw_data_from_file
39
+ if ::File.exist?(path) && ::File.size(path).positive?
40
+ ::YAML.load_file(path)
41
+ else
42
+ {}
43
+ end
44
+ end
64
45
  end
65
46
  end
66
47
  end
@@ -66,7 +66,10 @@ module EacRubyUtils
66
66
  protected
67
67
 
68
68
  def envvar_read_entry(entry_key)
69
- ENV[self.class.entry_key_to_envvar_name(entry_key)]
69
+ env_entry_key = self.class.entry_key_to_envvar_name(entry_key)
70
+ return nil unless ENV.key?(env_entry_key)
71
+
72
+ ENV.fetch(env_entry_key).if_present(::EacRubyUtils::BlankNotBlank.instance)
70
73
  end
71
74
 
72
75
  def read_entry_from_console(entry_key, options)
@@ -1,21 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'active_support/core_ext/object'
4
- require 'eac_ruby_utils/patches/object/asserts'
3
+ require 'eac_ruby_utils/core_ext'
5
4
 
6
5
  module EacRubyUtils
7
6
  class PathsHash
7
+ require_sub __FILE__
8
+
8
9
  class << self
9
10
  def parse_entry_key(entry_key)
10
11
  r = entry_key.to_s.strip
11
- raise EntryKeyError, 'Entry key cannot start or end with dot' if
12
+ raise ::EacRubyUtils::PathsHash::EntryKeyError, 'Entry key cannot start or end with dot' if
12
13
  r.start_with?('.') || r.end_with?('.')
13
14
 
14
15
  r = r.split('.').map(&:strip)
15
- raise EntryKeyError, "Entry key \"#{entry_key}\" is empty" if r.empty?
16
+ if r.empty?
17
+ raise ::EacRubyUtils::PathsHash::EntryKeyError, "Entry key \"#{entry_key}\" is empty"
18
+ end
16
19
  return r.map(&:to_sym) unless r.any?(&:blank?)
17
20
 
18
- raise EntryKeyError, "Entry key \"#{entry_key}\" has at least one blank part"
21
+ raise ::EacRubyUtils::PathsHash::EntryKeyError,
22
+ "Entry key \"#{entry_key}\" has at least one blank part"
19
23
  end
20
24
  end
21
25
 
@@ -26,68 +30,27 @@ module EacRubyUtils
26
30
  end
27
31
 
28
32
  def [](entry_key)
29
- root.read_entry(self.class.parse_entry_key(entry_key), [])
33
+ root.read_entry(::EacRubyUtils::PathsHash::PathSearch.parse_entry_key(entry_key))
30
34
  end
31
35
 
32
36
  def []=(entry_key, entry_value)
33
- root.write_entry(self.class.parse_entry_key(entry_key), entry_value, [])
37
+ root.write_entry(
38
+ ::EacRubyUtils::PathsHash::PathSearch.parse_entry_key(entry_key), entry_value
39
+ )
34
40
  end
35
41
 
36
- delegate :to_h, to: :root
37
-
38
- private
39
-
40
- attr_reader :data
41
-
42
- class EntryKeyError < StandardError
42
+ def fetch(entry_key)
43
+ root.fetch(::EacRubyUtils::PathsHash::PathSearch.parse_entry_key(entry_key))
43
44
  end
44
45
 
45
- class Node
46
- def initialize(source_hash)
47
- source_hash.assert_argument(Hash, 'source_hash')
48
- @data = source_hash.map { |k, v| [k.to_sym, v.is_a?(Hash) ? Node.new(v) : v] }.to_h
49
- end
50
-
51
- def to_h
52
- data.map { |k, v| [k, v.is_a?(Node) ? v.to_h : v] }.to_h
53
- end
54
-
55
- def read_entry(path, current)
56
- validate_path(path, current)
57
- node_key = path.shift
58
- node = data[node_key]
59
- return (node.is_a?(Node) ? node.to_h : node) if path.empty?
60
- return nil if node.blank?
61
- return node.read_entry(path, current + [node_key]) if node.is_a?(Node)
62
-
63
- raise(EntryKeyError,
64
- "Path #{current.join(',')} is not a Node and path continues (#{current + path})")
65
- end
66
-
67
- def write_entry(path, value, current)
68
- validate_path(path, current)
69
- node_key = path.shift
70
- write_entry_value(path, node_key, value, current)
71
- end
72
-
73
- private
46
+ def key?(entry_key)
47
+ root.entry?(::EacRubyUtils::PathsHash::PathSearch.parse_entry_key(entry_key))
48
+ end
74
49
 
75
- def write_entry_value(path, node_key, value, current)
76
- if path.empty?
77
- data[node_key] = value.is_a?(Hash) ? Node.new(value) : value
78
- else
79
- data[node_key] = Node.new({}) unless data[node_key].is_a?(Node)
80
- data[node_key].write_entry(path, value, current + [node_key])
81
- end
82
- end
50
+ delegate :to_h, to: :root
83
51
 
84
- def validate_path(path, current)
85
- path.assert_argument(Array, 'path')
86
- current.assert_argument(Array, 'current')
87
- raise EntryKeyError, 'Path is empty' if path.empty?
88
- end
52
+ private
89
53
 
90
- attr_reader :data
91
- end
54
+ attr_reader :data
92
55
  end
93
56
  end