Class: Flox::Entity
- Inherits:
-
Hash
- Object
- Hash
- Flox::Entity
- Defined in:
- lib/flox/entity.rb
Overview
The base class of all objects that can be stored persistently on the Flox server.
The class extends Hash. Thus, all properties of the Entity can be accessed
as keys of the Entity instance.
entity['name'] = 'Donald Duck'
For convenience, the standard entity properties (e.g. created_at and
updated_at)can be accessed via Ruby attributes.
entity.public_access = 'rw'
To load and save an entity, use the respective methods on the Flox class.
my_entity = flox.load_entity('SaveGame', '12345') # => Flox::Entity
flox.save_entity(my_entity)
Direct Known Subclasses
Instance Attribute Summary collapse
-
#created_at ⇒ Time
The time the entity was created.
-
#id ⇒ String
The primary identifier of the entity.
-
#owner_id ⇒ String
The player ID of the owner of the entity (referencing a Player entitity).
-
#path ⇒ String
readonly
The path to the REST-resource of the entity, relative to the game's root.
-
#public_access ⇒ String
The access rights of all players except the owner (the owner always has unlimited access).
-
#type ⇒ String
readonly
The type of the entity.
-
#updated_at ⇒ Time
The time the entity was last changed on the server.
Instance Method Summary collapse
-
#initialize(type, id = nil, data = nil) ⇒ Entity
constructor
A new instance of Entity.
-
#inspect ⇒ String
Provides a simple string representation of the Entity.
Constructor Details
#initialize(type, id = nil, data = nil) ⇒ Entity
Returns a new instance of Entity.
36 37 38 39 40 41 42 |
# File 'lib/flox/entity.rb', line 36 def initialize(type, id=nil, data=nil) @type = type @id = id ? id : String.random_uid self['createdAt'] = self['updatedAt'] = Time.now.utc.to_xs_datetime self.public_access = '' self.merge!(data) if data end |
Instance Attribute Details
#created_at ⇒ Time
Returns the time the entity was created.
89 90 91 |
# File 'lib/flox/entity.rb', line 89 def created_at Time.parse self['createdAt'] end |
#id ⇒ String
Returns the primary identifier of the entity.
28 29 30 |
# File 'lib/flox/entity.rb', line 28 def id @id end |
#owner_id ⇒ String
Returns the player ID of the owner of the entity (referencing a Player entitity).
85 86 87 |
# File 'lib/flox/entity.rb', line 85 def owner_id self["ownerId"] end |
#path ⇒ String (readonly)
Returns the path to the REST-resource of the entity, relative to the game's root.
99 100 101 |
# File 'lib/flox/entity.rb', line 99 def path "entities/#{@type}/#{@id}" end |
#public_access ⇒ String
Returns the access rights of all players except the owner (the owner always has unlimited access). Possible values: '', 'r', 'rw'.
95 96 97 |
# File 'lib/flox/entity.rb', line 95 def public_access self["publicAccess"] end |
#type ⇒ String (readonly)
Returns the type of the entity. Types group entities together on the server.
31 32 33 |
# File 'lib/flox/entity.rb', line 31 def type @type end |
#updated_at ⇒ Time
Returns the time the entity was last changed on the server.
92 93 94 |
# File 'lib/flox/entity.rb', line 92 def updated_at Time.parse self['updatedAt'] end |
Instance Method Details
#inspect ⇒ String
Returns provides a simple string representation of the Entity.
73 74 75 76 77 78 79 |
# File 'lib/flox/entity.rb', line 73 def inspect description = "[#{self.class} #{@id} (#{@type})\n" each_pair do |key, value| description += " #{key}: #{value}\n" end description += "]" end |