Class: RailsAppGenerator::AppGenerator
- Inherits:
-
Rails::Generators::AppGenerator
- Object
- Rails::Generators::AppGenerator
- RailsAppGenerator::AppGenerator
- Defined in:
- lib/rails_app_generator/app_generator.rb
Overview
AppGenerator is a wrapper for Rails::AppGenerator
Class Attribute Summary collapse
Instance Attribute Summary collapse
-
#addon_instances ⇒ Object
readonly
Returns the value of attribute addon_instances.
Class Method Summary collapse
Instance Method Summary collapse
-
#apply_rails_template ⇒ Object
Fire any callbacks defined on addons either before running the custom template.
-
#create_root_files ⇒ Object
def xxx_generate_default puts ‘xxx_generate_default’ # run(“spring stop > /dev/null 2>&1 || true”) generate(“rails_app_generator:foo”) # generate(“suspenders:runner”) # generate(“suspenders:profiler”) # generate(“suspenders:json”) # generate(“suspenders:static”) # generate(“suspenders:stylesheet_base”) unless options # generate(“suspenders:testing”) # generate(“suspenders:ci”) # generate(“suspenders:js_driver”) # generate(“suspenders:forms”) unless options # generate(“suspenders:db_optimizations”) # generate(“suspenders:factories”) # generate(“suspenders:lint”) # generate(“suspenders:jobs”) # generate(“suspenders:analytics”) # generate(“suspenders:inline_svg”) # generate(“suspenders:advisories”) end.
- #create_test_files ⇒ Object
-
#finish_template ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/MethodLength.
-
#initialize(*args) ⇒ AppGenerator
constructor
A new instance of AppGenerator.
-
#run_after_bundle_callbacks ⇒ Object
Fire any callbacks defined on addons either before or after the standard callbacks.
Constructor Details
#initialize(*args) ⇒ AppGenerator
Returns a new instance of AppGenerator.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/rails_app_generator/app_generator.rb', line 80 def initialize(*args) super @force_copy = false @addon_instances = [] # puts '----------------------------------------------------' # puts options # puts '----------------------------------------------------' # return unless options[:api] # self.options = options.merge( # skip_errors: true, # skip_high_voltage: true, # skip_stimulus: true, # skip_tailwind: true, # skip_views: true # ).freeze end |
Class Attribute Details
.addon_template_path ⇒ Object
24 25 26 |
# File 'lib/rails_app_generator/app_generator.rb', line 24 def addon_template_path @addon_template_path ||= gem_template_path('rails_app_generator', 'templates/addons/%<addon>s') end |
.override_template_path ⇒ Object
17 18 19 |
# File 'lib/rails_app_generator/app_generator.rb', line 17 def override_template_path @override_template_path ||= gem_template_path('rails_app_generator', 'templates') end |
.rails_template_path ⇒ Object
10 11 12 |
# File 'lib/rails_app_generator/app_generator.rb', line 10 def rails_template_path @rails_template_path ||= gem_template_path('railties', 'lib/rails/generators/rails/app/templates') end |
Instance Attribute Details
#addon_instances ⇒ Object (readonly)
Returns the value of attribute addon_instances.
78 79 80 |
# File 'lib/rails_app_generator/app_generator.rb', line 78 def addon_instances @addon_instances end |
Class Method Details
.add_class_option(option) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rails_app_generator/app_generator.rb', line 28 def add_class_option(option) find_name = option.name.to_s existing_option = .find { |class_option| class_option[1].name == find_name } return if existing_option args = { type: option.type, default: option.default, required: option.required } # for some reason, Railties uses :desc while thor uses :description and thor has nice humanization when key is missing args[:desc] = option.description unless option.description class_option(option.name, **args) end |
.to_h ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rails_app_generator/app_generator.rb', line 46 def to_h = .map { |o| o[1] } = RailsAppGenerator::Util.() # class_options_detailed: options_hash, { class_option_keys: .map { |option| option[:name] }, class_options: .map { |option| option.slice(:name, :description, :type, :default, :required) } } end |
Instance Method Details
#apply_rails_template ⇒ Object
Fire any callbacks defined on addons either before running the custom template
224 225 226 227 228 229 230 231 |
# File 'lib/rails_app_generator/app_generator.rb', line 224 def apply_rails_template # currently running prepare_environment in the template # this is doing a bundle install # unfortunately this bundle install happens before the normal bundle install, but for now # I have to do it until I figure out the why I need the prepare_environment method anyway. addon_instances.select { |addon| addon.respond_to?(:before_template) }.each(&:before_template) super end |
#create_root_files ⇒ Object
def xxx_generate_default
puts 'xxx_generate_default'
# run("spring stop > /dev/null 2>&1 || true")
generate("rails_app_generator:foo")
# generate("suspenders:runner")
# generate("suspenders:profiler")
# generate("suspenders:json")
# generate("suspenders:static")
# generate("suspenders:stylesheet_base") unless options[:api]
# generate("suspenders:testing")
# generate("suspenders:ci")
# generate("suspenders:js_driver")
# generate("suspenders:forms") unless options[:api]
# generate("suspenders:db_optimizations")
# generate("suspenders:factories")
# generate("suspenders:lint")
# generate("suspenders:jobs")
# generate("suspenders:analytics")
# generate("suspenders:inline_svg")
# generate("suspenders:advisories")
end
141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/rails_app_generator/app_generator.rb', line 141 def create_root_files RailsAppGenerator::Util.write_last_run('app_generator_data.json', to_h) super add_if(:irbrc) add_if(:foreman) add_if(:dotenv) add_if(:docker) add_if(:docker_compose) add_if(:rubocop) end |
#create_test_files ⇒ Object
154 155 156 157 158 159 160 |
# File 'lib/rails_app_generator/app_generator.rb', line 154 def create_test_files return if [:skip_test] super if [:test] == 'minitest' add(:rspec) if active?(:rspec) || [:test] == 'rspec' end |
#finish_template ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/MethodLength
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/rails_app_generator/app_generator.rb', line 163 def finish_template puts 'finish template' # https://github.com/AaronLasseigne/active_interaction add_if(:acts_as_list) # tested add_if(:administrate) # tested add_if(:annotate) # tested add_if(:avo) # tested add_if(:bcrypt) # tested add_if(:brakeman) # tested add_if(:browser) # tested add_if(:bundler_audit) # tested add_if(:chartkick) # tested add_if(:continuous_integration) # TODO: needs work add_if(:devise) # tested add_if(:devise_masquerade) # tested # docker_compose # docker add_if(:dotenv) # tested add_if(:factory_bot) # TODO: needs testing add_if(:factory_bot_rails) # tested add_if(:faker) # tested add_if(:friendly_id) # tested add_if(:generators) # TODO: needs testing add_if(:groupdate) # TODO: does not have a profile add_if(:hexapdf) # tested add_if(:httparty) # tested add_if(:high_voltage) # TODO: needs testing add_if(:honeybadger) # tested add_if(:image_processing) # TODO: needs testing # https://github.com/collectiveidea/interactor add_if(:kaminari) # tested add_if(:lograge) # tested add_if(:minimal_css) # tested (this is NOT a GEM) add_if(:mini_magick) # tested add_if(:motor_magick) # tested add_if(:phony_rails) # tested add_if(:pretender) # tested add_if(:public_suffix) # tested add_if(:pundit) # TODO: needs testing add_if(:rails_html_sanitizer) # tested add_if(:rails_app_generator) # TODO: needs testing add_if(:redcarpet) # tested add_if(:rolify) # tested add_if(:scenic) # add_if(:rspec) # see: create_test_filers add_if(:services) # TODO: needs testing add_if(:shoulda) # TODO: needs testing add_if(:sidekiq) # TODO: needs testing add_if(:ransack) # TODO: needs testing add_if(:rubocop) # tested add_if(:twilio_ruby) # tested add_if(:view_component) add(:views, :errors, :scaffold) if active?(:views) # invoke :rails_customization super end |
#run_after_bundle_callbacks ⇒ Object
Fire any callbacks defined on addons either before or after the standard callbacks
234 235 236 237 238 |
# File 'lib/rails_app_generator/app_generator.rb', line 234 def run_after_bundle_callbacks addon_instances.select { |addon| addon.respond_to?(:before_bundle) }.each(&:before_bundle) super addon_instances.select { |addon| addon.respond_to?(:after_bundle) }.each(&:after_bundle) end |