Class: Workarea::Storefront::ContentBlockViewModel

Inherits:
ApplicationViewModel
  • Object
show all
Defined in:
app/view_models/workarea/storefront/content_block_view_model.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.wrap(model, options = {}) ⇒ Object



4
5
6
7
8
9
# File 'app/view_models/workarea/storefront/content_block_view_model.rb', line 4

def self.wrap(model, options = {})
  return model.map { |m| wrap(m, options) } if model.is_a?(Enumerable)
  model.type.view_model.constantize.new(model, options)
rescue NameError
  new(model, options)
end

Instance Method Details

#find_asset(id) ⇒ Object

This ensures memoization happens



23
24
25
26
27
28
29
# File 'app/view_models/workarea/storefront/content_block_view_model.rb', line 23

def find_asset(id)
  @assets ||= {}
  return @assets[id.to_s] if @assets[id.to_s].present?

  @assets[id.to_s] = Content::Asset.find(id) rescue
                     Content::Asset.image_placeholder
end

#localsObject



15
16
17
18
19
20
# File 'app/view_models/workarea/storefront/content_block_view_model.rb', line 15

def locals
  @locals ||= model.data.merge(
    hidden_breakpoints: model.hidden_breakpoints,
    view_model: self
  )
end

#partialObject



11
12
13
# File 'app/view_models/workarea/storefront/content_block_view_model.rb', line 11

def partial
  "workarea/storefront/content_blocks/#{model.type.slug}"
end

#seriesObject



31
32
33
# File 'app/view_models/workarea/storefront/content_block_view_model.rb', line 31

def series
  @series ||= options[:base].try(:series) || generate_series
end