Class: Woyo::WorldObject
- Inherits:
-
Object
- Object
- Woyo::WorldObject
- Includes:
- Attributes, Evaluate
- Defined in:
- lib/woyo/world/world_object.rb
Instance Attribute Summary collapse
-
#_test ⇒ Object
Returns the value of attribute _test.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
- #attribute_changes ⇒ Object
- #attribute_clear_changes ⇒ Object
- #changes ⇒ Object
- #clear_changes ⇒ Object
-
#initialize(id, context: nil, &block) ⇒ WorldObject
constructor
A new instance of WorldObject.
- #initialize_object ⇒ Object
- #uid ⇒ Object
Methods included from Evaluate
#children, #evaluate, included
Methods included from Attributes
#attribute, #attributes, #define_attr, #define_attr!, #define_attr?, #define_attr_default, #define_attr_equals, #define_attr_methods, #dependent_changes, #exclusion, #exclusions, #group, #groups, #is, #is?, #track_changes
Constructor Details
#initialize(id, context: nil, &block) ⇒ WorldObject
Returns a new instance of WorldObject.
16 17 18 19 20 21 22 23 24 25 26 27 |
# 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 |
Instance Attribute Details
#_test ⇒ Object
Returns the value of attribute _test.
12 13 14 |
# File 'lib/woyo/world/world_object.rb', line 12 def _test @_test end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
11 12 13 |
# File 'lib/woyo/world/world_object.rb', line 11 def context @context end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
11 12 13 |
# File 'lib/woyo/world/world_object.rb', line 11 def id @id end |
Instance Method Details
#attribute_changes ⇒ Object
49 |
# File 'lib/woyo/world/world_object.rb', line 49 alias_method :attribute_changes, :changes |
#attribute_clear_changes ⇒ Object
39 |
# File 'lib/woyo/world/world_object.rb', line 39 alias_method :attribute_clear_changes, :clear_changes |
#changes ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 |
# 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 |
#clear_changes ⇒ Object
40 41 42 43 44 45 46 47 |
# 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 |
#initialize_object ⇒ Object
29 |
# File 'lib/woyo/world/world_object.rb', line 29 def initialize_object ; end |
#uid ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/woyo/world/world_object.rb', line 31 def uid if @context @context.uid + '-' + id.to_s else id.to_s end end |