class Gors::Routes

Constants

NAME_PATTERN

Attributes

models[RW]
posts[RW]
routes[RW]

Public Class Methods

new(logger) click to toggle source
# File lib/gors.rb, line 112
def initialize logger
  @routes = {}
  @models = {}
  @logger = logger
  @routespost = {}
end

Public Instance Methods

build_regex(signature) click to toggle source
# File lib/gors.rb, line 163
def build_regex signature
    return %r(^#{signature}$) unless signature.include?(':')

    groups = signature.split('/').map do |part|
      next part if part.empty?
      next part unless part.start_with? ':'
      name = NAME_PATTERN.match(part)[1]
      %Q{(?<#{name}>\\S+)}
    end.select {|s| !s.empty? }.join('\/')

    %r(^\/#{groups}$)
end
get(hash) click to toggle source
# File lib/gors.rb, line 119
def get hash
  @routes[pattern_for(hash.keys.first.to_s)] = hash[hash.keys.first.to_s]
  @logger.log "Adding route GET "+hash.keys.first.to_s
end
json() click to toggle source
# File lib/gors.rb, line 124
def json
  # TODO zorg evoor dat routes ook van routes.json gehaald kunnen worden (structuur zie generator in de CLI)
end
model(hash) click to toggle source
# File lib/gors.rb, line 137
def model hash
  @routes["/api/"+hash.keys.first.to_s] = "Gors::Model#call:"+hash[hash.keys.first.to_s];
  puts "Adding model with path "+hash.keys.first.to_s
end
pattern_for(signature) click to toggle source

Logic from github.com/alisnic/nyny

# File lib/gors.rb, line 156
def pattern_for signature
    if(signature.class == Regexp)
      return signature
    end
    build_regex(signature.start_with?('/') ? signature : "/#{signature}")
end
post(hash) click to toggle source
# File lib/gors.rb, line 128
def post hash
  @routespost[hash.keys.first.to_s] = hash[hash.keys.first.to_s]
  @logger.log "Adding route POST "+hash.keys.first.to_s
end