Class: Dato::Wrapper

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/dato/wrapper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(component_klass, query, preview: false, live: false) ⇒ Wrapper

Returns a new instance of Wrapper.



5
6
7
8
9
10
# File 'app/components/dato/wrapper.rb', line 5

def initialize(component_klass, query, preview: false, live: false)
  @component_klass = component_klass
  @query = query
  @preview = preview
  @live = live
end

Instance Attribute Details

#component_klassObject (readonly)

Returns the value of attribute component_klass.



3
4
5
# File 'app/components/dato/wrapper.rb', line 3

def component_klass
  @component_klass
end

#liveObject (readonly)

Returns the value of attribute live.



3
4
5
# File 'app/components/dato/wrapper.rb', line 3

def live
  @live
end

#previewObject (readonly)

Returns the value of attribute preview.



3
4
5
# File 'app/components/dato/wrapper.rb', line 3

def preview
  @preview
end

#queryObject (readonly)

Returns the value of attribute query.



3
4
5
# File 'app/components/dato/wrapper.rb', line 3

def query
  @query
end

Instance Method Details

#cache_keyObject



26
27
28
# File 'app/components/dato/wrapper.rb', line 26

def cache_key
  @cache_key ||= Digest::MD5.hexdigest(query.to_gql)
end

#dataObject



22
23
24
# File 'app/components/dato/wrapper.rb', line 22

def data
  @data ||= dato_fetch(query, preview: preview)
end

#live?Boolean

Returns:

  • (Boolean)


12
# File 'app/components/dato/wrapper.rb', line 12

def live? = @live

#render_in(view_context) ⇒ Object



14
15
16
17
18
19
20
# File 'app/components/dato/wrapper.rb', line 14

def render_in(view_context)
  if live?
    LiveStream.new(component_klass, query, preview: preview).render_in(view_context)
  else
    super
  end
end