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/- VERSION_DECLARATION =
/(?<prefix>mendix_version(?:\s+|\s*=\s*))["'](?<version>[^"']+)["']/
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.
16 17 18 19 |
# File 'lib/mxrb/project_lifecycle.rb', line 16 def initialize(root = Dir.pwd) @root = File.(root) @project_file = File.join(@root, 'project.rb') end |
Instance Method Details
#inspect ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/mxrb/project_lifecycle.rb', line 21 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
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/mxrb/project_lifecycle.rb', line 50 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
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/mxrb/project_lifecycle.rb', line 31 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(VERSION_DECLARATION) do "#{Regexp.last_match(:prefix)}\"#{target}\"" end transaction = Scaffold::Transaction.new transaction.write(@project_file, updated) transaction.commit end UpgradeResult.new(@project_file, current, target, apply) end |