##// END OF EJS Templates
add LazyConfig.prepend
MinRK -
Show More
@@ -90,6 +90,7 b' class LazyConfigValue(HasTraits):'
90 90
91 91 # list methods
92 92 _extend = List()
93 _prepend = List()
93 94
94 95 def append(self, obj):
95 96 self._extend.append(obj)
@@ -97,6 +98,10 b' class LazyConfigValue(HasTraits):'
97 98 def extend(self, other):
98 99 self._extend.extend(other)
99 100
101 def prepend(self, other):
102 """like list.extend, but for the front"""
103 self._prepend[:0] = other
104
100 105 _inserts = List()
101 106 def insert(self, index, other):
102 107 if not isinstance(index, int):
@@ -129,7 +134,9 b' class LazyConfigValue(HasTraits):'
129 134 if isinstance(value, list):
130 135 for idx, obj in self._inserts:
131 136 value.insert(idx, obj)
137 value[:0] = self._prepend
132 138 value.extend(self._extend)
139
133 140 elif isinstance(value, dict):
134 141 if self._update:
135 142 value.update(self._update)
@@ -142,13 +149,15 b' class LazyConfigValue(HasTraits):'
142 149 def to_dict(self):
143 150 """return JSONable dict form of my data
144 151
145 Currently update as dict or set, extend as list, and inserts as list of tuples.
152 Currently update as dict or set, extend, prepend as lists, and inserts as list of tuples.
146 153 """
147 154 d = {}
148 155 if self._update:
149 156 d['update'] = self._update
150 157 if self._extend:
151 158 d['extend'] = self._extend
159 if self._prepend:
160 d['prepend'] = self._prepend
152 161 elif self._inserts:
153 162 d['inserts'] = self._inserts
154 163 return d
General Comments 0
You need to be logged in to leave comments. Login now