Sha256: 80e541a42de2724c30091e2da50e1a3a888c5a0d9cf48bcd49f550d380cad6cc

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

require 'foreign_fqdn_routing/routing_extensions'

module ForeignFQDNRouting
  DEFAULT_NATIVE_DOMAINS = {:development => ['localhost:3000'], :test => ['test.host'], :production => ['example.com'] }
  mattr_accessor :init_native_domains
  @@init_native_domains = DEFAULT_NATIVE_DOMAINS.dup
    
  def self.native_domains
    init_native_domains[RAILS_ENV.to_sym]
  end
  
  def self.native_domains=(value)
    init_native_domains[RAILS_ENV.to_sym] = value
  end

  def self.foreign_domain?(host)
    native_domains.each do |domain|
      return false if host =~ /#{domain}\Z/i
    end
    true
  end
  
  def self.foreign_fqdn?(host)
    native_domains.each do |domain|
      return false if host =~ /\A#{domain}\Z/i
    end
    true
  end
  
  module Controller
    def self.included(controller)
      controller.helper_method(:foreign_domain?)
      controller.helper_method(:foreign_fqdn?)
    end
    
    protected
    
    def foreign_domain?
      ForeignFQDNRouting.foreign_domain?(request.host)
    end
    
    def foreign_fqdn?
      ForeignFQDNRouting.foreign_fqdn?(request.host)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
foreign-fqdn-routing-0.0.2 lib/foreign_fqdn_routing.rb
foreign-fqdn-routing-0.0.1 lib/foreign_fqdn_routing.rb