Class: Nextgen::RailsOptions
- Inherits:
-
Object
- Object
- Nextgen::RailsOptions
- Extended by:
- Forwardable
- Defined in:
- lib/nextgen/rails_options.rb
Constant Summary collapse
- TEST_FRAMEWORKS =
%i[minitest rspec].freeze
- FRAMEWORKS =
%i[ action_mailer action_mailbox action_text active_job active_storage action_cable hotwire jbuilder ].freeze
- JS_PACKAGE_MANAGERS =
%i[npm yarn].freeze
Instance Attribute Summary collapse
-
#asset_pipeline ⇒ Object
Returns the value of attribute asset_pipeline.
-
#css ⇒ Object
Returns the value of attribute css.
-
#database ⇒ Object
Returns the value of attribute database.
-
#javascript ⇒ Object
Returns the value of attribute javascript.
-
#js_package_manager ⇒ Object
Returns the value of attribute js_package_manager.
-
#test_framework ⇒ Object
Returns the value of attribute test_framework.
Instance Method Summary collapse
- #action_mailer? ⇒ Boolean
- #active_job? ⇒ Boolean
- #active_record? ⇒ Boolean
- #api! ⇒ Object
- #api? ⇒ Boolean
- #devcontainer! ⇒ Object
- #enable_optional_feature!(feature) ⇒ Object
- #frontend? ⇒ Boolean
-
#initialize(version:) ⇒ RailsOptions
constructor
A new instance of RailsOptions.
- #minitest? ⇒ Boolean
- #npm? ⇒ Boolean
- #postgresql? ⇒ Boolean
- #requires_node? ⇒ Boolean
- #rspec? ⇒ Boolean
- #rubocop? ⇒ Boolean
- #skip_active_record? ⇒ Boolean
- #skip_asset_pipeline? ⇒ Boolean
- #skip_default_feature!(feature) ⇒ Object
- #skip_default_feature?(feature) ⇒ Boolean
- #skip_javascript? ⇒ Boolean
- #skip_kamal? ⇒ Boolean
- #skip_solid? ⇒ Boolean
- #skip_system_test! ⇒ Object
- #skip_system_test? ⇒ Boolean
- #skip_test? ⇒ Boolean
- #system_testing? ⇒ Boolean
- #test_framework? ⇒ Boolean
-
#to_args ⇒ Object
rubocop:disable Metrics/PerceivedComplexity.
- #version_label ⇒ Object
- #vite! ⇒ Object
- #vite? ⇒ Boolean
Constructor Details
#initialize(version:) ⇒ RailsOptions
Returns a new instance of RailsOptions.
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/nextgen/rails_options.rb', line 28 def initialize(version:) @version = version @api = false @vite = false @enable_features = [] @skip_features = [] @skip_system_test = false @test_framework = :minitest @js_package_manager = :yarn end |
Instance Attribute Details
#asset_pipeline ⇒ Object
Returns the value of attribute asset_pipeline.
24 25 26 |
# File 'lib/nextgen/rails_options.rb', line 24 def asset_pipeline @asset_pipeline end |
#css ⇒ Object
Returns the value of attribute css.
24 25 26 |
# File 'lib/nextgen/rails_options.rb', line 24 def css @css end |
#database ⇒ Object
Returns the value of attribute database.
24 25 26 |
# File 'lib/nextgen/rails_options.rb', line 24 def database @database end |
#javascript ⇒ Object
Returns the value of attribute javascript.
24 25 26 |
# File 'lib/nextgen/rails_options.rb', line 24 def javascript @javascript end |
#js_package_manager ⇒ Object
Returns the value of attribute js_package_manager.
24 25 26 |
# File 'lib/nextgen/rails_options.rb', line 24 def js_package_manager @js_package_manager end |
#test_framework ⇒ Object
Returns the value of attribute test_framework.
24 25 26 |
# File 'lib/nextgen/rails_options.rb', line 24 def test_framework @test_framework end |
Instance Method Details
#action_mailer? ⇒ Boolean
170 171 172 |
# File 'lib/nextgen/rails_options.rb', line 170 def action_mailer? !skip_default_feature?(:action_mailer) end |
#active_job? ⇒ Boolean
174 175 176 |
# File 'lib/nextgen/rails_options.rb', line 174 def active_job? !skip_default_feature?(:active_job) end |
#active_record? ⇒ Boolean
142 143 144 |
# File 'lib/nextgen/rails_options.rb', line 142 def active_record? !skip_active_record? end |
#api! ⇒ Object
111 112 113 114 115 116 |
# File 'lib/nextgen/rails_options.rb', line 111 def api! raise ArgumentError, "Can't specify API mode if css is already specified" if css raise ArgumentError, "Can't specify API mode if javascript is already specified" if javascript @api = true end |
#api? ⇒ Boolean
118 119 120 |
# File 'lib/nextgen/rails_options.rb', line 118 def api? @api end |
#devcontainer! ⇒ Object
107 108 109 |
# File 'lib/nextgen/rails_options.rb', line 107 def devcontainer! @devcontainer = true end |
#enable_optional_feature!(feature) ⇒ Object
187 188 189 190 191 |
# File 'lib/nextgen/rails_options.rb', line 187 def enable_optional_feature!(feature) raise ArgumentError, "Unknown feature: #{feature}" unless optional_features.include?(feature) enable_features << feature end |
#frontend? ⇒ Boolean
122 123 124 |
# File 'lib/nextgen/rails_options.rb', line 122 def frontend? !api? end |
#minitest? ⇒ Boolean
130 131 132 |
# File 'lib/nextgen/rails_options.rb', line 130 def minitest? @test_framework == :minitest end |
#npm? ⇒ Boolean
69 70 71 |
# File 'lib/nextgen/rails_options.rb', line 69 def npm? js_package_manager == :npm end |
#postgresql? ⇒ Boolean
93 94 95 |
# File 'lib/nextgen/rails_options.rb', line 93 def postgresql? database == :postgresql end |
#requires_node? ⇒ Boolean
126 127 128 |
# File 'lib/nextgen/rails_options.rb', line 126 def requires_node? %w[bootstrap bulma postcss sass].include?(css) || %w[webpack esbuild rollup].include?(javascript) end |
#rspec? ⇒ Boolean
134 135 136 |
# File 'lib/nextgen/rails_options.rb', line 134 def rspec? @test_framework == :rspec end |
#rubocop? ⇒ Boolean
138 139 140 |
# File 'lib/nextgen/rails_options.rb', line 138 def rubocop? !skip_default_feature?(:rubocop) end |
#skip_active_record? ⇒ Boolean
146 147 148 |
# File 'lib/nextgen/rails_options.rb', line 146 def skip_active_record? defined?(@database) && @database.nil? end |
#skip_asset_pipeline? ⇒ Boolean
150 151 152 |
# File 'lib/nextgen/rails_options.rb', line 150 def skip_asset_pipeline? defined?(@asset_pipeline) && @asset_pipeline.nil? end |
#skip_default_feature!(feature) ⇒ Object
193 194 195 196 197 |
# File 'lib/nextgen/rails_options.rb', line 193 def skip_default_feature!(feature) raise ArgumentError, "Unknown feature: #{feature}" unless skippable_features.include?(feature) skip_features << feature end |
#skip_default_feature?(feature) ⇒ Boolean
199 200 201 202 203 |
# File 'lib/nextgen/rails_options.rb', line 199 def skip_default_feature?(feature) raise ArgumentError, "Unknown feature: #{feature}" unless skippable_features.include?(feature) skip_features.include?(feature) end |
#skip_javascript? ⇒ Boolean
83 84 85 |
# File 'lib/nextgen/rails_options.rb', line 83 def skip_javascript? defined?(@javascript) && @javascript.nil? end |
#skip_kamal? ⇒ Boolean
178 179 180 181 |
# File 'lib/nextgen/rails_options.rb', line 178 def skip_kamal? # Depending on the Rails version, kamal may not exist, in which case we can consider it "skipped". !skippable_features.include?(:kamal) || skip_default_feature?(:kamal) end |
#skip_solid? ⇒ Boolean
183 184 185 |
# File 'lib/nextgen/rails_options.rb', line 183 def skip_solid? !skippable_features.include?(:solid) || skip_default_feature?(:solid) end |
#skip_system_test! ⇒ Object
154 155 156 |
# File 'lib/nextgen/rails_options.rb', line 154 def skip_system_test! @skip_system_test = true end |
#skip_system_test? ⇒ Boolean
158 159 160 |
# File 'lib/nextgen/rails_options.rb', line 158 def skip_system_test? @skip_system_test end |
#skip_test? ⇒ Boolean
162 163 164 |
# File 'lib/nextgen/rails_options.rb', line 162 def skip_test? defined?(@test_framework) && [nil, :rspec].include?(@test_framework) end |
#system_testing? ⇒ Boolean
166 167 168 |
# File 'lib/nextgen/rails_options.rb', line 166 def system_testing? !(api? || test_framework.nil? || skip_system_test?) end |
#test_framework? ⇒ Boolean
103 104 105 |
# File 'lib/nextgen/rails_options.rb', line 103 def test_framework? !!@test_framework end |
#to_args ⇒ Object
rubocop:disable Metrics/PerceivedComplexity
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/nextgen/rails_options.rb', line 205 def to_args # rubocop:disable Metrics/PerceivedComplexity [].tap do |args| args.push(*version.args) args << "--api" if api? args << "--skip-active-record" if skip_active_record? args << "--skip-asset-pipeline" if skip_asset_pipeline? args << "--skip-javascript" if skip_javascript? args << "--skip-test" if skip_test? args << "--skip-system-test" if skip_system_test? args << "--asset-pipeline=#{asset_pipeline}" if asset_pipeline && asset_pipeline != asset_pipelines.keys.first args << "--database=#{database}" if database args << "--css=#{css}" if css args << "--javascript=#{javascript}" if javascript args.push(*enable_features.map { "--#{_1.to_s.tr("_", "-")}" }) args.push(*skip_features.map { "--skip-#{_1.to_s.tr("_", "-")}" }) end end |
#version_label ⇒ Object
39 40 41 |
# File 'lib/nextgen/rails_options.rb', line 39 def version_label version.label end |
#vite! ⇒ Object
73 74 75 76 77 |
# File 'lib/nextgen/rails_options.rb', line 73 def vite! self.asset_pipeline = nil @javascript = "esbuild" @vite = true end |
#vite? ⇒ Boolean
79 80 81 |
# File 'lib/nextgen/rails_options.rb', line 79 def vite? @vite end |