Module: Entity
- Includes:
- OpenConstructor
- Defined in:
- lib/ObjectModel/Entity.rb
Instance Attribute Summary collapse
-
#back_references ⇒ Object
readonly
Returns the value of attribute back_references.
-
#entity_id ⇒ Object
readonly
Returns the value of attribute entity_id.
-
#om_repository ⇒ Object
readonly
Returns the value of attribute om_repository.
-
#om_version ⇒ Object
readonly
Returns the value of attribute om_version.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #[](path) ⇒ Object
- #_parent=(parent) ⇒ Object
- #delete ⇒ Object
- #each(specificator, &block) ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
- #include?(path) ⇒ Boolean
- #inspect ⇒ Object
- #meta ⇒ Object
- #name ⇒ Object
- #name=(eid) ⇒ Object
- #name_get ⇒ Object
- #parent ⇒ Object
- #parent_get ⇒ Object
- #path ⇒ Object
- #search_up(&b) ⇒ Object
- #to_s ⇒ Object
- #to_yaml(io) ⇒ Object
- #up(method_name, *p, &b) ⇒ Object
- #validate ⇒ Object
Instance Attribute Details
#back_references ⇒ Object (readonly)
Returns the value of attribute back_references.
3 4 5 |
# File 'lib/ObjectModel/Entity.rb', line 3 def back_references @back_references end |
#entity_id ⇒ Object (readonly)
Returns the value of attribute entity_id.
3 4 5 |
# File 'lib/ObjectModel/Entity.rb', line 3 def entity_id @entity_id end |
#om_repository ⇒ Object (readonly)
Returns the value of attribute om_repository.
3 4 5 |
# File 'lib/ObjectModel/Entity.rb', line 3 def om_repository @om_repository end |
#om_version ⇒ Object (readonly)
Returns the value of attribute om_version.
3 4 5 |
# File 'lib/ObjectModel/Entity.rb', line 3 def om_version @om_version end |
Instance Method Details
#==(other) ⇒ Object
5 6 7 8 9 |
# File 'lib/ObjectModel/Entity.rb', line 5 def == other @entity_id.should_not! :be_nil return false unless other.respond_to? :entity_id @entity_id == other.entity_id end |
#[](path) ⇒ Object
167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/ObjectModel/Entity.rb', line 167 def [] path path = path.to_s if path.is_a? Path path.should! :be_a, String absolute_path = "#{path_get}/#{path}" entity_id = @om_repository.index(:path).get_entity_id absolute_path raise_without_self NotFoundError, "Entity with Path '#{path}' not found!", ObjectModel if entity_id == nil entity_id.should! :be_a, String return @om_repository.by_id entity_id end |
#_parent=(parent) ⇒ Object
100 101 102 103 104 105 106 107 |
# File 'lib/ObjectModel/Entity.rb', line 100 def _parent= parent if tr = Thread.current[:om_transaction] copy = tr.copy_get! self copy.parent = parent != nil ? parent.entity_id : nil else raise NoTransactionError end end |
#delete ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/ObjectModel/Entity.rb', line 38 def delete tr = Thread.current[:om_transaction] raise NoTransactionError unless tr copy = tr.copy_get!(self) copy.new?.should! :be_false tr.event_processor.fire_before self, :delete tr.event_processor.fire_after self, :delete copy.deleted! end |
#each(specificator, &block) ⇒ Object
146 147 148 149 150 151 152 153 154 |
# File 'lib/ObjectModel/Entity.rb', line 146 def each specificator, &block case specificator when :attribute then AnEntity::EntityType.each_attribute self, &block when :child then AnEntity::EntityType.each_child self, &block when :reference then AnEntity::EntityType.each_reference self, &block else should! :be_never_called end end |
#eql?(other) ⇒ Boolean
11 12 13 14 15 |
# File 'lib/ObjectModel/Entity.rb', line 11 def eql? other @entity_id.should_not! :be_nil return false unless self.class == other.class @entity_id == other.entity_id end |
#hash ⇒ Object
17 18 19 20 |
# File 'lib/ObjectModel/Entity.rb', line 17 def hash @entity_id.should_not! :be_nil return @entity_id.hash end |
#include?(path) ⇒ Boolean
156 157 158 159 160 161 162 163 164 165 |
# File 'lib/ObjectModel/Entity.rb', line 156 def include? path path = path.to_s if path.is_a? Path path.should! :be_a, String absolute_path = "#{path_get}/#{path}" entity_id = @om_repository.index(:path).get_entity_id absolute_path entity_id.should! :be_a, [String, NilClass] return entity_id != nil end |
#inspect ⇒ Object
26 27 28 |
# File 'lib/ObjectModel/Entity.rb', line 26 def inspect to_s end |
#meta ⇒ Object
34 35 36 |
# File 'lib/ObjectModel/Entity.rb', line 34 def self.class. end |
#name ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/ObjectModel/Entity.rb', line 50 def name if tr = Thread.current[:om_transaction] if tr.changed? @entity_id tr.copies[@entity_id].name else @name end else @name end end |
#name=(eid) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/ObjectModel/Entity.rb', line 66 def name= eid if tr = Thread.current[:om_transaction] copy = tr.copy_get! self old_value = copy.name tr.event_processor.fire_before self, :name_update, eid, old_value copy.name = eid tr.event_processor.fire_after self, :name_update, eid, old_value else raise NoTransactionError end end |
#name_get ⇒ Object
62 63 64 |
# File 'lib/ObjectModel/Entity.rb', line 62 def name_get @name end |
#parent ⇒ Object
86 87 88 89 90 91 92 93 94 |
# File 'lib/ObjectModel/Entity.rb', line 86 def parent tr = Thread.current[:om_transaction] if tr and tr.changed? @entity_id entity_id = tr.copies[@entity_id].parent entity_id ? tr.resolve(entity_id) : nil else @parent ? @om_repository.by_id(@parent) : nil end end |
#parent_get ⇒ Object
96 97 98 |
# File 'lib/ObjectModel/Entity.rb', line 96 def parent_get @parent ? @om_repository.by_id(@parent) : nil end |
#path ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/ObjectModel/Entity.rb', line 78 def path path, current = Path.new(name), self while current = current.parent path = Path.new(current.name) + path end path end |
#search_up(&b) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/ObjectModel/Entity.rb', line 132 def search_up &b return self if b.call self parent = parent_get if parent if b.call(parent) return parent else return parent.search_up &b end else nil end end |
#to_s ⇒ Object
22 23 24 |
# File 'lib/ObjectModel/Entity.rb', line 22 def to_s; "#<#{self.class.name.split("::").last}: #{name}>" end |
#to_yaml(io) ⇒ Object
30 31 32 |
# File 'lib/ObjectModel/Entity.rb', line 30 def to_yaml io raise "You can't save Entity as YAML!" end |
#up(method_name, *p, &b) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/ObjectModel/Entity.rb', line 109 def up method_name, *p, &b result = nil e = search_up do |e| result = e.respond_to method_name, *p result != nil end return result # if respond_to? method_name # value = send(method_name, *p, &b) # if value != nil # return value # elsif parent_get and parent_get.respond_to? method_name # parent_get.up method_name, *p, &b # else # return value # end # else # return parent_get.up method_name, *p, &b if parent_get # return nil #raise NoMethodError, "Undefined method '#{method_name}' for '#{self.class.name}' and for it's parents!", caller # end end |
#validate ⇒ Object
179 180 181 |
# File 'lib/ObjectModel/Entity.rb', line 179 def validate AnEntity::EntityType.validate_entity self end |