Class: RailsAppGenerator::Cli::Profile

Inherits:
Thor
  • Object
show all
Defined in:
lib/rails_app_generator/cli/profile.rb

Overview

Folder Diff

Instance Method Summary collapse

Instance Method Details

#profile(name) ⇒ Object

rubocop:disable Metrics/AbcSize



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rails_app_generator/cli/profile.rb', line 13

def profile(name)
  path          = options[:profile_path] || options[:fallback_profile_path]
  profile_name  = name.end_with?('.json') ? name : "#{name}.json"
  profile_file  = File.join(path, profile_name)

  unless File.exist?(profile_file)
    puts "Profile [#{profile_file}] not found"
    exit 1
  end

  puts "Using profile #{profile_file}"

  profile       = JSON.parse(File.read(profile_file), symbolize_names: true)
  args          = profile[:args]
  opts          = RailsAppGenerator::RailsOptions.new(profile[:opts])

  RailsAppGenerator::Util.write_last_run('rails_options_data.json', opts.to_h)

  starter = RailsAppGenerator::Starter.new(**args)
  starter.start(opts) if starter.handle_target_folder_found?
end