The plugin builder allows you to override elements of the plugin generator without being forced to reverse the operations of the default generator.

This allows you to override entire operations, like the creation of the Gemfile, README, or JavaScript files, without needing to know exactly what those operations do so you can create another template action.

Methods

Constants

DUMMY_IGNORE_OPTIONS = %i[dev edge master template]

Instance Public methods

app()

📝 Source code
# File railties/lib/rails/generators/rails/plugin/plugin_generator.rb, line 20
    def app
      if mountable?
        if api?
          directory "app", exclude_pattern: %r{app/(views|helpers)}
        else
          directory "app"
          empty_directory_with_keep_file "app/assets/images/#{namespaced_name}"
        end

        remove_dir "app/mailers" if options[:skip_action_mailer]
        remove_dir "app/jobs" if options[:skip_active_job]
      elsif full?
        empty_directory_with_keep_file "app/models"
        empty_directory_with_keep_file "app/controllers"
        empty_directory_with_keep_file "app/mailers" unless options[:skip_action_mailer]
        empty_directory_with_keep_file "app/jobs" unless options[:skip_active_job]

        unless api?
          empty_directory_with_keep_file "app/assets/images/#{namespaced_name}"
          empty_directory_with_keep_file "app/helpers"
          empty_directory_with_keep_file "app/views"
        end
      end
    end
🔎 See on GitHub

assets_manifest()

📝 Source code
# File railties/lib/rails/generators/rails/plugin/plugin_generator.rb, line 148
    def assets_manifest
      template "rails/engine_manifest.js", "app/assets/config/#{underscored_name}_manifest.js"
    end
🔎 See on GitHub

bin(force = false)

📝 Source code
# File railties/lib/rails/generators/rails/plugin/plugin_generator.rb, line 161
    def bin(force = false)
      bin_file = engine? ? "bin/rails.tt" : "bin/test.tt"
      template bin_file, force: force do |content|
        "#{shebang}\n" + content
      end
      chmod "bin", 0755, verbose: false
    end
🔎 See on GitHub

config()

📝 Source code
# File railties/lib/rails/generators/rails/plugin/plugin_generator.rb, line 83
    def config
      template "config/routes.rb" if engine?
    end
🔎 See on GitHub

gemfile()

📝 Source code
# File railties/lib/rails/generators/rails/plugin/plugin_generator.rb, line 49
    def gemfile
      template "Gemfile"
    end
🔎 See on GitHub

gemfile_entry()

📝 Source code
# File railties/lib/rails/generators/rails/plugin/plugin_generator.rb, line 169
    def gemfile_entry
      return unless inside_application?

      gemfile_in_app_path = File.join(rails_app_path, "Gemfile")
      if File.exist? gemfile_in_app_path
        entry = "\ngem '#{name}', path: '#{relative_path}'"
        append_file gemfile_in_app_path, entry
      end
    end
🔎 See on GitHub

gemspec()

📝 Source code
# File railties/lib/rails/generators/rails/plugin/plugin_generator.rb, line 57
    def gemspec
      template "%name%.gemspec"
    end
🔎 See on GitHub

generate_test_dummy(force = false)

📝 Source code
# File railties/lib/rails/generators/rails/plugin/plugin_generator.rb, line 102
    def generate_test_dummy(force = false)
      opts = options.transform_keys(&:to_sym).except(*DUMMY_IGNORE_OPTIONS)
      opts[:force] = force
      opts[:skip_bundle] = true
      opts[:skip_spring] = true
      opts[:skip_listen] = true
      opts[:skip_git] = true
      opts[:skip_turbolinks] = true
      opts[:skip_webpack_install] = true
      opts[:dummy_app] = true

      invoke Rails::Generators::AppGenerator,
        [ File.expand_path(dummy_path, destination_root) ], opts
    end
🔎 See on GitHub

gitignore()

📝 Source code
# File railties/lib/rails/generators/rails/plugin/plugin_generator.rb, line 61
    def gitignore
      template "gitignore", ".gitignore"
    end
🔎 See on GitHub

lib()

📝 Source code
# File railties/lib/rails/generators/rails/plugin/plugin_generator.rb, line 71
    def lib
      template "lib/%namespaced_name%.rb"
      template "lib/tasks/%namespaced_name%_tasks.rake"
      template "lib/%namespaced_name%/version.rb"

      if engine?
        template "lib/%namespaced_name%/engine.rb"
      else
        template "lib/%namespaced_name%/railtie.rb"
      end
    end
🔎 See on GitHub

license()

📝 Source code
# File railties/lib/rails/generators/rails/plugin/plugin_generator.rb, line 53
    def license
      template "MIT-LICENSE"
    end
🔎 See on GitHub

rakefile()

📝 Source code
# File railties/lib/rails/generators/rails/plugin/plugin_generator.rb, line 16
    def rakefile
      template "Rakefile"
    end
🔎 See on GitHub

readme()

📝 Source code
# File railties/lib/rails/generators/rails/plugin/plugin_generator.rb, line 45
    def readme
      template "README.md"
    end
🔎 See on GitHub

stylesheets()

📝 Source code
# File railties/lib/rails/generators/rails/plugin/plugin_generator.rb, line 152
    def stylesheets
      if mountable?
        copy_file "rails/stylesheets.css",
                  "app/assets/stylesheets/#{namespaced_name}/application.css"
      elsif full?
        empty_directory_with_keep_file "app/assets/stylesheets/#{namespaced_name}"
      end
    end
🔎 See on GitHub

test()

📝 Source code
# File railties/lib/rails/generators/rails/plugin/plugin_generator.rb, line 87
    def test
      template "test/test_helper.rb"
      template "test/%namespaced_name%_test.rb"
      append_file "Rakefile", <<-EOF

#{rakefile_test_tasks}
task default: :test
      EOF
      if engine?
        template "test/integration/navigation_test.rb"
      end
    end
🔎 See on GitHub

test_dummy_assets()

📝 Source code
# File railties/lib/rails/generators/rails/plugin/plugin_generator.rb, line 129
    def test_dummy_assets
      template "rails/javascripts.js",    "#{dummy_path}/app/javascript/packs/application.js", force: true
      template "rails/stylesheets.css",   "#{dummy_path}/app/assets/stylesheets/application.css", force: true
      template "rails/dummy_manifest.js", "#{dummy_path}/app/assets/config/manifest.js", force: true
    end
🔎 See on GitHub

test_dummy_clean()

📝 Source code
# File railties/lib/rails/generators/rails/plugin/plugin_generator.rb, line 135
    def test_dummy_clean
      inside dummy_path do
        remove_file ".ruby-version"
        remove_file "db/seeds.rb"
        remove_file "Gemfile"
        remove_file "lib/tasks"
        remove_file "public/robots.txt"
        remove_file "README.md"
        remove_file "test"
        remove_file "vendor"
      end
    end
🔎 See on GitHub

test_dummy_config()

📝 Source code
# File railties/lib/rails/generators/rails/plugin/plugin_generator.rb, line 117
    def test_dummy_config
      template "rails/boot.rb", "#{dummy_path}/config/boot.rb", force: true

      insert_into_file "#{dummy_path}/config/application.rb", <<~RUBY, after: /^Bundler\.require.+\n/
        require #{namespaced_name.inspect}
      RUBY

      if mountable?
        template "rails/routes.rb", "#{dummy_path}/config/routes.rb", force: true
      end
    end
🔎 See on GitHub

version_control()

📝 Source code
# File railties/lib/rails/generators/rails/plugin/plugin_generator.rb, line 65
    def version_control
      if !options[:skip_git] && !options[:pretend]
        run "git init", capture: options[:quiet], abort_on_failure: false
      end
    end
🔎 See on GitHub