module Fiona7 class Initializer CLASSES_MAP = { 'X_Generic' => 'generic', 'X_Image' => 'image', 'X_Container' => 'publication' } ATTRIBUTES_MAP = { 'X_widget_pool' => 'linklist' } def sanity_check any_class_present = false classes_present = CLASSES_MAP.all? do |name, type| obj_class = RailsConnector::ObjClass.find_by_name(name) any_class_present ||= obj_class && obj_class.obj_type == type end classes_present && raise("Initialization has already been performed, there is not need to perform it again.") any_class_present && raise("Misconfiguration of obj classes detected") any_attribute_present = false attributes_present = ATTRIBUTES_MAP.all? do |name, type| attribute = RailsConnector::Attribute.find_by_name(name) any_attribute_present ||= attribute && attribute.attribute_type == type end any_class_present && raise("Misconfiguration of attributes detected") end def classes_and_attributes CLASSES_MAP.each do |name, type| Reactor::Cm::ObjClass.create(name, type) end ATTRIBUTES_MAP.each do |name, type| Reactor::Cm::Attribute.create(name, type) end end def set_valid_sub_obj_classes RailsConnector::ObjClass.all.each do |obj_class| valid_sub_obj_classes = read_valid_sub_obj_classes(obj_class) # empty valid_sub_obj_classes = allow all unless valid_sub_obj_classes.empty? valid_sub_obj_classes += CLASSES_MAP.keys cm_class = Reactor::Cm::ObjClass.get(obj_class.name) cm_class.set(:validSubObjClasses, valid_sub_obj_classes) cm_class.save! end end end def create_login_page Scrivito::Workspace.current = Scrivito::Workspace.find('rtc') Scrivito::ObjClass.create( name: 'Fiona7LoginPage', title: 'Login Page', attributes: [ {name: "title", type: "string"}, {name: "body", type: "html"} ] ) Scrivito::Obj.create(_obj_class: 'Fiona7LoginPage', _path: '/_global/login_page', title: 'Log in') Scrivito::ObjClass.find('Fiona7LoginPage').update(is_active: false) end protected def read_valid_sub_obj_classes(obj_class) # TODO: upgrade reactor to get rid of this crap obj_class.send(:load_blob_data) data = obj_class.instance_variable_get('@blob_data') || {} data["validSubObjClasses"] || [] end end end