commit:     215091d5d1abeb9c38540eb0bb569851a3de1ba6
Author:     Alex Legler <alex <AT> a3li <DOT> li>
AuthorDate: Sun Feb 22 23:50:38 2015 +0000
Commit:     Alex Legler <a3li <AT> gentoo <DOT> org>
CommitDate: Sun Feb 22 23:50:38 2015 +0000
URL:        http://sources.gentoo.org/gitweb/?p=proj/ag.git;a=commit;h=215091d5

Refactor id resolving method to a more generic function

---
 lib/storage.rb | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/lib/storage.rb b/lib/storage.rb
index 660b300..37083fa 100644
--- a/lib/storage.rb
+++ b/lib/storage.rb
@@ -93,8 +93,8 @@ module Ag::Storage
     content
   end
 
-  def resolve_message_id(list, message_id = nil)
-    return nil if message_id == nil
+  def resolve_by_field(list, field, value)
+    return nil if value == nil
 
     result = $es.search(
       index: 'ml-' + list,
@@ -102,7 +102,7 @@ module Ag::Storage
         query: {
           filtered: {
             filter: {
-              term: { raw_message_id: message_id }
+              term: { field => value }
             }
           }
         },
@@ -111,10 +111,17 @@ module Ag::Storage
     )
 
     return nil if result['hits']['total'] == 0
-
     result['hits']['hits'].first['_id']
   end
 
+  def resolve_message_id(list, message_id = nil)
+    resolve_by_field(list, :raw_message_id, message_id)
+  end
+
+  def resolve_filename(list, filename)
+    resolve_by_field(list, :raw_filename, filename)
+  end
+
   def store(list, message, filename)
     content = get_content(message, filename)
 

Reply via email to