Class: Mxrb::Protocols::Plan

Inherits:
Object
  • Object
show all
Defined in:
lib/mxrb/protocols/plan.rb

Overview

Preview/apply boundary for a real official Marketplace connector. Planning never writes. Apply is available only when an authenticated Content API and an official installer were explicitly supplied by the caller.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request:, entry:, context:) ⇒ Plan

Returns a new instance of Plan.



15
16
17
18
19
20
21
22
# File 'lib/mxrb/protocols/plan.rb', line 15

def initialize(request:, entry:, context:)
  @request = request
  @entry = entry
  @mendix_version = context.fetch(:mendix_version).to_s
  @adapter = context[:adapter]
  @package = context[:package]
  @applied = false
end

Instance Attribute Details

#entryObject (readonly)

Returns the value of attribute entry.



13
14
15
# File 'lib/mxrb/protocols/plan.rb', line 13

def entry
  @entry
end

#mendix_versionObject (readonly)

Returns the value of attribute mendix_version.



13
14
15
# File 'lib/mxrb/protocols/plan.rb', line 13

def mendix_version
  @mendix_version
end

#packageObject (readonly)

Returns the value of attribute package.



13
14
15
# File 'lib/mxrb/protocols/plan.rb', line 13

def package
  @package
end

#requestObject (readonly)

Returns the value of attribute request.



13
14
15
# File 'lib/mxrb/protocols/plan.rb', line 13

def request
  @request
end

Instance Method Details

#applied?Boolean

Returns:

  • (Boolean)


41
# File 'lib/mxrb/protocols/plan.rb', line 41

def applied? = @applied

#apply!Object

Raises:



43
44
45
46
47
48
49
50
51
52
# File 'lib/mxrb/protocols/plan.rb', line 43

def apply!
  raise MarketplaceError, "connector plan is blocked: #{blocked_reasons.join('; ')}" unless safe?
  raise MarketplaceError, 'connector plan was already applied' if applied?

  result = @adapter.installer.pull_official(
    entry.marketplace_id, version: request.version, mendix_version:, api: @adapter.api
  )
  @applied = true
  result
end

#blocked_reasonsObject



33
34
35
36
37
38
# File 'lib/mxrb/protocols/plan.rb', line 33

def blocked_reasons
  [].tap do |reasons|
    reasons << 'official Marketplace adapter was not provided' unless @adapter
    reasons << 'official Marketplace version was not resolved' unless package
  end.freeze
end

#changesObject



24
25
26
27
28
29
30
31
# File 'lib/mxrb/protocols/plan.rb', line 24

def changes
  [{
    action: :install, protocol: entry.protocol, name: entry.name,
    marketplace_id: entry.marketplace_id,
    version: package&.version || request.version || 'latest-compatible',
    mendix_version:, source_url: entry.source_url
  }.freeze].freeze
end

#safe?Boolean

Returns:

  • (Boolean)


40
# File 'lib/mxrb/protocols/plan.rb', line 40

def safe? = blocked_reasons.empty?