Add inheritance hook creating subclasses if missing. Finn: #3416, Cockpit: #18043.

pull/6827/head
Konstantin Haase 14 years ago
parent 1cf51a88d5
commit 0b65f8302f
  1. 1
      app/models/report.rb
  2. 23
      app/models/report/inherited_namespace.rb

@ -1,6 +1,7 @@
require 'forwardable'
class Report < ActiveRecord::Base
InheritedNamespace.activate
extend Forwardable
include Enumerable
#belongs_to :user

@ -0,0 +1,23 @@
module Report::InheritedNamespace
def self.activate
[Report, Report::Validation, Report::Filter, Report::GroupBy, Report::Result].each do |klass|
extend_object klass
end
end
def const_missing(name, *)
super
rescue NameError => error
raise error unless respond_to? superclass and superclass != self
begin
zuper = superclass.const_get(name)
case zuper
when Class then const_set name, Class.new(zuper).extend(InheritedNamespace)
when Module then const_set name, Module.new { include zuper }.extend(InheritedNamespace)
else const_set name, zuper
end
rescue NameError
raise error
end
end
end
Loading…
Cancel
Save