Class: CacheCrispies::Collection
- Inherits:
-
Object
- Object
- CacheCrispies::Collection
- Defined in:
- lib/cache_crispies/collection.rb
Overview
Handles rendering and possibly caching a collection of models using a
Serializer
Instance Method Summary collapse
-
#as_json ⇒ Hash
Renders the collection to a JSON-ready Hash trying to cache the hash along the way.
-
#initialize(collection, serializer, options = {}) ⇒ Collection
constructor
Initializes a new instance of CacheCrispies::Collection.
Constructor Details
#initialize(collection, serializer, options = {}) ⇒ Collection
Initializes a new instance of CacheCrispies::Collection
14 15 16 17 18 |
# File 'lib/cache_crispies/collection.rb', line 14 def initialize(collection, serializer, = {}) @collection = collection @serializer = serializer @options = end |
Instance Method Details
#as_json ⇒ Hash
Renders the collection to a JSON-ready Hash trying to cache the hash
along the way
24 25 26 27 28 29 30 |
# File 'lib/cache_crispies/collection.rb', line 24 def as_json if serializer.do_caching? && collection.respond_to?(:cache_key) cached_json else uncached_json end end |