Class: ActiveJob::Notificare::Generators::ScaffoldGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/active_job/notificare/scaffold/scaffold_generator.rb

Instance Method Summary collapse

Instance Method Details

#create_controllerObject



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_localeObject



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_viewsObject



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


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_classObject



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