Sha256: 2be8b8c6f768f17234ce3bd0c1c8c1edd1e7aa6c853bce19356f4b48d067abdd

Contents?: true

Size: 1.62 KB

Versions: 2

Compression:

Stored size: 1.62 KB

Contents

# Thanks to Jamis Buck for ideas on this stuff
# http://weblog.jamisbuck.org/2006/10/26/monkey-patching-rails-extending-routes-2
# This is not yet a working part of SubdomainFu.

module SubdomainFu
  module RouteExtensions
    def self.included(base)
      base.alias_method_chain :recognition_conditions, :subdomain
    end

    def recognition_conditions_with_subdomain
      result = recognition_conditions_without_subdomain
      result << "conditions[:subdomain] === env[:subdomain]" if conditions[:subdomain] && conditions[:subdomain] != true && conditions[:subdomain] != false
      result << "SubdomainFu.has_subdomain?(env[:subdomain])" if conditions[:subdomain] == true
      result << "!SubdomainFu.has_subdomain?(env[:subdomain])" if conditions[:subdomain] == false
      result
    end
  end
  
  module RouteSetExtensions
    def self.included(base)
      base.alias_method_chain :extract_request_environment, :subdomain  
    end

    def extract_request_environment_with_subdomain(request)
      env = extract_request_environment_without_subdomain(request)
      env.merge(:host => request.host, :domain => request.domain, :subdomain => SubdomainFu.subdomain_from(request.host))
    end
  end
end

ActionController::Routing::RouteSet.send :include, SubdomainFu::RouteSetExtensions
ActionController::Routing::Route.send :include, SubdomainFu::RouteExtensions

# UrlRewriter::RESERVED_OPTIONS is only available in Rails >= 2.2
# http://www.portallabs.com/blog/2008/12/02/fixing-subdomain_fu-with-named-routes-rails-22/
if Rails::VERSION::MAJOR >= 2 and Rails::VERSION::MINOR >= 2
  ActionController::UrlRewriter::RESERVED_OPTIONS << :subdomain
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mbleigh-subdomain-fu-0.0.4 lib/subdomain_fu/routing_extensions.rb
mbleigh-subdomain-fu-0.0.5 lib/subdomain_fu/routing_extensions.rb