Class: PracticalPig::CLI

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/practical/pig/cli.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#app_nameObject

Returns the value of attribute app_name.



18
19
20
# File 'lib/practical/pig/cli.rb', line 18

def app_name
  @app_name
end

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/practical/pig/cli.rb', line 72

def self.exit_on_failure?
  true
end

.source_rootObject



68
69
70
# File 'lib/practical/pig/cli.rb', line 68

def self.source_root
  File.join(__dir__, "../../template")
end

Instance Method Details

#new(app_path) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/practical/pig/cli.rb', line 37

def new(app_path)
  # ensure that applications are not requests for help, or that their names follow the
  # appropriate format
  if Thor::HELP_MAPPINGS.include?(app_path) || (flag = !app_path.match?(NAME_PATTERN))
    if flag
      say <<~MSG.squish
        \e[31mBy design, your application name must start and end with an alphanumeric
        character.\e[0m
      MSG
      say
    end

    help("new")
    return
  end

  # generate a Rails application, omitting many things
  run(
    <<~CMD.squish
      rails new #{app_path} -GMPCSJB --database=postgresql --skip-gemfile --skip-keeps
      #{" --quiet" if options[:quiet]} --skip-action-mailbox --skip-system-test
      --skip-action-text --skip-active-storage --skip-turbolinks
    CMD
  )

  app_root = File.join(Dir.pwd, app_path)
  @app_name = File.basename(app_root)

  generate(app_root)
end