-
-
Save nixterrimus/4592571 to your computer and use it in GitHub Desktop.
DevicePersistanceThing | |
def self.load(target_uuid) | |
# Get associated associated adapter, ask AdapterPersistanceThing | |
# attributes = query persistance store for uuid | |
# Setup Device with attributes & adapter | |
# return device | |
end | |
def self.save(device) | |
# Serialize device | |
# Save it out to the persistance store with store[uuid] = serialized | |
# return true if save, false if problems | |
end | |
end |
Perhaps another idea- I currently have a devices object. It does have the persistance store. Maybe persistance belongs to the collection. Still hacky?
What is your motivation for providing persistance at all? Shouldn't the state be saved in the class for the duration of the program and shut everything off once the program's been terminated? Or are you talking about saving states?
If you decide persistance is what you're looking for, this module could serialize the object (maybe each Device
has a #serialize
method?) and store it. I think each Device
would include the Persistable
module if the class could be persisted as defined.
Good thoughts. The idea with saving devices is that if you setup a bunch of devices then close the program, then the next time you open it all of your devices are still there.
You are totally right that some things should not be persisted though. Take for example the brightness of a light. It's not worth persisting because the next time the program fires up we can just fire off a request to the lamp to get it's current brightness. So it's really the device's unique identifier (uuid) and adapter specific information (light #1 to the hue adapter) that needs to get saved.
Also adapter need to get saved.
And then everything needs to get linked back up.
But what I'm thinking about (and really not sure about) is whether device should ANYTHING about how it's serialized or stored and the same for adapter. I don't think persistance is a responsibility of a device. Serialization might be. Each device could implement a serialize
method with the information it feels is important. 👍, good thought.
Persistable module is also interesting, but I think what each device considers important may very. I need to think about it more.
Does it make sense to have a persistance object? Or should this code be in Device::Base? I'm think it doesn't make sense for an object to have an idea how it's persisted. I would rather Devices not have any idea about the store.