Sha256: f9a2b1d911a31b5c66cc8ac85f4dd10a4e268f72f76f7c09493b4107803af5a5

Contents?: true

Size: 1.01 KB

Versions: 4

Compression:

Stored size: 1.01 KB

Contents

module Roomer
  module Extensions
    module Controller
      def self.included(base)
        base.before_filter :set_current_tenant!
      end

      protected
      # Fetches the URL Identifier
      # @return [True, False]
      def url_identifier
        case Roomer.url_routing_strategy
          when :domain
            return request.host
          when :path
            return params[:tenant_identifier]
        end
      end

      # Sets the current tenant, this method is set in the before_filter
      # @throws if tenant is not found
      def set_current_tenant!
        # Raise an exception if the current tenant is blank
        raise "No tenant found for '#{url_identifier}' url identifier" if current_tenant.blank?
        Roomer.current_tenant = current_tenant
      end

      # Returns the current tenant
      # @returns Roomer.tenant_model
      # @see Roomer.model
      def current_tenant
        @current_tenant ||= Roomer.tenant_model.find_by_url_identifier(url_identifier)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
roomer-0.0.11 lib/roomer/extensions/controller.rb
roomer-0.0.10 lib/roomer/extensions/controller.rb
roomer-0.0.9 lib/roomer/extensions/controller.rb
roomer-0.0.8 lib/roomer/extensions/controller.rb