avm 0.44.0 → 0.46.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: 75da0735d17a4472beabdba8b1a848bd1df14e0e8b630885bbf2b1503d198e14
4
- data.tar.gz: 4d71ad19868decc5d8eebcd01b71a1a518702345a06521edb0c27f55bd25cca5
3
+ metadata.gz: 3de16327c43ae558d30a57324fcbaa23da1546da8110c4de0ba502003d6ac42c
4
+ data.tar.gz: 1bc7005ac83d1191579db59161d656fb4054e35f23c611a46c563df5351c6213
5
5
  SHA512:
6
- metadata.gz: 8e75c632a176c1f15431466cf0fe85c53fcbaccf5d914e643b7a5a51ef17bc8a41ea7c5b2d6253feb0587557d01d66a40b7073ac375115f7e07afe1ffa13d694
7
- data.tar.gz: d3c82791118497839cea0c53d9e8d838dedf1db1a7f462c022ea24d82411774f86db27b9e0e8d40b844a09ad6c2f918f0b23802f58f489e03490bc52f10d526f
6
+ metadata.gz: 893701096abafe979997222cce3150766e944369ad8cb089f4022acfe1673d4651529dfa9b63e8b585028c8cac2f1a394aba20627b8b1b37d73f3ee0b4089d34
7
+ data.tar.gz: 5c042ea77b1f9daf6b29ea86484ecf24b9ac4eef274eb4c1999a612ae8f92dc3173b3b492c62fb364bb76c89fd8c6406fc46104a8ec652e00803e1dc631ed4a5
@@ -8,15 +8,22 @@ module Avm
8
8
  module AutoValues
9
9
  class Entry
10
10
  class << self
11
- def auto_value_method_name(suffix)
12
- "auto_#{suffix.to_s.gsub('.', '_')}"
11
+ # @param path [EacConfig::EntryPath]
12
+ # @return String
13
+ def auto_value_method_name(path)
14
+ "auto_#{::EacConfig::EntryPath.assert(path).to_string.gsub('.', '_')}"
13
15
  end
14
16
  end
15
17
 
16
- common_constructor :entries_provider, :suffix
18
+ # @!method initialize(entries_provider, path)
19
+ # @param entries_provider
20
+ # @param path [EacConfig::EntryPath]
21
+ common_constructor :entries_provider, :path do
22
+ self.path = ::EacConfig::EntryPath.assert(path)
23
+ end
17
24
 
18
25
  def auto_value_method
19
- self.class.auto_value_method_name(suffix)
26
+ self.class.auto_value_method_name(path)
20
27
  end
21
28
 
22
29
  def found?
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/entries/jobs/with_variables_source'
4
+ require 'avm/result'
5
+ require 'eac_cli/core_ext'
6
+
7
+ module Avm
8
+ module Entries
9
+ module Jobs
10
+ module Base
11
+ common_concern do
12
+ include ::ActiveSupport::Callbacks
13
+ include ::Avm::Entries::Jobs::WithVariablesSource
14
+
15
+ enable_speaker
16
+ enable_simple_cache
17
+ enable_listable
18
+ common_constructor :instance, :options, default: [{}] do
19
+ if option_list.present?
20
+ self.options = option_list.hash_keys_validate!(options.symbolize_keys)
21
+ end
22
+ end
23
+ define_callbacks(*jobs)
24
+ end
25
+
26
+ module ClassMethods
27
+ def jobs
28
+ const_get('JOBS').dup
29
+ end
30
+ end
31
+
32
+ module InstanceMethods
33
+ def option_list
34
+ nil
35
+ end
36
+
37
+ def run
38
+ start_banner if respond_to?(:start_banner)
39
+ run_jobs
40
+ ::Avm::Result.success('Done!')
41
+ rescue ::Avm::Result::Error => e
42
+ e.to_result
43
+ end
44
+
45
+ protected
46
+
47
+ def run_jobs
48
+ jobs.each do |job|
49
+ run_callbacks job do
50
+ send(job)
51
+ end
52
+ end
53
+ end
54
+
55
+ def jobs
56
+ self.class.jobs
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module Entries
7
+ module Jobs
8
+ class VariablesSource
9
+ class ReadEntry
10
+ enable_method_class
11
+ common_constructor :variables_source, :path, :options, default: [{}]
12
+ delegate :instance, :job, to: :variables_source
13
+
14
+ def result
15
+ return result_from_job if result_from_job?
16
+ return result_from_instance_method if result_from_instance_method?
17
+
18
+ result_from_instance_entry
19
+ end
20
+
21
+ private
22
+
23
+ def path_method_name
24
+ path.gsub('.', '_').underscore
25
+ end
26
+
27
+ def result_from_instance_entry
28
+ instance.read_entry(path, options)
29
+ end
30
+
31
+ def result_from_instance_method
32
+ instance.send(path_method_name)
33
+ end
34
+
35
+ def result_from_instance_method?
36
+ instance.respond_to?(path_method_name, true)
37
+ end
38
+
39
+ def result_from_job
40
+ job.send(path_method_name)
41
+ end
42
+
43
+ def result_from_job?
44
+ job.respond_to?(path_method_name, true)
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module Entries
7
+ module Jobs
8
+ class VariablesSource
9
+ require_sub __FILE__, require_dependency: true
10
+ common_constructor :job
11
+ delegate :instance, to: :job
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/entries/jobs/variables_source'
4
+
5
+ module Avm
6
+ module Entries
7
+ module Jobs
8
+ module WithVariablesSource
9
+ def variables_source
10
+ ::Avm::Entries::Jobs::VariablesSource.new(self)
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -3,7 +3,9 @@
3
3
  require 'eac_ruby_utils/core_ext'
4
4
 
5
5
  module Avm
6
- module Jobs
7
- require_sub __FILE__
6
+ module Entries
7
+ module Jobs
8
+ require_sub __FILE__
9
+ end
8
10
  end
9
11
  end
@@ -13,7 +13,7 @@ module Avm
13
13
  end
14
14
 
15
15
  define_method "#{method_name}_optional" do
16
- read_entry(key, required: false)
16
+ read_entry_optional(key)
17
17
  end
18
18
  end
19
19
  end
@@ -35,7 +35,7 @@ module Avm
35
35
  '' => %w[id from reply_to],
36
36
  smtp: URI_FIELDS + %w[address domain authentication openssl_verify_mode starttls_auto tls]
37
37
  },
38
- web: URI_FIELDS + %w[authority userinfo]
38
+ web: URI_FIELDS
39
39
  }.each { |prefix, suffixes| keys_consts_set(prefix, suffixes) }
40
40
  end
41
41
  end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module Launcher
7
+ class Context
8
+ class InstanceCollector
9
+ common_constructor :context
10
+
11
+ def add_all
12
+ instances_set.merge(context.instances)
13
+ self
14
+ end
15
+
16
+ def add_path(path)
17
+ instances_set.merge(instances_on_path(path))
18
+ self
19
+ end
20
+
21
+ def add_pending
22
+ instances_set.merge(context.pending_instances)
23
+ self
24
+ end
25
+
26
+ def instances
27
+ instances_set.sort
28
+ end
29
+
30
+ private
31
+
32
+ def instance_match?(instance, instance_name)
33
+ ::File.fnmatch?(instance_name, instance.name)
34
+ end
35
+
36
+ def instances_on_path(path)
37
+ context.instances.select { |instance| instance_match?(instance, path) }
38
+ end
39
+
40
+ def instances_set
41
+ @instances_set ||= ::Set.new
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ruby-progressbar'
4
+ require 'avm/launcher/instances/base'
5
+
6
+ module Avm
7
+ module Launcher
8
+ class Context
9
+ class InstanceDiscovery
10
+ attr_reader :instances
11
+
12
+ def initialize(context)
13
+ @context = context
14
+ @progress = ::ProgressBar.create(title: 'Instance discovery', total: 1)
15
+ @instances = path_instances(@context.root, nil)
16
+ ensure
17
+ @progress&.finish
18
+ end
19
+
20
+ private
21
+
22
+ def path_instances(path, parent_instance)
23
+ update_progress_format(path)
24
+ on_rescued_path_instances(path) do |r|
25
+ if path.project?
26
+ parent_instance = ::Avm::Launcher::Instances::Base.instanciate(path, parent_instance)
27
+ r << path
28
+ end
29
+ children = path.children
30
+ update_progress_count(children)
31
+ r.concat(children.flat_map { |c| path_instances(c, parent_instance) })
32
+ end
33
+ end
34
+
35
+ def on_rescued_path_instances(path)
36
+ r = []
37
+ begin
38
+ yield(r) if path.included?
39
+ rescue StandardError => e
40
+ warn("#{path}: #{e}")
41
+ end
42
+ r
43
+ end
44
+
45
+ def update_progress_format(path)
46
+ @progress.format = "%t (Paths: %c/%C, Current: #{path.logical}) |%B| %a"
47
+ end
48
+
49
+ def update_progress_count(children)
50
+ @progress.total += children.count
51
+ @progress.increment
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/launcher/instances/base'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Avm
7
+ module Launcher
8
+ class Context
9
+ class InstanceManager
10
+ class CachedInstance
11
+ enable_speaker
12
+ enable_simple_cache
13
+ common_constructor :cached_instances, :data
14
+
15
+ private
16
+
17
+ def instance_uncached
18
+ ::Avm::Launcher::Instances::Base.instanciate(path, parent_instance)
19
+ rescue ::Avm::Launcher::Errors::NonProject
20
+ warn "Cached instance \"#{data[:logical]}\" not found"
21
+ nil
22
+ end
23
+
24
+ def parent_instance_uncached
25
+ data[:parent]
26
+ .if_present { |v| cached_instances.by_logical_path(v) }
27
+ .if_present(&:instance)
28
+ end
29
+
30
+ def path_uncached
31
+ ::Avm::Launcher::Paths::Logical.from_h(cached_instances.context, data)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/launcher/context/instance_manager/cached_instance'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Avm
7
+ module Launcher
8
+ class Context
9
+ class InstanceManager
10
+ class CachedInstances
11
+ enable_simple_cache
12
+ common_constructor :context, :content
13
+
14
+ def instances
15
+ content.keys.map { |k| by_logical_path(k).instance }.reject(&:blank?)
16
+ end
17
+
18
+ def by_logical_path(key)
19
+ cached_instances[key].if_blank do
20
+ cached_instances[key] = ::Avm::Launcher::Context::InstanceManager::CachedInstance.new(
21
+ self, content.fetch(key)
22
+ )
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def cached_instances_uncached
29
+ {}
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'avm/launcher/publish/check_result'
5
+ require('yaml')
6
+
7
+ module Avm
8
+ module Launcher
9
+ class Context
10
+ class InstanceManager
11
+ require_sub __FILE__
12
+ enable_simple_cache
13
+ common_constructor :context
14
+
15
+ def publish_state_set(instance, stereotype_name, check_status)
16
+ data = cached_instances_file_content_uncached
17
+ data[instance.logical] ||= {}
18
+ data[instance.logical][:publish_state] ||= {}
19
+ data[instance.logical][:publish_state][stereotype_name] = check_status
20
+ write_cache_file(data)
21
+ end
22
+
23
+ def pending_instances
24
+ instances.select { |instance| pending_instance?(instance) }
25
+ end
26
+
27
+ private
28
+
29
+ def instances_uncached
30
+ (cached_instances || search_instances).select(&:included?)
31
+ end
32
+
33
+ def search_instances
34
+ cache_instances(::Avm::Launcher::Context::InstanceDiscovery.new(context).instances)
35
+ end
36
+
37
+ def cached_instances
38
+ return nil if context.recache
39
+ return nil unless cached_instances_file_content
40
+
41
+ CachedInstances.new(self, cached_instances_file_content).instances
42
+ end
43
+
44
+ def cached_instances_file_content_uncached
45
+ r = YAML.load_file(cache_file_path)
46
+ r.is_a?(::Hash) ? r : nil
47
+ rescue Errno::ENOENT
48
+ nil
49
+ end
50
+
51
+ def cache_instances(instances)
52
+ write_cache_file(Hash[instances.map { |i| [i.logical, i.to_h] }])
53
+ instances
54
+ end
55
+
56
+ def write_cache_file(data)
57
+ ::File.write(cache_file_path, data.to_yaml)
58
+ end
59
+
60
+ def cache_file_path
61
+ ::File.join(context.cache_root, 'instances.yml')
62
+ end
63
+
64
+ def pending_instance?(instance)
65
+ data = cached_instances_file_content
66
+ return false unless data[instance.logical]
67
+ return false unless data[instance.logical][:publish_state].is_a?(Hash)
68
+
69
+ data[instance.logical][:publish_state].any? do |_k, v|
70
+ ::Avm::Launcher::Publish::CheckResult.pending_status?(v)
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/launcher/instances/settings'
4
+ require 'eac_ruby_utils/simple_cache'
5
+ require 'yaml'
6
+
7
+ module Avm
8
+ module Launcher
9
+ class Context
10
+ class Settings
11
+ include ::EacRubyUtils::SimpleCache
12
+
13
+ def initialize(file)
14
+ unless ::File.exist?(file)
15
+ ::FileUtils.mkdir_p(::File.dirname(file))
16
+ ::File.write(file, {}.to_yaml)
17
+ end
18
+ @data = YAML.load_file(file)
19
+ end
20
+
21
+ def instance_settings(instance)
22
+ ::Avm::Launcher::Instances::Settings.new(value(['Instances', instance.name]))
23
+ end
24
+
25
+ private
26
+
27
+ def excluded_projects_uncached
28
+ enum_value(%w[Projects Exclude])
29
+ end
30
+
31
+ def excluded_paths_uncached
32
+ enum_value(%w[Paths Exclude])
33
+ end
34
+
35
+ def enum_value(path)
36
+ r = value(path)
37
+ r.is_a?(Enumerable) ? r : []
38
+ end
39
+
40
+ def value(path)
41
+ node_value(@data, path)
42
+ end
43
+
44
+ def node_value(data, path)
45
+ return data if path.empty?
46
+ return nil unless data.is_a?(Hash)
47
+
48
+ node_value(data[path.first], path.drop(1))
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/core_ext/hash/indifferent_access'
4
+ require 'avm/launcher/context/instance_manager'
5
+ require 'eac_ruby_utils/simple_cache'
6
+ require 'eac_cli/speaker'
7
+ require 'avm/launcher/context/instance_discovery'
8
+ require 'avm/launcher/context/settings'
9
+ require 'avm/launcher/paths/logical'
10
+ require 'avm/launcher/project'
11
+ require 'avm/tools/self'
12
+
13
+ module Avm
14
+ module Launcher
15
+ class Context
16
+ include ::EacRubyUtils::SimpleCache
17
+ enable_speaker
18
+
19
+ class << self
20
+ attr_writer :current
21
+
22
+ def current
23
+ @current ||= default
24
+ end
25
+
26
+ def default
27
+ @default ||= Context.new
28
+ end
29
+ end
30
+
31
+ attr_reader :root, :settings, :cache_root
32
+ attr_accessor :publish_options, :recache, :instance_manager
33
+
34
+ CONFIG_PATH_PREFIX = 'launcher'
35
+
36
+ def initialize(options = {})
37
+ @options = options.with_indifferent_access
38
+ @root = ::Avm::Launcher::Paths::Logical.new(self, nil, build_option(:projects_root), '/')
39
+ @settings = ::Avm::Launcher::Context::Settings.new(build_option(:settings_file))
40
+ @cache_root = build_option(:cache_root)
41
+ @publish_options = { new: false, confirm: false, stereotype: nil }
42
+ @instance_manager = ::Avm::Launcher::Context::InstanceManager.new(self)
43
+ @recache = false
44
+ end
45
+
46
+ def instance(name)
47
+ instances.find { |i| i.name == name }
48
+ end
49
+
50
+ def instances
51
+ @instance_manager.instances
52
+ end
53
+
54
+ def pending_instances
55
+ @instance_manager.pending_instances
56
+ end
57
+
58
+ private
59
+
60
+ def build_option(key)
61
+ @options[key] || config_option(key) || default_option(key)
62
+ end
63
+
64
+ def config_option(key)
65
+ ::Avm::Self::Instance.default.entry([CONFIG_PATH_PREFIX, key].join('.')).optional_value
66
+ end
67
+
68
+ def default_cache_root
69
+ ::Avm::Tools::Self.application.cache_dir.join('launcher')
70
+ end
71
+
72
+ def default_option(key)
73
+ send("default_#{key}".underscore)
74
+ end
75
+
76
+ def default_projects_root
77
+ '.'
78
+ end
79
+
80
+ def default_settings_file
81
+ ::Avm::Tools::Self.application.config_dir.join('launcher.yaml')
82
+ end
83
+
84
+ def projects_uncached
85
+ r = {}
86
+ instances.each do |i|
87
+ r[i.project_name] ||= []
88
+ r[i.project_name] << i
89
+ end
90
+ r.map { |name, instances| ::Avm::Launcher::Project.new(name, instances) }
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avm
4
+ module Launcher
5
+ module Instances
6
+ module Base
7
+ module Cache
8
+ def cache_path(subpath)
9
+ File.join(cache_root, subpath)
10
+ end
11
+
12
+ def cache_key(key, &block)
13
+ v = cache_key_get(key)
14
+ return v if v.present? || block.nil?
15
+
16
+ v = yield
17
+ cache_key_write(key, v)
18
+ v
19
+ end
20
+
21
+ private
22
+
23
+ def cache_key_get(key)
24
+ File.file?(cache_key_path(key)) ? File.read(cache_key_path(key)) : nil
25
+ end
26
+
27
+ def cache_key_write(key, value)
28
+ FileUtils.mkdir_p(File.dirname(cache_key_path(key)))
29
+ File.write(cache_key_path(key), value)
30
+ end
31
+
32
+ def cache_key_path(key)
33
+ File.join(cache_root, 'keys', key.parameterize)
34
+ end
35
+
36
+ def cache_root
37
+ File.join(::Avm::Launcher::Context.current.cache_root, name.parameterize)
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,96 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'base/cache'
4
+ require 'avm/launcher/errors/non_project'
5
+ require 'eac_ruby_utils/speaker/sender'
6
+
7
+ module Avm
8
+ module Launcher
9
+ module Instances
10
+ module Base
11
+ class << self
12
+ def extend_object(object)
13
+ object.extend ::EacRubyUtils::SimpleCache
14
+ object.extend ::EacRubyUtils::Speaker::Sender
15
+ object.extend ::Avm::Launcher::Instances::Base::Cache
16
+ super
17
+ end
18
+
19
+ def instanciate(path, parent)
20
+ unless path.is_a?(::Avm::Launcher::Instances::Base)
21
+ raise ::Avm::Launcher::Errors::NonProject, path unless path.project?
22
+
23
+ path.extend(::Avm::Launcher::Instances::Base)
24
+ path.parent = parent
25
+ end
26
+ path
27
+ end
28
+ end
29
+
30
+ attr_accessor :parent
31
+
32
+ def name
33
+ logical
34
+ end
35
+
36
+ def stereotype?(stereotype)
37
+ stereotypes.include?(stereotype)
38
+ end
39
+
40
+ def to_parent_path
41
+ return self unless @parent
42
+
43
+ logical.gsub(/\A#{Regexp.quote(@parent.logical)}/, '')
44
+ end
45
+
46
+ def project?
47
+ stereotypes.any?
48
+ end
49
+
50
+ def publish_run
51
+ stereotypes.each do |s|
52
+ next unless publish?(s)
53
+
54
+ infov(name, "publishing #{s.label}")
55
+ s.publish_class.new(self).run
56
+ end
57
+ end
58
+
59
+ def publish_check
60
+ stereotypes.each do |s|
61
+ next unless publish?(s)
62
+
63
+ puts "#{name.to_s.cyan}|#{s.label}|" \
64
+ "#{s.publish_class.new(self).check}"
65
+ end
66
+ end
67
+
68
+ def project_name
69
+ ::File.basename(logical)
70
+ end
71
+
72
+ def included?
73
+ !::Avm::Launcher::Context.current.settings.excluded_projects.include?(project_name)
74
+ end
75
+
76
+ def to_h
77
+ super.to_h.merge(parent: parent ? parent.logical : nil)
78
+ end
79
+
80
+ private
81
+
82
+ def publish?(stereotype)
83
+ return false unless stereotype.publish_class
84
+ return false unless options.stereotype_publishable?(stereotype)
85
+
86
+ filter = ::Avm::Launcher::Context.current.publish_options[:stereotype]
87
+ filter.blank? ? true : filter == stereotype.name.demodulize
88
+ end
89
+
90
+ def options_uncached
91
+ ::Avm::Launcher::Context.current.settings.instance_settings(self)
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avm
4
+ module Launcher
5
+ module Instances
6
+ class Error < StandardError
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/launcher/context'
4
+ require 'avm/tools/core_ext'
5
+ require 'avm/launcher/context/instance_collector'
6
+
7
+ module Avm
8
+ module Launcher
9
+ module Instances
10
+ module RunnerHelper
11
+ common_concern do
12
+ runner_definition do
13
+ bool_opt '--all', 'Select all instances.'
14
+ bool_opt '--pending', 'Select pending instances.'
15
+ bool_opt '--recache', 'Rewrite instances cache.'
16
+ end
17
+
18
+ set_callback :run, :before, :setup_cache
19
+ end
20
+
21
+ def context
22
+ @context ||= ::Avm::Launcher::Context.current
23
+ end
24
+
25
+ def instances
26
+ collector = ::Avm::Launcher::Context::InstanceCollector.new(context)
27
+ collector.add_all if parsed.all?
28
+ collector.add_pending if parsed.pending?
29
+ parsed.instance_path.flat_map { |p| collector.add_path(p) }
30
+ collector.instances
31
+ end
32
+
33
+ def instance_stereotypes(instance)
34
+ instance.stereotypes.map(&:label).join(', ')
35
+ end
36
+
37
+ def instance_label(instance)
38
+ "#{instance.name} [#{instance_stereotypes(instance)}]"
39
+ end
40
+
41
+ def setup_cache
42
+ ::Avm::Launcher::Context.current.recache = parsed.recache?
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module Launcher
7
+ module Instances
8
+ class Settings
9
+ DEFAULT_CURRENT_REVISION = 'origin/master'
10
+ DEFAULT_PUBLISH_REMOTE = 'publish'
11
+ PUBLISHABLE_KEY = :publishable
12
+
13
+ common_constructor :data do
14
+ self.data = (data.is_a?(Hash) ? data : {}).with_indifferent_access
15
+ end
16
+
17
+ def git_current_revision
18
+ data[__method__] || DEFAULT_CURRENT_REVISION
19
+ end
20
+
21
+ def git_publish_remote
22
+ data[__method__] || DEFAULT_PUBLISH_REMOTE
23
+ end
24
+
25
+ def publishable?
26
+ publishable_value ? true : false
27
+ end
28
+
29
+ def stereotype_publishable?(stereotype)
30
+ return publishable? unless publishable_value.is_a?(::Hash)
31
+
32
+ parse_publishable_value(publishable_value[stereotype.stereotype_name], true)
33
+ end
34
+
35
+ private
36
+
37
+ def publishable_value
38
+ parse_publishable_value(data[PUBLISHABLE_KEY], false)
39
+ end
40
+
41
+ def parse_publishable_value(value, hash_to_true)
42
+ return value.with_indifferent_access if parse_publishable_value_hash?(value, hash_to_true)
43
+ return true if value.nil? || value == true
44
+ return false if value == false
45
+
46
+ value ? true : false
47
+ end
48
+
49
+ def parse_publishable_value_hash?(value, hash_to_true)
50
+ !hash_to_true && value.is_a?(::Hash)
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/projects/stereotypes'
4
+ require 'avm/launcher/paths/real'
5
+
6
+ module Avm
7
+ module Launcher
8
+ module Paths
9
+ class Logical
10
+ include ::Comparable
11
+ include ::EacRubyUtils::SimpleCache
12
+
13
+ class << self
14
+ def from_h(context, hash)
15
+ parent_path = hash[:parent_path] ? from_h(context, hash[:parent_path]) : nil
16
+ new(context, parent_path, hash[:real], hash[:logical])
17
+ end
18
+ end
19
+
20
+ attr_reader :context, :real, :logical, :parent_path
21
+
22
+ def initialize(context, parent_path, real, logical)
23
+ @context = context
24
+ @parent_path = parent_path
25
+ @real = ::Avm::Launcher::Paths::Real.new(real)
26
+ @logical = logical
27
+ end
28
+
29
+ def <=>(other)
30
+ [logical, real] <=> [other.logical, other.real]
31
+ end
32
+
33
+ def to_s
34
+ logical
35
+ end
36
+
37
+ def to_h
38
+ { logical: logical, real: real.to_s, parent_path: parent_path ? parent_path.to_h : nil }
39
+ end
40
+
41
+ def project?
42
+ stereotypes.any?
43
+ end
44
+
45
+ def children
46
+ r = []
47
+ Dir.entries(warped).each do |c|
48
+ c_path = ::File.join(warped, c)
49
+ next unless ::File.directory?(c_path)
50
+ next if c.start_with?('.')
51
+
52
+ r << build_child(c)
53
+ end
54
+ r
55
+ end
56
+
57
+ def included?
58
+ !context.settings.excluded_paths.include?(logical)
59
+ end
60
+
61
+ private
62
+
63
+ def stereotypes_uncached
64
+ ::Avm::Projects::Stereotype.stereotypes.select { |s| s.match?(self) }
65
+ end
66
+
67
+ def build_child(name)
68
+ ::Avm::Launcher::Paths::Logical.new(
69
+ context,
70
+ self,
71
+ ::File.join(warped, name),
72
+ ::File.join(logical, name)
73
+ )
74
+ end
75
+
76
+ def warped_uncached
77
+ if is_a?(::Avm::Launcher::Instances::Base)
78
+ stereotypes.each do |s|
79
+ return s.warp_class.new(self) if s.warp_class
80
+ end
81
+ end
82
+ real
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/launcher/errors/base'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Avm
7
+ module Launcher
8
+ module Publish
9
+ class Base
10
+ common_constructor :instance
11
+
12
+ def run
13
+ s = check
14
+ info("Check: #{s}")
15
+ return unless s.status == ::Avm::Launcher::Publish::CheckResult::STATUS_PENDING
16
+
17
+ publish
18
+ end
19
+
20
+ def check
21
+ s = check_with_rescue
22
+ ::Avm::Launcher::Context.current.instance_manager.publish_state_set(
23
+ instance, stereotype.stereotype_name, s.status
24
+ )
25
+ s
26
+ end
27
+
28
+ private
29
+
30
+ def stereotype
31
+ self.class.name.deconstantize.constantize
32
+ end
33
+
34
+ def check_with_rescue
35
+ internal_check
36
+ rescue ::Avm::Launcher::Errors::Base => e
37
+ ::Avm::Launcher::Publish::CheckResult.blocked("Error: #{e}")
38
+ rescue ::Avm::Launcher::Git::Error => e
39
+ ::Avm::Launcher::Publish::CheckResult.blocked("Git error: #{e}")
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
data/lib/avm/registry.rb CHANGED
@@ -10,8 +10,6 @@ module Avm
10
10
  lists.add_symbol :category, :application_stereotypes, :instances, :runners, :scms,
11
11
  :source_generators, :sources
12
12
 
13
- WITH_PATH = [CATEGORY_SCMS, CATEGORY_SOURCES].freeze
14
-
15
13
  class << self
16
14
  enable_simple_cache
17
15
 
@@ -5,17 +5,16 @@ require 'eac_ruby_utils/core_ext'
5
5
  module Avm
6
6
  module Rspec
7
7
  module Setup
8
- def self.extended(obj)
9
- obj.setup_in_avm_registry_example
10
- obj.setup_not_in_avm_registry_example
11
- end
8
+ EXAMPLES = %w[entries_values in_avm_registry not_in_avm_registry].freeze
12
9
 
13
- def setup_in_avm_registry_example
14
- require 'avm/rspec/shared_examples/in_avm_registry'
10
+ def self.extended(obj)
11
+ obj.setup_examples
15
12
  end
16
13
 
17
- def setup_not_in_avm_registry_example
18
- require 'avm/rspec/shared_examples/not_in_avm_registry'
14
+ def setup_examples
15
+ EXAMPLES.each do |example|
16
+ require "avm/rspec/shared_examples/#{example}"
17
+ end
19
18
  end
20
19
  end
21
20
  end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ ::RSpec.shared_examples 'entries_values' do |spec_file, expected_values|
6
+ describe '#read_entry' do
7
+ config_path = spec_file.to_pathname
8
+ config_path = config_path.dirname.join("#{config_path.basename_noext}_files", 'config.yml')
9
+ ::EacRubyUtils::Rspec.default_setup.stub_eac_config_node(self, config_path)
10
+
11
+ expected_values.each do |instance_id, values|
12
+ values.each do |input, expected|
13
+ context "when a auto value is requested for \"#{instance_id}.#{input}\"" do
14
+ let(:instance) { described_class.by_id(instance_id) }
15
+
16
+ it ".read_entry should return \"#{expected}\"" do
17
+ expect(instance.read_entry(input)).to eq(expected)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
data/lib/avm/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Avm
4
- VERSION = '0.44.0'
4
+ VERSION = '0.46.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.44.0
4
+ version: 0.46.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eduardo H. Bogoni
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-22 00:00:00.000000000 Z
11
+ date: 2022-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eac_cli
@@ -50,20 +50,14 @@ dependencies:
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: '0.4'
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- version: 0.4.2
53
+ version: '0.5'
57
54
  type: :runtime
58
55
  prerelease: false
59
56
  version_requirements: !ruby/object:Gem::Requirement
60
57
  requirements:
61
58
  - - "~>"
62
59
  - !ruby/object:Gem::Version
63
- version: '0.4'
64
- - - ">="
65
- - !ruby/object:Gem::Version
66
- version: 0.4.2
60
+ version: '0.5'
67
61
  - !ruby/object:Gem::Dependency
68
62
  name: eac_git
69
63
  requirement: !ruby/object:Gem::Requirement
@@ -73,7 +67,7 @@ dependencies:
73
67
  version: '0.12'
74
68
  - - ">="
75
69
  - !ruby/object:Gem::Version
76
- version: 0.12.2
70
+ version: 0.12.3
77
71
  type: :runtime
78
72
  prerelease: false
79
73
  version_requirements: !ruby/object:Gem::Requirement
@@ -83,7 +77,7 @@ dependencies:
83
77
  version: '0.12'
84
78
  - - ">="
85
79
  - !ruby/object:Gem::Version
86
- version: 0.12.2
80
+ version: 0.12.3
87
81
  - !ruby/object:Gem::Dependency
88
82
  name: eac_ruby_utils
89
83
  requirement: !ruby/object:Gem::Requirement
@@ -241,6 +235,11 @@ files:
241
235
  - lib/avm/entries/base/uri_components_entries_values/path_component.rb
242
236
  - lib/avm/entries/base/uri_components_entries_values/url_component.rb
243
237
  - lib/avm/entries/entry.rb
238
+ - lib/avm/entries/jobs.rb
239
+ - lib/avm/entries/jobs/base.rb
240
+ - lib/avm/entries/jobs/variables_source.rb
241
+ - lib/avm/entries/jobs/variables_source/read_entry.rb
242
+ - lib/avm/entries/jobs/with_variables_source.rb
244
243
  - lib/avm/entries/keys_constants_set.rb
245
244
  - lib/avm/entries/uri_builder.rb
246
245
  - lib/avm/executables.rb
@@ -259,12 +258,23 @@ files:
259
258
  - lib/avm/instances/docker_image.rb
260
259
  - lib/avm/instances/entry_keys.rb
261
260
  - lib/avm/instances/runner.rb
262
- - lib/avm/jobs.rb
263
- - lib/avm/jobs/base.rb
264
- - lib/avm/jobs/variables_source.rb
261
+ - lib/avm/launcher/context.rb
262
+ - lib/avm/launcher/context/instance_collector.rb
263
+ - lib/avm/launcher/context/instance_discovery.rb
264
+ - lib/avm/launcher/context/instance_manager.rb
265
+ - lib/avm/launcher/context/instance_manager/cached_instance.rb
266
+ - lib/avm/launcher/context/instance_manager/cached_instances.rb
267
+ - lib/avm/launcher/context/settings.rb
265
268
  - lib/avm/launcher/errors/base.rb
266
269
  - lib/avm/launcher/errors/non_project.rb
270
+ - lib/avm/launcher/instances/base.rb
271
+ - lib/avm/launcher/instances/base/cache.rb
272
+ - lib/avm/launcher/instances/error.rb
273
+ - lib/avm/launcher/instances/runner_helper.rb
274
+ - lib/avm/launcher/instances/settings.rb
275
+ - lib/avm/launcher/paths/logical.rb
267
276
  - lib/avm/launcher/paths/real.rb
277
+ - lib/avm/launcher/publish/base.rb
268
278
  - lib/avm/launcher/publish/check_result.rb
269
279
  - lib/avm/path_string.rb
270
280
  - lib/avm/registry.rb
@@ -282,6 +292,7 @@ files:
282
292
  - lib/avm/result.rb
283
293
  - lib/avm/rspec.rb
284
294
  - lib/avm/rspec/setup.rb
295
+ - lib/avm/rspec/shared_examples/entries_values.rb
285
296
  - lib/avm/rspec/shared_examples/in_avm_registry.rb
286
297
  - lib/avm/rspec/shared_examples/not_in_avm_registry.rb
287
298
  - lib/avm/runners/base.rb
data/lib/avm/jobs/base.rb DELETED
@@ -1,63 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'avm/jobs/variables_source'
4
- require 'avm/result'
5
- require 'eac_cli/core_ext'
6
-
7
- module Avm
8
- module Jobs
9
- module Base
10
- common_concern do
11
- include ::ActiveSupport::Callbacks
12
-
13
- enable_speaker
14
- enable_simple_cache
15
- enable_listable
16
- common_constructor :instance, :options, default: [{}] do
17
- if option_list.present?
18
- self.options = option_list.hash_keys_validate!(options.symbolize_keys)
19
- end
20
- end
21
- define_callbacks(*jobs)
22
- end
23
-
24
- module ClassMethods
25
- def jobs
26
- const_get('JOBS').dup
27
- end
28
- end
29
-
30
- module InstanceMethods
31
- def option_list
32
- nil
33
- end
34
-
35
- def run
36
- start_banner if respond_to?(:start_banner)
37
- run_jobs
38
- ::Avm::Result.success('Done!')
39
- rescue ::Avm::Result::Error => e
40
- e.to_result
41
- end
42
-
43
- def variables_source
44
- ::Avm::Jobs::VariablesSource.new(self, instance)
45
- end
46
-
47
- protected
48
-
49
- def run_jobs
50
- jobs.each do |job|
51
- run_callbacks job do
52
- send(job)
53
- end
54
- end
55
- end
56
-
57
- def jobs
58
- self.class.jobs
59
- end
60
- end
61
- end
62
- end
63
- end
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_ruby_utils/core_ext'
4
-
5
- module Avm
6
- module Jobs
7
- class VariablesSource
8
- common_constructor :job, :instance
9
-
10
- def read_entry(path, options = {})
11
- entry_from_job(path) || instance.read_entry(path, options)
12
- end
13
-
14
- private
15
-
16
- def entry_from_job(path)
17
- method = path.gsub('.', '_').underscore
18
- return job.send(method) if job.respond_to?(method, true)
19
- end
20
- end
21
- end
22
- end