give inherited_namespace to konstantin for further work

pull/6827/head
Philipp Tessenow 14 years ago
parent 8bf8dac886
commit e95ec569d1
  1. 44
      app/models/report/inherited_namespace.rb

@ -1,28 +1,50 @@
module Report::InheritedNamespace module Report::InheritedNamespace
NESTED_NAMESPACES = %w[Validation Filter GroupBy Result]
def self.activate def self.activate
[Report, Report::Validation, Report::Filter, Report::GroupBy, Report::Result].each do |klass| Report.extend self
extend_object klass NESTED_NAMESPACES.each { |n| n.extend self }
end
end end
def const_missing(name, *) def const_missing(name, *)
puts "const_missing called on #{self.name}"
super super
rescue NameError => error rescue NameError => error
raise error unless respond_to? :superclass and superclass != self raise error unless respond_to? :superclass and superclass != self
begin load_constant name, error
end
def inherited(klass)
super
propagate klass
end
def included(klass)
super
propagate klass
end
def propagate(klass)
klass.extend Report::InheritedNamespace
NESTED_NAMESPACES.each do |name|
if file = ActiveSupport::Dependencies.search_for_file("#{klass.name}::#{name}".underscore)
require_or_load file
else
const_missing name
end
end
end
def load_constant(name, error = nil)
puts "#{self.name} #{name}"
zuper = superclass.const_get(name) zuper = superclass.const_get(name)
case zuper case zuper
when Class then const_set name, Class.new(zuper).extend(Report::InheritedNamespace) when Class then const_set name, Class.new(zuper).extend(Report::InheritedNamespace)
when Module then const_set name, Module.new { include zuper }.extend(Report::InheritedNamespace) when Module then const_set name, Module.new { include zuper }.extend(Report::InheritedNamespace)
else const_set name, zuper else const_set name, zuper
end end
rescue NameError rescue NameError, ArgumentError
raise error raise error
end end
end
def inherited(klass)
super
klass.extend Report::InheritedNamespace
end
end end

Loading…
Cancel
Save