Class: Mxrb::OfficialMarketplace::ModulePackageInventory
- Inherits:
-
Object
- Object
- Mxrb::OfficialMarketplace::ModulePackageInventory
- Defined in:
- lib/mxrb/official_marketplace/lifecycle.rb
Overview
Read-only view of a module package used to compare update boundaries.
Instance Attribute Summary collapse
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#module_id ⇒ Object
readonly
Returns the value of attribute module_id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#unit_ids ⇒ Object
readonly
Returns the value of attribute unit_ids.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
-
.find_module(mpr, name) ⇒ Object
rubocop:enable Metrics/AbcSize, Metrics/MethodLength.
-
.read(path) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/MethodLength.
- .subtree_ids(mpr, root_id) ⇒ Object
Instance Method Summary collapse
-
#initialize(name:, version:, module_id:, unit_ids:, files:) ⇒ ModulePackageInventory
constructor
A new instance of ModulePackageInventory.
Constructor Details
#initialize(name:, version:, module_id:, unit_ids:, files:) ⇒ ModulePackageInventory
Returns a new instance of ModulePackageInventory.
39 40 41 42 43 44 45 |
# File 'lib/mxrb/official_marketplace/lifecycle.rb', line 39 def initialize(name:, version:, module_id:, unit_ids:, files:) @name = name @version = version @module_id = module_id @unit_ids = unit_ids.freeze @files = files.freeze end |
Instance Attribute Details
#files ⇒ Object (readonly)
Returns the value of attribute files.
37 38 39 |
# File 'lib/mxrb/official_marketplace/lifecycle.rb', line 37 def files @files end |
#module_id ⇒ Object (readonly)
Returns the value of attribute module_id.
37 38 39 |
# File 'lib/mxrb/official_marketplace/lifecycle.rb', line 37 def module_id @module_id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
37 38 39 |
# File 'lib/mxrb/official_marketplace/lifecycle.rb', line 37 def name @name end |
#unit_ids ⇒ Object (readonly)
Returns the value of attribute unit_ids.
37 38 39 |
# File 'lib/mxrb/official_marketplace/lifecycle.rb', line 37 def unit_ids @unit_ids end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
37 38 39 |
# File 'lib/mxrb/official_marketplace/lifecycle.rb', line 37 def version @version end |
Class Method Details
.find_module(mpr, name) ⇒ Object
rubocop:enable Metrics/AbcSize, Metrics/MethodLength
74 75 76 |
# File 'lib/mxrb/official_marketplace/lifecycle.rb', line 74 def self.find_module(mpr, name) mpr.units_by_containment('Modules').find { mpr.parse_contents(_1)['Name'] == name } end |
.read(path) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/MethodLength
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/mxrb/official_marketplace/lifecycle.rb', line 48 def self.read(path) Dir.mktmpdir('mxrb-marketplace-inspect-') do |temporary| Zip::File.open(path) do |archive| reader = ModulePackageReader.new(archive) descriptor = reader.descriptor source_path = reader.extract_project(descriptor, temporary) staged = reader.stage_files(descriptor.files, temporary) source = IO::MprFile.open(source_path, readonly: true) module_unit = find_module(source, descriptor.name) raise MarketplaceError, "module #{descriptor.name.inspect} is absent from package MPR" unless module_unit ids = subtree_ids(source, module_unit.fetch('UnitID')) files = staged.transform_values { Digest::SHA256.file(_1).hexdigest } return new( name: descriptor.name, version: descriptor.version, module_id: module_unit.fetch('UnitID'), unit_ids: ids, files: ) ensure source&.close end end rescue Zip::Error, REXML::ParseException => e raise MarketplaceError, "invalid Mendix module package: #{e.}" end |
.subtree_ids(mpr, root_id) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/mxrb/official_marketplace/lifecycle.rb', line 78 def self.subtree_ids(mpr, root_id) ids = [root_id] loop do children = mpr.all_units.filter_map do |unit| unit.fetch('UnitID') if ids.include?(unit['ContainerID']) && !ids.include?(unit.fetch('UnitID')) end break if children.empty? ids.concat(children) end ids end |