You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[STORE] Added the method_added hook to allow defining gateway methods directly in the class
Instead of calling the `gateway` method with a block, to redefine the serialize/deserialize methods:
class NoteRepository
gateway do
def serialize(document)
Hash[document.to_hash.map() { |k,v| v.upcase! if k == :title; [k,v] }]
end
def deserialize(document)
MyNote.new ActiveSupport::HashWithIndifferentAccess.new(document['_source']).deep_symbolize_keys
end
end
end
Define them directly in the class, and they will be intercepted by the hook, and (re)defined directly on the gateway:
class NoteRepository
def serialize(document)
Hash[document.to_hash.map() { |k,v| v.upcase! if k == :title; [k,v] }]
end
def deserialize(document)
MyNote.new ActiveSupport::HashWithIndifferentAccess.new(document['_source']).deep_symbolize_keys
end
end
See: http://www.ruby-doc.org/core-2.1.1/Module.html#method-i-method_added
(COMITTED WITH FINGERS CROSSED :)
0 commit comments