class Cynic::RouteOption

Public Class Methods

new(hash={}) click to toggle source
# File lib/cynic/route_option.rb, line 3
def initialize(hash={})
  @hash = hash
end

Public Instance Methods

[](route) click to toggle source
# File lib/cynic/route_option.rb, line 7
def [](route)
  key, regex = regex_for_key(route)
  object, method = @hash[key]
  Cynic::Route.new(object, method, params(route)) if object 
end
method_missing(method, *args) click to toggle source
# File lib/cynic/route_option.rb, line 28
def method_missing(method, *args)
  @hash.send(method, *args)
end
params(route) click to toggle source
# File lib/cynic/route_option.rb, line 13
def params(route)
  key, regex = regex_for_key(route)
  return nil if regex.nil?
  matched_route = route.match(regex)
  Hash[matched_route.names.map(&:to_sym).zip(matched_route.captures)]
end
regex_for_key(key) click to toggle source
# File lib/cynic/route_option.rb, line 20
def regex_for_key(key)
  regexps.find {|k, regex| key.match regex }
end
regexps() click to toggle source
# File lib/cynic/route_option.rb, line 24
def regexps
  @hash.keys.map {|key| [key, Regexp.new("^" + key.gsub(/:(.\w+)/, '(?<\1>\w+)') + "$")] }
end