avm 0.104.0 → 0.105.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0f81cb550ea61d3e42d6c56c151466c5db78917ab021d6d46c51e630e2a1960b
4
- data.tar.gz: 9426d8da3752dcba81eae1db4af9d877b4674c6368ba2602c6d19c58328537eb
3
+ metadata.gz: 8091e047a9a5e87bd93ff3423128f385a7c5c7752bfa25b8fa4de750454f7fc2
4
+ data.tar.gz: b30e8c2519e8f9752349c6d59ab63260438f1e01d8aa1d25645027c7e12516cd
5
5
  SHA512:
6
- metadata.gz: e02f582b688449eeb0858e4e9c543f734f5429dddb6ab7e09dbdc2821d284189090e8058fc21472c5b3bf8c7a8dc359e2381fe00331eb49babec3497fac00399
7
- data.tar.gz: 2dc4f643abcc04da4cd732889823db1303a678d3622199e3280759ec8b0d1fc9a6e0101a3e1bc142ec122db3dc0eea37d88ee87a4ea477e09f97aeac1db6ab8b
6
+ metadata.gz: ff7c94a0119d61c3f53211a26e1fecce8d407342066ec2f25d6d1ce77680ec745219f5679e94341838a5c46baeafd062d395b426a91f554763b5f4edc57ac64d
7
+ data.tar.gz: 8e01554f896bb77f0b404182983ecc9bf7308088801db05f2b1a56141652b9143f5da8ef1e392345bc8bbafc74d74cee21e45c8a4eeca32e0f52f7752d1e4356
@@ -4,22 +4,26 @@ module Avm
4
4
  module Launcher
5
5
  class Context
6
6
  class InstanceDiscovery
7
- enable_simple_cache
8
-
9
- # @!method instances
10
- # @return [Array<Avm::Launcher::Instances::Base>]
7
+ enable_memoized
11
8
 
12
9
  # @!method initialize(context)
13
10
  # @param context [Avm::Launcher::Context]
14
11
  common_constructor :context
15
12
 
16
- private
17
-
18
13
  # @return [Array<Avm::Launcher::Instances::Base>]
19
- def instances_uncached
14
+ memoize def instances
20
15
  root_source_wrappers.flat_map(&:projects)
21
16
  end
22
17
 
18
+ # @param logical_path [Avm::Launcher::Paths::Logical]
19
+ # @param parent_project [Avm::Launcher::Instances::Base, nil]
20
+ # @return [Array<Avm::Launcher::Instances::Base>]
21
+ def instances_from(logical_path, parent_project)
22
+ ::Avm::Launcher::Context::InstanceDiscovery::SourceWrapper.new(
23
+ self, logical_path, parent_project
24
+ ).projects
25
+ end
26
+
23
27
  require_sub __FILE__, require_mode: :kernel
24
28
  end
25
29
  end
@@ -5,27 +5,59 @@ module Avm
5
5
  class Context
6
6
  class InstanceManager
7
7
  class CachedInstance
8
+ enable_memoized
8
9
  enable_speaker
9
- enable_simple_cache
10
- common_constructor :cached_instances, :data
10
+ common_constructor :cached_instances, :logical_path
11
11
 
12
- private
12
+ # @return [Hash]
13
+ memoize def data
14
+ ::YAML.load_file(data_path)
15
+ end
16
+
17
+ # @param value [Hash]
18
+ def data=(value)
19
+ data_path.assert_parent.write(value.to_yaml)
20
+ unmemoize_all
21
+ end
22
+
23
+ # @return [Pathname]
24
+ def data_path
25
+ cached_instances.instance_manager.context.cache_root.to_pathname
26
+ .join('instances', "#{logical_path.parameterize}.yaml")
27
+ end
13
28
 
14
- def instance_uncached
29
+ # @return [Hash, nil]
30
+ memoize def instance
15
31
  ::Avm::Launcher::Instances::Base.instanciate(path, parent_instance)
16
32
  rescue ::Avm::Launcher::Errors::NonProject
17
33
  warn "Cached instance \"#{data[:logical]}\" not found"
18
34
  nil
19
35
  end
20
36
 
21
- def parent_instance_uncached
37
+ # @return [Boolean]
38
+ def outdated?
39
+ instance.present? && instance.commit_id != data[:commit_id]
40
+ end
41
+
42
+ # @return [Hash, nil]
43
+ memoize def parent_instance
22
44
  data[:parent]
23
45
  .if_present { |v| cached_instances.by_logical_path(v) }
24
46
  .if_present(&:instance)
25
47
  end
26
48
 
27
- def path_uncached
28
- ::Avm::Launcher::Paths::Logical.from_h(cached_instances.context, data)
49
+ # @return [Avm::Launcher::Paths::Logical]
50
+ memoize def path
51
+ ::Avm::Launcher::Paths::Logical.from_h(cached_instances.instance_manager, data)
52
+ end
53
+
54
+ # @param stereotype_name [String]
55
+ # @param check_status [String]
56
+ def publish_state_set(stereotype_name, check_status)
57
+ new_data = data
58
+ new_data[:publish_state] ||= {}
59
+ new_data[:publish_state][stereotype_name] = check_status
60
+ self.data = new_data
29
61
  end
30
62
  end
31
63
  end
@@ -5,25 +5,113 @@ module Avm
5
5
  class Context
6
6
  class InstanceManager
7
7
  class CachedInstances
8
- enable_simple_cache
9
- common_constructor :context, :content
8
+ enable_memoized
9
+ common_constructor :instance_manager
10
10
 
11
+ memoize def cached_instances
12
+ {}
13
+ end
14
+
15
+ # @return [Hash, nil]
16
+ memoize def content
17
+ content_unmemoized
18
+ end
19
+
20
+ # @return [Hash, nil]
21
+ def content_unmemoized
22
+ r = YAML.load_file(root_file_path)
23
+ r.is_a?(::Hash) ? r : nil
24
+ rescue Errno::ENOENT
25
+ nil
26
+ end
27
+
28
+ # @return [Array<Avm::Launcher::Instances::Base>]
11
29
  def instances
30
+ refresh_outdated_instances
12
31
  content.keys.map { |k| by_logical_path(k).instance }.compact_blank
13
32
  end
14
33
 
15
34
  def by_logical_path(key)
16
35
  cached_instances[key].if_blank do
17
36
  cached_instances[key] = ::Avm::Launcher::Context::InstanceManager::CachedInstance.new(
18
- self, content.fetch(key)
37
+ self, key
19
38
  )
20
39
  end
21
40
  end
22
41
 
23
- private
42
+ # @return [String]
43
+ def root_file_path
44
+ ::File.join(instance_manager.context.cache_root, 'instances.yml')
45
+ end
24
46
 
25
- def cached_instances_uncached
26
- {}
47
+ # @param instances []
48
+ # @return []
49
+ def write_instances(instances)
50
+ write_root_file(write_instances_files(instances))
51
+ instances
52
+ end
53
+
54
+ protected
55
+
56
+ # @param cached_instance [Avm::Launcher::Context::InstanceManager::CachedInstance]
57
+ # @return [Array<Avm::Launcher::Instances::Base>]
58
+ def rediscovered_instances(cached_instance)
59
+ ::Avm::Launcher::Context::InstanceDiscovery.new(instance_manager.context)
60
+ .instances_from(
61
+ ::Avm::Launcher::Paths::Logical.new(
62
+ instance_manager.context, nil, cached_instance.path.real,
63
+ cached_instance.logical_path
64
+ ),
65
+ cached_instance.parent_instance
66
+ )
67
+ end
68
+
69
+ # @param cached_instance [Avm::Launcher::Context::InstanceManager::CachedInstance]
70
+ # @return [void]
71
+ def refresh_instance(cached_instance)
72
+ write_root_file(
73
+ content.reject { |key, _| subtree_key?(cached_instance.logical_path, key) }
74
+ .merge(write_instances_files(rediscovered_instances(cached_instance)))
75
+ )
76
+ unmemoize(:content)
77
+ end
78
+
79
+ # @return [void]
80
+ def refresh_outdated_instances
81
+ content.keys.sort.each do |key|
82
+ next unless content.key?(key)
83
+
84
+ by_logical_path(key).then { |v| refresh_instance(v) if v.outdated? }
85
+ end
86
+ end
87
+
88
+ # @param root_key [String]
89
+ # @param key [String]
90
+ # @return [Boolean]
91
+ def subtree_key?(root_key, key)
92
+ key == root_key || key.start_with?("#{root_key}/")
93
+ end
94
+
95
+ # @param logical_path [Avm::Launcher::Paths::Logical]
96
+ # @param instance_data [Hash]
97
+ # @return [String]
98
+ def write_instance(logical_path, instance_data)
99
+ cached_instance = by_logical_path(logical_path)
100
+ cached_instance.data = instance_data
101
+ cached_instance.data_path.to_path
102
+ end
103
+
104
+ # @param instances [Enumerable<Avm::Launcher::Instances::Base>]
105
+ # @return [Hash<String, String>]
106
+ def write_instances_files(instances)
107
+ instances.to_h { |i| [i.logical, write_instance(i.logical, i.to_h)] }
108
+ end
109
+
110
+ # @param cache_file_data [Hash<String, String>]
111
+ # @return [void]
112
+ def write_root_file(cache_file_data)
113
+ root_file_path.to_pathname.parent.mkpath
114
+ ::File.write(root_file_path, cache_file_data.to_yaml)
27
115
  end
28
116
  end
29
117
  end
@@ -6,65 +6,59 @@ module Avm
6
6
  module Launcher
7
7
  class Context
8
8
  class InstanceManager
9
- enable_simple_cache
9
+ enable_memoized
10
10
  common_constructor :context
11
11
 
12
+ memoize def cached_instances_file_content
13
+ cached_instances_file_content_unmemoized
14
+ end
15
+
16
+ memoize def instances
17
+ (cached_instances || search_instances).select(&:included?)
18
+ end
19
+
20
+ # @param instance [Avm::Launcher::Paths::Logical]
21
+ # @param stereotype_name [String]
22
+ # @param check_status [String]
12
23
  def publish_state_set(instance, stereotype_name, check_status)
13
- data = cached_instances_file_content_uncached
14
- data[instance.logical] ||= {}
15
- data[instance.logical][:publish_state] ||= {}
16
- data[instance.logical][:publish_state][stereotype_name] = check_status
17
- write_cache_file(data)
24
+ cached_instances_obj.by_logical_path(instance.logical)
25
+ .publish_state_set(stereotype_name, check_status)
18
26
  end
19
27
 
20
28
  def pending_instances
21
29
  instances.select { |instance| pending_instance?(instance) }
22
30
  end
23
31
 
24
- private
32
+ protected
25
33
 
26
- def instances_uncached
27
- (cached_instances || search_instances).select(&:included?)
34
+ # @return [Avm::Launcher::Context::InstanceManager::CachedInstances]
35
+ memoize def cached_instances_obj
36
+ Avm::Launcher::Context::InstanceManager::CachedInstances.new(self)
28
37
  end
29
38
 
39
+ private
40
+
30
41
  def search_instances
31
- cache_instances(::Avm::Launcher::Context::InstanceDiscovery.new(context).instances)
42
+ cached_instances_obj.write_instances(
43
+ ::Avm::Launcher::Context::InstanceDiscovery.new(context).instances
44
+ )
32
45
  end
33
46
 
34
47
  def cached_instances
35
48
  return nil if context.recache
36
- return nil unless cached_instances_file_content
37
-
38
- CachedInstances.new(self, cached_instances_file_content).instances
39
- end
40
-
41
- def cached_instances_file_content_uncached
42
- r = YAML.load_file(cache_file_path)
43
- r.is_a?(::Hash) ? r : nil
44
- rescue Errno::ENOENT
45
- nil
46
- end
47
-
48
- def cache_instances(instances)
49
- write_cache_file(instances.to_h { |i| [i.logical, i.to_h] })
50
- instances
51
- end
52
-
53
- def write_cache_file(data)
54
- cache_file_path.to_pathname.parent.mkpath
55
- ::File.write(cache_file_path, data.to_yaml)
56
- end
49
+ return nil unless cached_instances_obj.content
57
50
 
58
- def cache_file_path
59
- ::File.join(context.cache_root, 'instances.yml')
51
+ cached_instances_obj.instances
60
52
  end
61
53
 
54
+ # @param instance [Avm::Launcher::Paths::Logical]
55
+ # @return [Boolean]
62
56
  def pending_instance?(instance)
63
- data = cached_instances_file_content
64
- return false unless data[instance.logical]
65
- return false unless data[instance.logical][:publish_state].is_a?(Hash)
57
+ data = cached_instances_obj.by_logical_path(instance.logical).data
58
+ return false unless data
59
+ return false unless data[:publish_state].is_a?(Hash)
66
60
 
67
- data[instance.logical][:publish_state].any? do |_k, v|
61
+ data[:publish_state].any? do |_k, v|
68
62
  ::Avm::Launcher::Publish::CheckResult.pending_status?(v)
69
63
  end
70
64
  end
@@ -44,9 +44,7 @@ module Avm
44
44
  instances.find { |i| i.name == name }
45
45
  end
46
46
 
47
- delegate :instances, to: :@instance_manager
48
-
49
- delegate :pending_instances, to: :@instance_manager
47
+ delegate :instances, :pending_instances, to: :@instance_manager
50
48
 
51
49
  private
52
50
 
@@ -31,6 +31,17 @@ module Avm
31
31
  @application ||= ::Avm::Registry.applications.detect(project_name)
32
32
  end
33
33
 
34
+ # @return [String, nil]
35
+ def commit_id
36
+ if parent.blank? && source.scm.respond_to?(:git_repo)
37
+ source.scm.git_repo.rev_parse(options.git_current_revision)
38
+ else
39
+ source.scm.head_commit.id
40
+ end
41
+ rescue ::Avm::Registry::DetectionError
42
+ nil
43
+ end
44
+
34
45
  def name
35
46
  logical
36
47
  end
@@ -57,8 +68,9 @@ module Avm
57
68
  ::Avm::Launcher::Context.current.settings.excluded_projects.exclude?(project_name)
58
69
  end
59
70
 
71
+ # @return [Hash]
60
72
  def to_h
61
- super.to_h.merge(parent: parent&.logical)
73
+ super.to_h.merge(commit_id: commit_id, parent: parent&.logical)
62
74
  end
63
75
 
64
76
  private
@@ -24,7 +24,7 @@ module Avm
24
24
  end
25
25
 
26
26
  def to_h
27
- { logical: logical, real: real.to_s, parent_path: parent_path&.to_h }
27
+ { logical: logical, real: real.to_s }
28
28
  end
29
29
 
30
30
  def project?
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.104.0'
4
+ VERSION = '0.105.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.104.0
4
+ version: 0.105.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eduardo H. Bogoni
@@ -163,14 +163,14 @@ dependencies:
163
163
  requirements:
164
164
  - - "~>"
165
165
  - !ruby/object:Gem::Version
166
- version: '0.23'
166
+ version: '0.24'
167
167
  type: :development
168
168
  prerelease: false
169
169
  version_requirements: !ruby/object:Gem::Requirement
170
170
  requirements:
171
171
  - - "~>"
172
172
  - !ruby/object:Gem::Version
173
- version: '0.23'
173
+ version: '0.24'
174
174
  - !ruby/object:Gem::Dependency
175
175
  name: eac_ruby_gem_support
176
176
  requirement: !ruby/object:Gem::Requirement