Commit 8859fa78219375cd6ab5686f3de022c3ab7a0a71

Authored by Tássia Camões Araújo
1 parent 7174d454
Exists in master and in 1 other branch add_vagrant

Data repositories class inherit from Singleton() which implements the pattern.

(close #7)
Showing 1 changed file with 7 additions and 3 deletions   Show diff stats
@@ -45,9 +45,13 @@ def normalize_tags(string): @@ -45,9 +45,13 @@ def normalize_tags(string):
45 """ 45 """
46 return string.replace(':','_').replace('-','\'') 46 return string.replace(':','_').replace('-','\'')
47 47
48 -# FIXME Data repositories should be singleton 48 +class Singleton(object):
  49 + def __new__(cls, *args, **kwargs):
  50 + if '_inst' not in vars(cls):
  51 + cls._inst = object.__new__(cls)
  52 + return cls._inst
49 53
50 -class DebtagsDB(debtags.DB): 54 +class DebtagsDB(debtags.DB,Singleton):
51 def __init__(self,path): 55 def __init__(self,path):
52 self.path = path 56 self.path = path
53 57
@@ -72,7 +76,7 @@ class DebtagsDB(debtags.DB): @@ -72,7 +76,7 @@ class DebtagsDB(debtags.DB):
72 relevance_index(b))) 76 relevance_index(b)))
73 return normalize_tags(' '.join(sorted_relevant_tags[-qtd_of_tags:])) 77 return normalize_tags(' '.join(sorted_relevant_tags[-qtd_of_tags:]))
74 78
75 -class DebtagsIndex(xapian.WritableDatabase): 79 +class DebtagsIndex(xapian.WritableDatabase,Singleton):
76 def __init__(self,path): 80 def __init__(self,path):
77 self.path = path 81 self.path = path
78 self.db_md5 = 0 82 self.db_md5 = 0