Permalink
Browse files

Cache the RandomCardGenerator cards in .cards property

  • Loading branch information...
jleclanche committed Jul 10, 2015
1 parent 23ca9a8 commit f022ced67eebe34cb10d12fe2d2b0c37c35192c7
Showing with 9 additions and 2 deletions.
  1. +9 −2 fireplace/actions.py
@@ -11,10 +11,17 @@ class RandomCardGenerator(object):
"""
def __init__(self, **filters):
self.filters = filters
self._cards = None

@property
def cards(self):
if self._cards is None:
from . import cards
self._cards = cards.filter(**self.filters)
return self._cards

def pick(self) -> str:
from . import cards
return random.choice(cards.filter(**self.filters))
return random.choice(self.cards)


class Copy(object):

0 comments on commit f022ced

Please sign in to comment.