Sha256: 96091312b1ee3df8b6093aa39bb1b88d56cbcf94cf27a5d292d0bd20c3c59617

Contents?: true

Size: 993 Bytes

Versions: 1

Compression:

Stored size: 993 Bytes

Contents

#:enddoc:
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 RailsConnector::ResourceNotFound => e
          e
        end
    end

    def find_obj
      found_obj =
        if params[:id]
          Obj.find(params[:id])
        elsif params[:permalink].present?
          permalink =  params[:permalink].to_a.join("/")
          Obj.find_by_permalink!(permalink)
        else
          Obj.homepage
        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

1 entries across 1 versions & 1 rubygems

Version Path
infopark_rails_connector-6.8.0.beta.200.621.4c8e1b0 lib/rails_connector/cms_env.rb