Module: Cell::RailsExtensions::ViewModel

Extended by:
ActiveSupport::Concern
Defined in:
lib/cell/rails.rb

Overview

Gets included into Cell::ViewModel in a Rails environment.

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#cache_storeObject

we want to use DI to set a cache store in cell/rails.



68
69
70
# File 'lib/cell/rails.rb', line 68

def cache_store  # we want to use DI to set a cache store in cell/rails.
  ::ActionController::Base.cache_store
end

#callObject



55
56
57
# File 'lib/cell/rails.rb', line 55

def call(*)
  super.html_safe
end

#form_authenticity_token(**options) ⇒ Object



82
83
84
# File 'lib/cell/rails.rb', line 82

def form_authenticity_token(**options)
  controller.send(:form_authenticity_token, **options)
end

#parent_controllerObject Also known as: controller



59
60
61
# File 'lib/cell/rails.rb', line 59

def parent_controller
  context[:controller]
end

#perform_caching?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/cell/rails.rb', line 64

def perform_caching?
  ::ActionController::Base.perform_caching
end

#protect_against_forgery?Boolean

In Ruby 2.4.0+, Forwardable prints a warning when you delegate to a private or protected method - so ‘delegates :protect_against_forgery?` or `delegates :form_authenticity_token` will print warnings all over the place

This workaround prevents warnings being printed

Returns:

  • (Boolean)


78
79
80
# File 'lib/cell/rails.rb', line 78

def protect_against_forgery?
  controller.send(:protect_against_forgery?)
end