Sha256: 47764ff43c1ef31143f4852c82e70883a4ac528d393d9c99d285b9c38ef9b137

Contents?: true

Size: 1.08 KB

Versions: 5

Compression:

Stored size: 1.08 KB

Contents

module Saasable::Railties
  module Helpers
    def self.included klass
      klass.extend ClassMethods
      klass.send(:include, InstanceMethods)
      klass.class_eval do
        helper_method :current_saas
        
        before_filter :_redirect_if_saas_not_found
        saas_not_found_redirect_to "/404.html"
        
        private
          def _skip_saasable
            current_saas.deactivate! if current_saas
          end
      end
    end
    
    module ClassMethods
      def saas_not_found_redirect_to path_or_url
        self.class_eval <<-METHOD, __FILE__, __LINE__ + 1
          private
            def _redirect_if_saas_not_found
              unless current_saas
                redirect_to "#{path_or_url}"
              end
            end
        METHOD
      end
      
      def skip_saasable options
        skip_before_filter :_redirect_if_saas_not_found, options
        before_filter :_skip_saasable, options
      end
    end
  
    module InstanceMethods
      def current_saas
        @current_saas ||= request.env[:saasable][:current_saas]
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
saasable-0.3.5 lib/saasable/railties/helpers.rb
saasable-0.3.3 lib/saasable/railties/helpers.rb
saasable-0.3.2 lib/saasable/railties/helpers.rb
saasable-0.3.1 lib/saasable/railties/helpers.rb
saasable-0.3.0 lib/saasable/railties/helpers.rb