title: Ruby on Rails - custom generators and maintenance
body: <p>I am fairly new to Ruby on Rails, have only been using it for ~6 months.  Previously I worked primarily in .NET, and have architected some large web applications using that framework.  I have been a proponent of code generation for some time, which is part of what attracted me to RoR for my next application. </p>
  
  <p>In the .NET world, I had a lot of success using generated code, inheritance and partial classes to more easily enable refactoring, enhancements and maintenance of generated code.  Essentially, within each layer of the applications, generators were used to create 'base' classes with core functionality.  Those base classes could then be sub-classed to extend or modify the behavior as necessary to address the needs of each specific component.  </p>
  
  <p>Over time, however, we often needed to make changes to the generated code without overwriting the hand-written extension code.  In a .NET world, that was quite manageable using partial classes to implement the subclass extensions/overrides, keeping the generated code files separate from the extension code files.</p>
  
  <p>I am now trying to decide how to best accomplish the same thing in an RoR world, and am hoping for some guidance from those of you that may tried similar approaches.  I have not found anything analogous to partial classes in ruby, but maybe there is a different mechanism to accomplish the same thing.</p>
  
  <p>Below is a quick example of how I typically organized code in a .NET world:
  </p>
  
  <p>\generated\BaseEmployee.cs</p>
  
  <pre class="lang-cs prettyprint-override"><code>public abstract class BaseEmployee
  {
    public BaseEmployee(string name, decimal salary)
    {
      this.Name = name;
      this.Salary = salary;
    }
    public string Name { get; protected set; }
    public decimal Salary { get; protected set; }
    public virtual void GiveRaise(decimal amount)
    {
      if (this.AuthorizeRaise(amount)) this.Salary += amount;
    }
    protected virtual AuthorizeRaise(decimal amount)
    {
      if (amount &gt; this.Salary * 0.1) // no raises over 10%
        return false;
      else
        return true;
    }
  }
  </code></pre>
  
  <p>\generated\Employee.cs</p>
  
  <pre class="lang-cs prettyprint-override"><code>public partial class Employee : BaseEmployee
  {
    public Employee(string name, decimal salary) : base(name, salary) { }
  }
  </code></pre>
  
  <p>\extensions\Employee.cs</p>
  
  <pre class="lang-cs prettyprint-override"><code>partial class Employee
  {
    public Employee(string name, string title, decimal salary) 
      : base(name, title, salary) { }
    protected override AuthorizeRaise(decimal amount)
    {
      if (this.Name == "Mr. Dithers")  // this clown gets no raise
        return false;
      else
        return base.AuthorizeRaise(amount);
    }
  }
  </code></pre>