Class: ActiveJob::Notificare::Generators::ScaffoldGenerator
- Inherits:
-
Rails::Generators::NamedBase
- Object
- Rails::Generators::NamedBase
- ActiveJob::Notificare::Generators::ScaffoldGenerator
- Defined in:
- lib/generators/active_job/notificare/scaffold/scaffold_generator.rb
Instance Method Summary collapse
- #create_controller ⇒ Object
- #create_locale ⇒ Object
- #create_views ⇒ Object
- #print_routes_snippet ⇒ Object
- #validate_job_class ⇒ Object
Instance Method Details
#create_controller ⇒ Object
31 32 33 34 |
# File 'lib/generators/active_job/notificare/scaffold/scaffold_generator.rb', line 31 def create_controller return if @invalid template "controller.rb.tt", "app/controllers/#{prefix}_controller.rb" end |
#create_locale ⇒ Object
42 43 44 45 |
# File 'lib/generators/active_job/notificare/scaffold/scaffold_generator.rb', line 42 def create_locale return if @invalid template "locale.en.yml.tt", "config/locales/active_job_notificare_#{prefix}.en.yml" end |
#create_views ⇒ Object
36 37 38 39 40 |
# File 'lib/generators/active_job/notificare/scaffold/scaffold_generator.rb', line 36 def create_views return if @invalid template "index.html.erb.tt", "app/views/#{prefix}/index.html.erb" template "show.html.erb.tt", "app/views/#{prefix}/show.html.erb" end |
#print_routes_snippet ⇒ Object
47 48 49 50 51 52 |
# File 'lib/generators/active_job/notificare/scaffold/scaffold_generator.rb', line 47 def print_routes_snippet return if @invalid say "\nPaste into config/routes.rb:\n\n" say " resources :#{prefix}, only: [:index, :show]", :green say "" end |
#validate_job_class ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/generators/active_job/notificare/scaffold/scaffold_generator.rb', line 14 def validate_job_class klass = class_name.constantize unless klass.ancestors.include?(::ActiveJob::Notificare) say_status :error, "#{class_name} does not include ActiveJob::Notificare. " \ "Add `include ActiveJob::Notificare` to the job class and re-run the generator.", :red @invalid = true end rescue NameError say_status :error, "#{class_name} could not be loaded. " \ "Make sure the job class exists and includes `include ActiveJob::Notificare`.", :red @invalid = true end |