Created
April 24, 2014 13:39
-
-
Save luxflux/11254936 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Daemon | |
def handle_payload(payload) | |
event_handler = EventHandler.new(payload[:id], payload) | |
event_handler.send(payload[:event]) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EventHandler | |
def initialize(id, payload) | |
@id = id | |
@payload = payload | |
end | |
def created | |
model = model_from_payload.find(@id) | |
model.write | |
end | |
alias_method :created, :updated | |
def destroyed | |
model_from_payload.delete_by_mac_address(@payload) | |
end | |
def model_from_payload | |
"PXEConfGen::#{@payload[:model]}".constantize | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment