Commit 44c9952
committed
[STORE] Added the
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 :)method_added hook to allow defining gateway methods directly in the class1 parent cbbff17 commit 44c9952
File tree
2 files changed
+33
-3
lines changed- elasticsearch-persistence
- lib/elasticsearch/persistence
- test/unit
2 files changed
+33
-3
lines changedLines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
38 | 44 | | |
39 | 45 | | |
40 | 46 | | |
| |||
Lines changed: 27 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
89 | | - | |
90 | | - | |
| 89 | + | |
| 90 | + | |
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
100 | | - | |
| 100 | + | |
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
| |||
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
116 | 140 | | |
117 | 141 | | |
118 | 142 | | |
| |||
0 commit comments