Class: Dato::Wrapper
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Dato::Wrapper
- Defined in:
- app/components/dato/wrapper.rb
Instance Attribute Summary collapse
-
#component_klass ⇒ Object
readonly
Returns the value of attribute component_klass.
-
#live ⇒ Object
readonly
Returns the value of attribute live.
-
#preview ⇒ Object
readonly
Returns the value of attribute preview.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
Instance Method Summary collapse
- #cache_key ⇒ Object
- #data ⇒ Object
-
#initialize(component_klass, query, preview: false, live: false) ⇒ Wrapper
constructor
A new instance of Wrapper.
- #live? ⇒ Boolean
- #render_in(view_context) ⇒ Object
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_klass ⇒ Object (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 |
#live ⇒ Object (readonly)
Returns the value of attribute live.
3 4 5 |
# File 'app/components/dato/wrapper.rb', line 3 def live @live end |
#preview ⇒ Object (readonly)
Returns the value of attribute preview.
3 4 5 |
# File 'app/components/dato/wrapper.rb', line 3 def preview @preview end |
#query ⇒ Object (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_key ⇒ Object
26 27 28 |
# File 'app/components/dato/wrapper.rb', line 26 def cache_key @cache_key ||= Digest::MD5.hexdigest(query.to_gql) end |
#data ⇒ Object
22 23 24 |
# File 'app/components/dato/wrapper.rb', line 22 def data @data ||= dato_fetch(query, preview: preview) end |
#live? ⇒ 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 |