Class: Mxrb::RubyApp::Preset
- Inherits:
-
Object
- Object
- Mxrb::RubyApp::Preset
- Defined in:
- lib/mxrb/ruby_app/preset.rb
Overview
Adds an opt-in conventional Ruby framework around the generic MXRB Rack backend. Presets never alter the default Ruby mode and never own Mendix domain metadata; the Ruby application manifest remains authoritative. rubocop:disable Metrics
Constant Summary collapse
- NAMES =
%i[flymetothemoon onrails].freeze
- MARKER_PATH =
File.join('config', 'mxrb_stack.rb')
Class Method Summary collapse
Instance Method Summary collapse
- #apply! ⇒ Object
-
#initialize(root, name) ⇒ Preset
constructor
A new instance of Preset.
Constructor Details
#initialize(root, name) ⇒ Preset
Returns a new instance of Preset.
36 37 38 39 40 41 42 43 |
# File 'lib/mxrb/ruby_app/preset.rb', line 36 def initialize(root, name) @root = File.(root) @name = name.to_sym raise ArgumentError, "Ruby stack must be #{NAMES.join(' or ')}" unless NAMES.include?(@name) @manifest = Manifest.load(@root) @namespace = ruby_constant(@manifest.data.dig('project', 'name')) end |
Class Method Details
.apply!(root, name) ⇒ Object
16 17 18 |
# File 'lib/mxrb/ruby_app/preset.rb', line 16 def self.apply!(root, name) new(root, name).apply! end |
.detect(root) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/mxrb/ruby_app/preset.rb', line 20 def self.detect(root) path = File.join(root, MARKER_PATH) return unless File.file?(path) File.read(path)[/MXRB_RUBY_STACK\s*=\s*['"](flymetothemoon|onrails)['"]/, 1] end |
.manifest(name) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/mxrb/ruby_app/preset.rb', line 27 def self.manifest(name) selected = name.to_s { 'preset' => selected, 'rack' => true, 'server' => 'puma', 'web_framework' => selected == 'onrails' ? 'rails' : 'sinatra', 'orm' => 'active_record', 'test' => 'rspec', 'tasks' => 'rake' } end |
Instance Method Details
#apply! ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/mxrb/ruby_app/preset.rb', line 45 def apply! ensure_gems write(MARKER_PATH, marker_source, replace_baseline: true) name == :onrails ? write_rails : write_flymetothemoon update_manifest append_readme root end |