Class: RailsApp::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_app/command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_name, args) ⇒ Command

Returns a new instance of Command.



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/rails_app/command.rb', line 5

def initialize(app_name, args)
  # puts "args: #{args}"
  @app_name = app_name
  @assets = args[:assets]
  @styling = args[:styling]
  @database = args[:database]
  @skip_spring = args[:skip_spring]
  @skip_action_mailer = args[:action_mailer]
  @skip_action_mailbox = args[:action_mailbox]
  @skip_action_text = args[:action_text]
  @skip_action_storage = args[:action_storage]
  @skip_action_cable = args[:action_cable]
end

Instance Attribute Details

#app_nameObject (readonly)

Returns the value of attribute app_name.



3
4
5
# File 'lib/rails_app/command.rb', line 3

def app_name
  @app_name
end

#assetsObject (readonly)

Returns the value of attribute assets.



3
4
5
# File 'lib/rails_app/command.rb', line 3

def assets
  @assets
end

#databaseObject (readonly)

Returns the value of attribute database.



3
4
5
# File 'lib/rails_app/command.rb', line 3

def database
  @database
end

#stylingObject (readonly)

Returns the value of attribute styling.



3
4
5
# File 'lib/rails_app/command.rb', line 3

def styling
  @styling
end

Instance Method Details

#asset_managementObject



62
63
64
# File 'lib/rails_app/command.rb', line 62

def asset_management
  "-a propshaft" unless assets == "sprockets"
end

#database_adapterObject



54
55
56
# File 'lib/rails_app/command.rb', line 54

def database_adapter
  "-d #{@database}" unless database == "sqlite3"
end

#javascript_bundlingObject



58
59
60
# File 'lib/rails_app/command.rb', line 58

def javascript_bundling
  "-j esbuild"
end

#runObject



23
24
25
26
27
28
# File 'lib/rails_app/command.rb', line 23

def run
  command = "rails new #{@app_name} --no-rc #{skip_spring} #{skip_action_mailer} #{skip_action_mailbox} #{skip_action_text} #{skip_action_text} #{skip_action_cable} #{database_adapter} #{asset_management} #{javascript_bundling} #{styling_framework} #{testing_framework} -m #{template}"
  command.squeeze!(" ")
  # puts command
  system(command)
end

#skip_action_cableObject



50
51
52
# File 'lib/rails_app/command.rb', line 50

def skip_action_cable
  "--skip-action-cable" if @skip_action_cable == true
end

#skip_action_mailboxObject



38
39
40
# File 'lib/rails_app/command.rb', line 38

def skip_action_mailbox
  "--skip-action-mailbox" if @skip_action_mailbox == true
end

#skip_action_mailerObject



34
35
36
# File 'lib/rails_app/command.rb', line 34

def skip_action_mailer
  "--skip-action-mailer" if @skip_action_mailer == true
end

#skip_action_storageObject



46
47
48
# File 'lib/rails_app/command.rb', line 46

def skip_action_storage
  "--skip-active-storage" if @skip_action_storage == true
end

#skip_action_textObject



42
43
44
# File 'lib/rails_app/command.rb', line 42

def skip_action_text
  "--skip-action-text" if @skip_action_text == true
end

#skip_springObject



30
31
32
# File 'lib/rails_app/command.rb', line 30

def skip_spring
  "--skip-spring" if @skip_spring == true
end

#styling_frameworkObject



66
67
68
# File 'lib/rails_app/command.rb', line 66

def styling_framework
  "--css #{@styling}"
end

#templateObject



19
20
21
# File 'lib/rails_app/command.rb', line 19

def template
  File.join(__dir__, "template", "template.rb")
end

#testing_frameworkObject



70
71
72
# File 'lib/rails_app/command.rb', line 70

def testing_framework
  "-T"
end