Class: GameMachine::DataStore
- Inherits:
-
Object
- Object
- GameMachine::DataStore
- Extended by:
- Forwardable
- Includes:
- Singleton
- Defined in:
- lib/game_machine/data_store.rb
Instance Attribute Summary collapse
-
#store ⇒ Object
readonly
Returns the value of attribute store.
Instance Method Summary collapse
- #get(key) ⇒ Object
-
#initialize ⇒ DataStore
constructor
A new instance of DataStore.
- #set(key, value) ⇒ Object
- #set_store(store_name) ⇒ Object
Constructor Details
#initialize ⇒ DataStore
Returns a new instance of DataStore.
15 16 17 18 |
# File 'lib/game_machine/data_store.rb', line 15 def initialize @store_name = Application.config.data_store connect end |
Instance Attribute Details
#store ⇒ Object (readonly)
Returns the value of attribute store.
14 15 16 |
# File 'lib/game_machine/data_store.rb', line 14 def store @store end |
Instance Method Details
#get(key) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/game_machine/data_store.rb', line 27 def get(key) value = @store.get(key) return nil if value.nil? if value.is_a?(String) MessageLib::Entity.new.set_id(key).set_json_storage( MessageLib::JsonStorage.new.set_json(value) ) else MessageLib::Entity.parse_from(value) end end |
#set(key, value) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/game_machine/data_store.rb', line 39 def set(key,value) if value.has_json_storage @store.set(key,value.json_storage.json) else @store.set(key,value.to_byte_array) end end |
#set_store(store_name) ⇒ Object
20 21 22 23 24 |
# File 'lib/game_machine/data_store.rb', line 20 def set_store(store_name) @store = nil @store_name = store_name connect end |