Class: Mxrb::ProjectLifecycle
- Inherits:
-
Object
- Object
- Mxrb::ProjectLifecycle
- Defined in:
- lib/mxrb/project_lifecycle.rb
Overview
Inspects, previews upgrades, and compares generated definitions with an MPR.
Constant Summary collapse
- VERSION =
/\A\d+\.\d+\.\d+\z/
Instance Method Summary collapse
-
#initialize(root = Dir.pwd) ⇒ ProjectLifecycle
constructor
A new instance of ProjectLifecycle.
- #inspect ⇒ Object
-
#migration_plan ⇒ Object
rubocop:disable Metrics/MethodLength.
-
#upgrade(version, apply: false) ⇒ Object
rubocop:disable Metrics/MethodLength.
Constructor Details
#initialize(root = Dir.pwd) ⇒ ProjectLifecycle
Returns a new instance of ProjectLifecycle.
15 16 17 18 |
# File 'lib/mxrb/project_lifecycle.rb', line 15 def initialize(root = Dir.pwd) @root = File.(root) @project_file = File.join(@root, 'project.rb') end |
Instance Method Details
#inspect ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/mxrb/project_lifecycle.rb', line 20 def inspect { root: @root, project_file: File.file?(@project_file), declared_version: declared_version, modules: Dir[File.join(@root, 'modules', '*', 'module.rb')].map { File.basename(File.dirname(_1)) }, mprs: Dir[File.join(@root, '*.mpr')].sort, registered_scaffolds: Scaffold::Registry.new(@root).entries.keys.sort } end |
#migration_plan ⇒ Object
rubocop:disable Metrics/MethodLength
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/mxrb/project_lifecycle.rb', line 47 def migration_plan # rubocop:disable Metrics/MethodLength current = Dir[File.join(@root, '*.mpr')].first raise ArgumentError, 'no current MPR found' unless current Dir.mktmpdir('mxrb-migration-') do |dir| generated = File.join(dir, File.basename(current)) previous = ENV['MXRB_OUTPUT_PATH'] ENV['MXRB_OUTPUT_PATH'] = generated load @project_file MigrationResult.new(current, generated, Mxrb.diff(current, generated)) ensure previous.nil? ? ENV.delete('MXRB_OUTPUT_PATH') : ENV['MXRB_OUTPUT_PATH'] = previous end end |
#upgrade(version, apply: false) ⇒ Object
rubocop:disable Metrics/MethodLength
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/mxrb/project_lifecycle.rb', line 30 def upgrade(version, apply: false) # rubocop:disable Metrics/MethodLength target = version.to_s raise ArgumentError, 'Mendix version must use MAJOR.MINOR.PATCH' unless VERSION.match?(target) source = project_source current = declared_version raise ArgumentError, 'project.rb has no mendix_version declaration' unless current if apply updated = source.sub(/mendix_version\s+["'][^"']+["']/, %(mendix_version "#{target}")) transaction = Scaffold::Transaction.new transaction.write(@project_file, updated) transaction.commit end UpgradeResult.new(@project_file, current, target, apply) end |