Class: Workarea::Storefront::BlogEntryViewModel
- Inherits:
-
ApplicationViewModel
- Object
- ApplicationViewModel
- Workarea::Storefront::BlogEntryViewModel
- Includes:
- DisplayContent
- Defined in:
- app/view_models/workarea/storefront/blog_entry_view_model.rb
Instance Method Summary collapse
- #blog ⇒ Object
- #comments ⇒ Object
-
#find_asset(id) ⇒ Object
This ensures memoization happens.
- #products ⇒ Object
- #thumbnail_image_url ⇒ Object
Instance Method Details
#blog ⇒ Object
6 7 8 |
# File 'app/view_models/workarea/storefront/blog_entry_view_model.rb', line 6 def blog @blog ||= Storefront::BlogViewModel.new(model.blog) end |
#comments ⇒ Object
10 11 12 |
# File 'app/view_models/workarea/storefront/blog_entry_view_model.rb', line 10 def comments @comments ||= model.comments.approved.limit(100) end |
#find_asset(id) ⇒ Object
This ensures memoization happens
25 26 27 28 29 30 31 32 33 34 |
# File 'app/view_models/workarea/storefront/blog_entry_view_model.rb', line 25 def find_asset(id) @assets ||= {} return @assets[id.to_s] if @assets[id.to_s].present? @assets[id.to_s] = begin Content::Asset.find(id) rescue StandardError Content::Asset.image_placeholder end end |
#products ⇒ Object
14 15 16 17 18 |
# File 'app/view_models/workarea/storefront/blog_entry_view_model.rb', line 14 def products @products ||= Workarea::Storefront::ProductViewModel.wrap( Catalog::Product.find_ordered(product_ids) ) end |
#thumbnail_image_url ⇒ Object
20 21 22 |
# File 'app/view_models/workarea/storefront/blog_entry_view_model.rb', line 20 def thumbnail_image_url find_asset(model.thumbnail_image).url(host: thumbnail_image_url_host) end |