Class: Mxrb::OfficialMarketplace::WidgetPackageInventory

Inherits:
Object
  • Object
show all
Defined in:
lib/mxrb/official_marketplace/widget_package_installer.rb

Overview

Read-only, fail-closed inventory for a clientModule MPK. rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, version:, widget_ids:, project_filename:) ⇒ WidgetPackageInventory

Returns a new instance of WidgetPackageInventory.



41
42
43
44
45
46
# File 'lib/mxrb/official_marketplace/widget_package_installer.rb', line 41

def initialize(name:, version:, widget_ids:, project_filename:)
  @name = name
  @version = version
  @widget_ids = widget_ids.freeze
  @project_filename = project_filename
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



39
40
41
# File 'lib/mxrb/official_marketplace/widget_package_installer.rb', line 39

def name
  @name
end

#project_filenameObject (readonly)

Returns the value of attribute project_filename.



39
40
41
# File 'lib/mxrb/official_marketplace/widget_package_installer.rb', line 39

def project_filename
  @project_filename
end

#versionObject (readonly)

Returns the value of attribute version.



39
40
41
# File 'lib/mxrb/official_marketplace/widget_package_installer.rb', line 39

def version
  @version
end

#widget_idsObject (readonly)

Returns the value of attribute widget_ids.



39
40
41
# File 'lib/mxrb/official_marketplace/widget_package_installer.rb', line 39

def widget_ids
  @widget_ids
end

Class Method Details

.read(path) ⇒ Object



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/widget_package_installer.rb', line 48

def self.read(path)
  Zip::File.open(path) do |archive|
    validate_entries!(archive)
    document = package_document(archive)
    clients = elements(document.root, 'clientModule')
    raise MarketplaceError, 'package.xml must declare exactly one clientModule' unless clients.one?

    client = clients.first

    name = valid_name(client.attributes['name'])
    version = valid_version(client.attributes['version'])
    widget_paths = elements(client, 'widgetFile').map do |element|
      safe_relative_path(element.attributes['path'])
    end.uniq
    raise MarketplaceError, 'widget package does not declare widgetFiles' if widget_paths.empty?

    validate_declared_files!(archive, client)
    widget_ids = widget_paths.map { widget_id(archive, _1) }
    filename = project_filename(name, widget_ids)
    new(name:, version:, widget_ids:, project_filename: filename)
  end
rescue Zip::Error, REXML::ParseException => e
  raise MarketplaceError, "invalid Mendix widget package: #{e.message}"
end