Class: Mxrb::Frontend::MigrationPlan
- Inherits:
-
Object
- Object
- Mxrb::Frontend::MigrationPlan
- Defined in:
- lib/mxrb/frontend/migrator.rb
Overview
Immutable, fail-closed preview of frontend model migrations. rubocop:disable Metrics/AbcSize, Metrics/MethodLength
Instance Attribute Summary collapse
-
#changes ⇒ Object
readonly
Returns the value of attribute changes.
-
#issues ⇒ Object
readonly
Returns the value of attribute issues.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #applied? ⇒ Boolean
- #apply! ⇒ Object
- #design_properties ⇒ Object
-
#initialize(path:, version:, changes:, issues:) ⇒ MigrationPlan
constructor
A new instance of MigrationPlan.
- #layout_rows ⇒ Object
- #safe? ⇒ Boolean
- #widgets ⇒ Object
Constructor Details
#initialize(path:, version:, changes:, issues:) ⇒ MigrationPlan
Returns a new instance of MigrationPlan.
18 19 20 21 22 23 24 |
# File 'lib/mxrb/frontend/migrator.rb', line 18 def initialize(path:, version:, changes:, issues:) @path = path @version = version @changes = changes.freeze @issues = issues.freeze @applied = false end |
Instance Attribute Details
#changes ⇒ Object (readonly)
Returns the value of attribute changes.
16 17 18 |
# File 'lib/mxrb/frontend/migrator.rb', line 16 def changes @changes end |
#issues ⇒ Object (readonly)
Returns the value of attribute issues.
16 17 18 |
# File 'lib/mxrb/frontend/migrator.rb', line 16 def issues @issues end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
16 17 18 |
# File 'lib/mxrb/frontend/migrator.rb', line 16 def path @path end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
16 17 18 |
# File 'lib/mxrb/frontend/migrator.rb', line 16 def version @version end |
Instance Method Details
#applied? ⇒ Boolean
27 |
# File 'lib/mxrb/frontend/migrator.rb', line 27 def applied? = @applied |
#apply! ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/mxrb/frontend/migrator.rb', line 32 def apply! raise SerializationError, unless safe? raise SerializationError, 'frontend migration plan was already applied' if applied? mpr = IO::MprFile.open(path) mpr.transaction do changes.each do |change| current = mpr.unit(change.unit_id) raise SerializationError, "frontend unit disappeared: #{change.unit_id}" unless current raise SerializationError, "frontend unit changed after preview: #{change.unit_id}" unless current['ContentsHash'] == change.before_hash mpr.update_unit(change.unit_id, change.after) end end @applied = true self ensure mpr&.close end |
#design_properties ⇒ Object
30 |
# File 'lib/mxrb/frontend/migrator.rb', line 30 def design_properties = changes.sum(&:design_properties) |
#layout_rows ⇒ Object
29 |
# File 'lib/mxrb/frontend/migrator.rb', line 29 def layout_rows = changes.sum(&:layout_rows) |
#safe? ⇒ Boolean
26 |
# File 'lib/mxrb/frontend/migrator.rb', line 26 def safe? = issues.empty? |
#widgets ⇒ Object
28 |
# File 'lib/mxrb/frontend/migrator.rb', line 28 def = changes.sum(&:widgets) |