Rails Plugins: Extending Rails Beyond the Core

Book description

One of the most powerful aspects of the Rails framework is the ability to extend and override it within your own applications. This is achieved through the Rails plugin mechanism, which provides an avenue for Rails developers to add powerful new features to their applications and share this functionality with the worldwide community.

This short cut introduces Rails plugins and considers each aspect of their behavior and development. You'll learn what plugins are, how they work, and why they're useful. Discover how to find and install plugins using the provided script, then explore the world of plugin development, including common plugin idioms, testing, and version control. Finally, learn how to share your own plugins.

What This Short Cut Covers 4

Section 1: Introduction 5

Section 2: Installing Plugins 14

Section 3: Saluton, Mondo! (init rb) 33

Section 4: Sharing Code (lib) 39

Section 5: The Rest (README, install rb, Rakefile, tasks, and More) 51

Section 6: Plugin Development 62

Section 7: Sharing Classes and Code 83

Section 8: Testing Plugins 100

Section 9: Sharing Your Plugin 113

Section 10: Conclusions 121

About the Author 123

Table of contents

  1. Copyright
    1. Dedication
  2. What This Short Cut Covers
  3. 1. Introduction
    1. Ruby on Rails
      1. Ruby Will Give You Infinite Power and Unlimited Riches
    2. Oh Plugin, Where Art Thou?
    3. Overview of This Short Cut
    4. Ruby and Rails Versions
    5. A Short Essay about Reusable Code
      1. Programmers Are Abstract Problem Solvers
      2. To Reuse, or Not to Reuse; That Is the Question
        1. In Search of the Reuse Equation
        2. And That Is All You Need to Know. Isn’t It?
  4. 2. Installing Plugins
    1. Installing Plugins with script/plugin
      1. script/plugin list
      2. script/plugin sources
      3. script/plugin source [url [url2 [...]]]
      4. script/plugin unsource [url [url2 [...]]]
      5. script/plugin discover [url]
      6. script/plugin install [plugin]
      7. script/plugin remove [plugin]
      8. script/plugin info [plugin]
      9. script/plugin update [plugin]
    2. Plugins from Subversion
      1. Subversion for the Uninitiated
      2. Subversion and script/plugin
        1. Installing Subversion
        2. Checking Out a Plugin
    3. script/plugin update, Redux
      1. Automatic Updates: SVN Externals
    4. Summary
  5. 3. Saluton, Mondo! (init.rb)
    1. The Plugin Generator
    2. init.rb
    3. Summary
  6. 4. Sharing Code (lib)
    1. The lib Directory
      1. A Simple Example
      2. The Code Payload
    2. The CopyrightHelper Plugin
    3. Rails, Modules, and Auto-Loading Code
    4. Using the Copyright Plugin in an Application
    5. Including Code Automatically
    6. Adding to ApplicationHelper
      1. Fully Automatic Module Inclusion
    7. Summary
  7. 5. The Rest (README, install.rb, Rakefile, tasks, and More)
    1. README—Capitalized for a Good Reason
    2. install.rb and uninstall.rb
    3. uninstall.rb (Edge Rails Only)
    4. about.yml (Edge Rails Only)
    5. Rake and Plugins
      1. tasks/*.rake
      2. The Plugin Rakefile
    6. Rakefile versus tasks/—What’s the Difference?
    7. Summary
  8. 6. Plugin Development
    1. Prelude: Mixing a Module’s Methods into a Class
      1. How to Successfully Mix in Class Methods
    2. Staring into the Heart of Ruby
    3. Extracting Behavior into a Plugin
      1. Specifying Behavior with Ruby Code
      2. Creating the breadcrumbs Plugin
      3. Creating the stores_breadcrumbs Class Method
    4. Writing an acts_as Plugin
      1. Implementing acts_as_checksummed
      2. Implementing the checksum Method
      3. Adding the Callback
      4. Putting the Pieces Together
      5. The Behavior Module
      6. Adding Class Methods to the Model Class
      7. Why Bother Adding Class Methods to a Subclass Only?
      8. acts_as, Redux
    5. Summary
  9. 7. Sharing Classes and Code
    1. Using Plugins to Share Code
    2. Models and Helpers
    3. Controllers
    4. Organizing Your Shared Classes
    5. Sharing Files That Aren’t Code
      1. Views and Partials
      2. Public Assets
        1. Copying via install.rb
        2. Copying via init.rb
        3. Using Symbolic Links
        4. Other Mechanisms
    6. Using Engine Plugins
      1. Developing with Engines
        1. The init_engine.rb File
        2. Code Mixing
        3. Sharing Public Assets
      2. With Great Power Comes Great Responsibility
        1. Appropriate Reuse
      3. Engines—Further Information
    7. Generators in Plugins
    8. Creating Generators
    9. Running Plugin Generators
    10. Sharing Generators
    11. Upgrading Generated Code
    12. Summary
  10. 8. Testing Plugins
    1. Writing Plugin Tests
      1. The test:plugins Task
      2. Testing Plugins Individually
      3. The PLUGIN Argument
      4. The Plugin Rakefile
      5. Customized Testing Tasks
      6. Loading the Rails Test Environment
    2. Testing Plugins Against an Isolated Database
      1. Creating the Test Data
      2. Defining the Test Schema
      3. Testing Against a Plugin Database with a Test Helper
      4. Using the Plugin Test Database
    3. Summary
  11. 9. Sharing Your Plugin
    1. To Share, or Not to Share
    2. Hosting
      1. Subversion Hosting
      2. Sharing Plugins Without Subversion
    3. Releasing Your Plugin
      1. Making Your Plugin Discoverable
      2. Announce It!
    4. Supporting the Plugin
  12. 10. Conclusions
    1. Ruby, Ruby, Ruby
  13. About the Author

Product information

  • Title: Rails Plugins: Extending Rails Beyond the Core
  • Author(s): James Adam
  • Release date: September 2006
  • Publisher(s): Addison-Wesley Professional
  • ISBN: None