Class: SystemListener
- Inherits:
-
Object
- Object
- SystemListener
- Defined in:
- lib/ObjectModel/Repository/SystemListener.rb
Instance Method Summary collapse
- #after_delete_parent(entity, old_parent) ⇒ Object
- #after_new(entity) ⇒ Object
- #after_new_parent(entity, old_parent) ⇒ Object
- #before_attribute_update(entity, name, new, old) ⇒ Object
- #before_commit(entities) ⇒ Object
- #before_delete(entity) ⇒ Object
- #before_delete_child(entity, name, child) ⇒ Object
- #before_delete_reference(entity, name, reference) ⇒ Object
- #before_name_update(entity, new, old) ⇒ Object
- #before_new_child(entity, name, child) ⇒ Object
- #before_new_reference(entity, name, reference) ⇒ Object
-
#initialize(transaction) ⇒ SystemListener
constructor
A new instance of SystemListener.
Constructor Details
#initialize(transaction) ⇒ SystemListener
Returns a new instance of SystemListener.
2 3 4 5 |
# File 'lib/ObjectModel/Repository/SystemListener.rb', line 2 def initialize transaction @transaction = transaction @deleted_parents = {} end |
Instance Method Details
#after_delete_parent(entity, old_parent) ⇒ Object
25 26 27 |
# File 'lib/ObjectModel/Repository/SystemListener.rb', line 25 def after_delete_parent entity, old_parent check_name_uniquity entity, entity.name end |
#after_new(entity) ⇒ Object
36 37 38 |
# File 'lib/ObjectModel/Repository/SystemListener.rb', line 36 def after_new entity AnEntity::EntityType.custom_initialization entity end |
#after_new_parent(entity, old_parent) ⇒ Object
21 22 23 |
# File 'lib/ObjectModel/Repository/SystemListener.rb', line 21 def after_new_parent entity, old_parent check_name_uniquity entity, entity.name end |
#before_attribute_update(entity, name, new, old) ⇒ Object
7 8 9 10 |
# File 'lib/ObjectModel/Repository/SystemListener.rb', line 7 def before_attribute_update entity, name, new, old name.should! :be_a, Symbol AnEntity::EntityType.validate_attribute entity, name, new, old end |
#before_commit(entities) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/ObjectModel/Repository/SystemListener.rb', line 29 def before_commit entities entities.should! :be_a, Array entities.each do |e| AnEntity::EntityType.validate_entity e end end |
#before_delete(entity) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/ObjectModel/Repository/SystemListener.rb', line 75 def before_delete entity if entity.name_get == "child2" copy = @transaction.copies[entity.entity_id] parent = entity.parent parent.should! :be_a, [Entity, NilClass] @transaction.deleted_entities[entity.entity_id] = entity AnEntity::EntityType.delete_all_references_to @transaction, entity AnEntity::EntityType.delete_from_parent entity, parent if parent AnEntity::EntityType.delete_all_children entity return end copy = @transaction.copies[entity.entity_id] copy.should_not! :deleted? parent = entity.parent parent.should! :be_a, [Entity, NilClass] @transaction.deleted_entities[entity.entity_id] = entity AnEntity::EntityType.delete_all_references_to @transaction, entity AnEntity::EntityType.delete_from_parent entity, parent if parent AnEntity::EntityType.delete_all_children entity end |
#before_delete_child(entity, name, child) ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'lib/ObjectModel/Repository/SystemListener.rb', line 65 def before_delete_child entity, name, child child.should! :be_a, Entity entity.should! :be_a, Entity name.should! :be_a, Symbol @transaction.event_processor.fire_before child, :delete_parent, entity child._parent = nil @transaction.event_processor.fire_after child, :delete_parent, entity end |
#before_delete_reference(entity, name, reference) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/ObjectModel/Repository/SystemListener.rb', line 103 def before_delete_reference entity, name, reference entity.should! :be_a, Entity reference.should! :be_a, Entity name.should! :be_a, Symbol @transaction.event_processor.fire_before reference, :delete_referrer, entity AnEntity::EntityType.delete_backreference @transaction, entity, reference @transaction.event_processor.fire_after reference, :delete_referrer, entity end |
#before_name_update(entity, new, old) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/ObjectModel/Repository/SystemListener.rb', line 12 def before_name_update entity, new, old return if new == old raise_without_self "name '#{new}' should be a String!", ObjectModel unless new.is_a? String raise_without_self "name '#{new}' shouldn't be Emtpy!", ObjectModel if new.empty? raise_without_self "name '#{new}' should not include '/' Symbol!", ObjectModel if new.include? '/' check_name_uniquity entity, new end |
#before_new_child(entity, name, child) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/ObjectModel/Repository/SystemListener.rb', line 40 def before_new_child entity, name, child raise_without_self "Child should be Entity or Nil (#{child})!", ObjectModel unless child.is_a?(Entity) or child == nil raise_without_self "Forbiden to add self as Child!", ObjectModel if child == entity raise_without_self "Forbiden to add the same Child twice!", ObjectModel if child.parent == entity name.should! :be_a, Symbol old_parent = child.parent if old_parent != nil # :move AnEntity::EntityType.delete_from_parent child, old_parent @transaction.event_processor.fire_before child, :move, entity, old_parent @transaction.copies[entity.entity_id].moved! end @transaction.event_processor.fire_before child, :new_parent, entity child._parent = entity @transaction.event_processor.fire_after child, :new_parent, old_parent if old_parent != nil # :move @transaction.event_processor.fire_after child, :move, entity, old_parent end end |
#before_new_reference(entity, name, reference) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/ObjectModel/Repository/SystemListener.rb', line 115 def before_new_reference entity, name, reference entity.should! :be_a, Entity reference.should! :be_a, Entity name.should! :be_a, Symbol @transaction.event_processor.fire_before reference, :new_referrer, entity AnEntity::EntityType.new_backreference @transaction, entity, reference @transaction.event_processor.fire_after reference, :new_referrer, entity end |