root/lang/ruby/active_record_template/init.rb @ 1519

Revision 466, 1.0 kB (checked in by yugui, 7 years ago)

lang/ruby/active_record_template: initial import

Line 
1require 'active_record/template'
2require 'active_record/template/eval_context'
3require 'active_record/template/sql_helper'
4
5# Include hook code here
6ObjectSpace.each_object(Class) do |subclass|
7  if subclass < ActiveRecord::Base
8    subclass.extend ActiveRecord::Template::EvalContext
9    subclass.extend ActiveRecord::Template::SqlHelper
10    subclass.__send__(:include, ActiveRecord::Template::EvalContext)
11    subclass.extend ActiveRecord::Template::ClassMethods
12  end
13end
14
15ActiveRecord::Base.class_eval do
16  class << self
17    def inherited_with_query_template(subclass)
18      subclass.extend ActiveRecord::Template::ClassMethods
19      subclass.extend ActiveRecord::Template::EvalContext
20      subclass.extend ActiveRecord::Template::SqlHelper
21      subclass.__send__(:include, ActiveRecord::Template::EvalContext)
22      inherited_without_query_template(subclass)
23    end
24    alias_method :inherited_without_query_template, :inherited
25    alias_method :inherited, :inherited_with_query_template
26  end
27end
Note: See TracBrowser for help on using the browser.