class Woyo::WorldObject

Attributes

_test[RW]
context[R]
id[R]

Public Class Methods

new(id, context: nil, &block) click to toggle source
# File lib/woyo/world/world_object.rb, line 16
def initialize id, context: nil, &block
  @id = id ? id.to_s.downcase.to_sym : nil
  @context = context
  attributes :description, name: proc { id.to_s.capitalize.gsub('_',' ') }
  initialize_object
  evaluate &block
  # todo:
  #   creating attributes should register with change listener
  #   this will catch all attributes anytime they are created
  #   instead of just after initialize->evaluate
  track_changes
end

Public Instance Methods

attribute_changes()
Alias for: changes
attribute_clear_changes()
Alias for: clear_changes
changes() click to toggle source
# File lib/woyo/world/world_object.rb, line 50
def changes
  all_changes = attribute_changes
  children.each do |child_type,type_children|
    child_type_changes = {}
    type_children.each do |child_id,child|
      child_changes = child.changes
      child_type_changes[child_id] = child_changes unless child_changes.empty?
    end
    all_changes[child_type] = child_type_changes unless child_type_changes.empty?
  end
  all_changes
end
Also aliased as: attribute_changes
clear_changes() click to toggle source
# File lib/woyo/world/world_object.rb, line 40
def clear_changes
  attribute_clear_changes
  children.each do |child_type,type_children|
    type_children.each do |child_id,child|
      child.clear_changes
    end
  end
end
Also aliased as: attribute_clear_changes
initialize_object() click to toggle source
# File lib/woyo/world/world_object.rb, line 29
def initialize_object ; end
uid() click to toggle source
# File lib/woyo/world/world_object.rb, line 31
def uid
  if @context
    @context.uid + '-' + id.to_s
  else
    id.to_s
  end
end