Sha256: 4f3355df2fa5cacb02db771c4a11c59e9ba922d45418e7fb859dec40e6256351
Contents?: true
Size: 1.33 KB
Versions: 8
Compression:
Stored size: 1.33 KB
Contents
module RailsConnector class CmsEnv OBJ_ENV_KEY = "INFOPARK_OBJ" def initialize(env) @env = env end def load return if env[OBJ_ENV_KEY] load_object end protected attr_reader :env def load_object env[OBJ_ENV_KEY] = begin find_obj rescue StandardError => e e end end def find_obj found_obj = if params[:id] Obj.find(params[:id]) elsif params[:permalink].present? permalink = Array(params[:permalink]).join("/") Obj.find_by_permalink!(permalink) else if callback = RailsConnector::Configuration.choose_homepage_callback callback_result = callback.call(env) if callback_result.is_a?(Obj) callback_result else raise "choose_homepage callback did not return an Obj. "\ "Instead saw #{callback_result.class}." end else Obj.homepage end end if found_obj.suppressed? raise RailsConnector::ResourceNotFound, "Tried to access Obj #{found_obj.inspect}, but it is suppressed (suppress_export is set)!" end found_obj end def params env["action_dispatch.request.path_parameters"] end end end
Version data entries
8 entries across 8 versions & 1 rubygems