Class: Mxrb::Protocols::Plan
- Inherits:
-
Object
- Object
- Mxrb::Protocols::Plan
- 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
-
#entry ⇒ Object
readonly
Returns the value of attribute entry.
-
#mendix_version ⇒ Object
readonly
Returns the value of attribute mendix_version.
-
#package ⇒ Object
readonly
Returns the value of attribute package.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
Instance Method Summary collapse
- #applied? ⇒ Boolean
- #apply! ⇒ Object
- #blocked_reasons ⇒ Object
- #changes ⇒ Object
-
#initialize(request:, entry:, context:) ⇒ Plan
constructor
A new instance of Plan.
- #safe? ⇒ Boolean
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
#entry ⇒ Object (readonly)
Returns the value of attribute entry.
13 14 15 |
# File 'lib/mxrb/protocols/plan.rb', line 13 def entry @entry end |
#mendix_version ⇒ Object (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 |
#package ⇒ Object (readonly)
Returns the value of attribute package.
13 14 15 |
# File 'lib/mxrb/protocols/plan.rb', line 13 def package @package end |
#request ⇒ Object (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
41 |
# File 'lib/mxrb/protocols/plan.rb', line 41 def applied? = @applied |
#apply! ⇒ Object
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_reasons ⇒ Object
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 |
#changes ⇒ Object
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
40 |
# File 'lib/mxrb/protocols/plan.rb', line 40 def safe? = blocked_reasons.empty? |