Module: SubdomainFu::MapperExtensions

Defined in:
lib/subdomain_fu/routing_extensions.rb

Instance Method Summary collapse

Instance Method Details

#quick_map(has_unless, *args, &block) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/subdomain_fu/routing_extensions.rb', line 32

def quick_map(has_unless, *args, &block)
  options = args.find{|a| a.is_a?(Hash)}
  namespace_str = options ? options.delete(:namespace).to_s : args.join('_or_')
  namespace_str += '_' unless namespace_str.blank?
  mapped_exp = args.map(&:to_s).join('|')
  conditions_hash = { :subdomain => ( has_unless ? /[^(#{mapped_exp})]/ : /(#{mapped_exp})/) }
  with_options(:conditions => conditions_hash, :name_prefix => namespace_str, &block)
end

#subdomain(*args, &block) ⇒ Object

Adds methods to Mapper to apply an options with a method. Example

map.subdomain :blog { |blog| blog.resources :pages }

or

map.unless_subdomain :blog { |not_blog| not_blog.resources :people }


44
45
46
# File 'lib/subdomain_fu/routing_extensions.rb', line 44

def subdomain(*args, &block)
  quick_map(false, *args, &block)
end

#unless_subdomain(*args, &block) ⇒ Object



47
48
49
# File 'lib/subdomain_fu/routing_extensions.rb', line 47

def unless_subdomain(*args, &block)
  quick_map(true, *args, &block)
end