File: notifier_generator.rb

package info (click to toggle)
ruby-noticed 3.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 324 kB
  • sloc: ruby: 1,186; makefile: 4
file content (32 lines) | stat: -rw-r--r-- 825 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# frozen_string_literal: true

require "rails/generators/named_base"

module Noticed
  module Generators
    class NotifierGenerator < Rails::Generators::NamedBase
      include Rails::Generators::ResourceHelpers

      check_class_collision suffix: "Notifier"

      source_root File.expand_path("../templates", __FILE__)

      desc "Generates a notification with the given NAME."

      def generate_abstract_class
        return if File.exist?("app/notifiers/application_notifier.rb")
        template "application_notifier.rb", "app/notifiers/application_notifier.rb"
      end

      def generate_notification
        template "notifier.rb", "app/notifiers/#{file_path}_notifier.rb"
      end

      private

      def file_name # :doc:
        @_file_name ||= super.sub(/_notifier\z/i, "")
      end
    end
  end
end