Class: Rad::Request

Inherits:
Rack::Request
  • Object
show all
Defined in:
lib/rad/http/support/rack/request.rb

Instance Method Summary collapse

Instance Method Details

#cookies_with_memoryObject



32
33
34
# File 'lib/rad/http/support/rack/request.rb', line 32

def cookies_with_memory
  @cookies_with_memory ||= cookies_without_memory
end

#domain(tld_length = 1) ⇒ Object

Returns the domain part of a host, such as “rubyonrails.org” in “www.rubyonrails.org”. You can specify a different tld_length, such as 2 to catch rubyonrails.co.uk in “www.rubyonrails.co.uk”.



26
27
28
29
30
# File 'lib/rad/http/support/rack/request.rb', line 26

def domain(tld_length = 1)
  return nil unless named_host?(host)

  host.split('.').last(1 + tld_length).join('.')
end

#subdomains(tld_length = 1) ⇒ Object

Returns all the subdomains as an array, so ["dev", "www"] would be returned for “dev.www.rubyonrails.org”. You can specify a different tld_length, such as 2 to catch ["www"] instead of ["www", "rubyonrails"] in “www.rubyonrails.co.uk”.



17
18
19
20
21
# File 'lib/rad/http/support/rack/request.rb', line 17

def subdomains(tld_length = 1)
  return [] unless named_host?(host)
  parts = host.split('.')
  parts[0..-(tld_length+2)]
end