Class: Omega::Server::ProxyEntity

Inherits:
Object
  • Object
show all
Defined in:
lib/omega/server/proxy.rb

Overview

Omega Proxy Entity, protects entity access using a registry

Instance Method Summary collapse

Constructor Details

#initialize(entity, registry) ⇒ ProxyEntity

Returns a new instance of ProxyEntity


17
18
19
20
# File 'lib/omega/server/proxy.rb', line 17

def initialize(entity, registry)
  @entity = entity
  @registry = registry
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object (protected)


24
25
26
27
28
29
30
31
32
33
34
# File 'lib/omega/server/proxy.rb', line 24

def method_missing(name, *args, &block)
  ret = nil
  old_entity = nil
  @registry.safe_exec { |entities|
    old_entity = RJR::JSONParser.parse(@entity.to_json)
    ret = @entity.send(name, *args, &block)
  }
  # TODO only invoke if entity changed?
  @registry.raise_event(:updated, @entity, old_entity)
  ret
end