Class: Fiona7::Initializer
- Inherits:
-
Object
- Object
- Fiona7::Initializer
- Defined in:
- lib/fiona7/initializer.rb
Constant Summary collapse
- CLASSES_MAP =
{ 'X_Generic' => 'generic', 'X_Image' => 'image', 'X_Container' => 'publication' }
- CLASSES_TITLE_MAP =
{ 'X_Generic' => {'Binärdatei (Systemvorlage)' => {'lang' => 'de'}, 'Binary file (system class)' => {'lang' => 'en'}}, 'X_Image' => {'Bilddatei (Systemvorlage)' => {'lang' => 'de'}, 'Image file (system class)' => {'lang' => 'en'}}, 'X_Container' => {'Container (Systemvorlage)' => {'lang' => 'de'}, 'Contaienr (system class)' => {'lang' => 'en'}} }
- ATTRIBUTES_MAP =
{ 'X_widget_pool' => 'linklist', 'X_full_text' => 'text' }
- ATTRIBUTES_TITLE_MAP =
{ 'X_widget_pool' => {'Verlinkte Widgets (Systemfeld)' => {'lang' => 'de'}, 'Linked widgets (system field)' => {'lang' => 'en'}}, 'X_full_text' => {'Hauptinhalt für die Suchmaschine (Systemfeld)' => {'lang' => 'de'}, 'Body for search engine (system field)' => {'lang' => 'en'}} }
Instance Method Summary collapse
- #classes_and_attributes ⇒ Object
- #create_login_page ⇒ Object
- #initialize_system ⇒ Object
- #sanity_check ⇒ Object
- #set_valid_sub_obj_classes ⇒ Object
Instance Method Details
#classes_and_attributes ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/fiona7/initializer.rb', line 56 def classes_and_attributes CLASSES_MAP.each do |name, type| obj_class = Reactor::Cm::ObjClass.create(name, type) obj_class.set(:title, CLASSES_TITLE_MAP[name]) obj_class.save! end ATTRIBUTES_MAP.each do |name, type| attribute = Reactor::Cm::Attribute.create(name, type) attribute.set(:title, ATTRIBUTES_TITLE_MAP[name]) if (type == 'text') attribute.set(:isSearchableInCM, 1) attribute.set(:isSearchableInTE, 1) end attribute.save! end end |
#create_login_page ⇒ Object
88 89 90 91 92 |
# File 'lib/fiona7/initializer.rb', line 88 def create_login_page # TODO: write new creation procedure Scrivito::Workspace.current = Scrivito::Workspace.find('rtc') Scrivito::BasicObj.create(_obj_class: 'Fiona7LoginPage', _path: '/_global/login_page', title: 'Log in') end |
#initialize_system ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/fiona7/initializer.rb', line 25 def initialize_system should_run = self.sanity_check return unless should_run self.classes_and_attributes self.set_valid_sub_obj_classes self.create_login_page end |
#sanity_check ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/fiona7/initializer.rb', line 34 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 return false if classes_present 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_attribute_present && raise("Misconfiguration of attributes detected") return true end |
#set_valid_sub_obj_classes ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/fiona7/initializer.rb', line 74 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? || CLASSES_MAP.keys.all? {|obj_class| valid_sub_obj_classes.include?(obj_class) } 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 |