module ShadowClassesSupport def self.included(base) base.extend(ClassMethods) end module ClassMethods alias_method :real_to_s, :to_s # NOTE: this workaround is neccessary, because # in many places scrivito_sdk assumes that # class.name == obj_class_name which isn't # true for shadow classes # it breaks the bijection that scrivito_sdk # expects, but injection is mostly ok def to_s self.name.sub(/\AShadowClasses::/, '') end def real_to_s self.name end end end module ShadowClasses def self.fetch(name,type) # false skips inheritance chain, it checks only this module if self.const_defined?(name, false) self.const_get(name, false) else self.define(name,type) end end def self.define(name,type) if name =~ /::/ raise "Invalid name: #{name}, nesting of classes not allowed" end if type == 'Obj' if name == 'Obj' self.const_set(name, scrivito_obj_class) else self.const_set( name, Class.new(scrivito_obj_class) do include ::ShadowClassesSupport end ).tap do |klass| klass.register_attribute_definitions(name) end end elsif type == 'Widget' parent_class = 'Widget'.safe_constantize || Scrivito::BasicWidget self.const_set( name, Class.new(parent_class) do include ::ShadowClassesSupport end ).tap do |klass| klass.register_attribute_definitions(name) end end end def self.scrivito_obj_class if !::Scrivito.const_defined?('Obj', false) if Fiona7.mode == :standalone ::Scrivito.const_set('Obj', ::Obj) elsif Fiona7.mode == :legacy ::Scrivito.const_set('Obj', Class.new(::Scrivito::BasicObj)) else raise "Invalid Fiona7.mode = #{Fiona7.mode}" end end ::Scrivito.const_get('Obj', false) end end