Sha256: 3e6e3e7e1c17cc12784172b4c14a61f5e3ca4ee9500f1b1a8864319d10cc8e1d

Contents?: true

Size: 809 Bytes

Versions: 6

Compression:

Stored size: 809 Bytes

Contents

# Reopening WSList to add custom methods specific to this library.
module WSList

  # We want to load all routes with more globing routes last
  def self.sorted_for_sinatra_load
    globbing, no_globbing = all.partition{|ws| ws.url.include?(":") }

    all.sort do |a,b|
      a_colon_idx = a.url.index(":")
      b_colon_idx = b.url.index(":")
      a_length = a_colon_idx ? a_colon_idx + 1 : a.url.length
      b_length = b_colon_idx ? b_colon_idx + 1 : b.url.length
      if a_length == b_length
        if a_colon_idx && !b_colon_idx
          a_length -= 1
        elsif b_colon_idx && !a_colon_idx
          b_length -= 1
        else
          a_length = a.url.gsub(/\/$/, '').length
          b_length = b.url.gsub(/\/$/, '').length
        end
      end
      b_length <=> a_length
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
wd_sinatra-2.0.0 lib/wd_sinatra/ws_list_ext.rb
wd_sinatra-1.0.6 lib/wd_sinatra/ws_list_ext.rb
wd_sinatra-1.0.5 lib/wd_sinatra/ws_list_ext.rb
wd_sinatra-1.0.4 lib/wd_sinatra/ws_list_ext.rb
wd_sinatra-1.0.3 lib/wd_sinatra/ws_list_ext.rb
wd_sinatra-1.0.2 lib/wd_sinatra/ws_list_ext.rb