41b76a0d9fd81133d545fb2b994013ab

So i need to define @purl_base and @user. @user needs to be defined only if the url navigated to has a subdomain (g.manley.personalurl.com). @purl_base is currently being defined by sub'ing out the subdomain but if there is no subdomain then obviously it doesn't need to be subbed out. I currently have a semi working version of it but its pretty clunky and wanted to see if there was a better way like maybe even a rack function that i missed that defines the base url.

Its a sinatra app using datamapper.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
  module Rack
    class Request
      def subdomains
        @env['rack.env.subdomains'] ||= lambda {
          return [] if (host.nil? ||
          /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.match(host))
          host.split('.')[0...-2]
          }.call
        end
      end
    end

    before do
      @purl_base = if request.subdomains.empty? then request.host else request.host.sub("#{request.subdomains.join('.')}.", "") end #personalurl.com
      @purl = Purl.first(:purl => @purl_base)
      Purl.current = @purl
      @user = CData.first(:unique_name => request.subdomains.join('.')) unless request.subdomains.empty? #g.manley
    end

    get '/' do
      if
        request.subdomains.empty?
        then
        erb :"#{@purl.name}/blank"
      else
        erb :"#{@purl.name}/index"
      end
    end

Refactorings

No refactoring yet !

Your refactoring





Format Copy from initial code

or Cancel