lib/usher/route.rb in joshbuddy-usher-0.3.6 vs lib/usher/route.rb in joshbuddy-usher-0.4.0

- old
+ new

@@ -6,18 +6,19 @@ class Usher class Route attr_reader :paths, :original_path, :requirements, :conditions, :params, :primary_path - def initialize(original_path, router, options = {}) # :nodoc: + def initialize(original_path, router, options = nil) # :nodoc: @original_path = original_path @router = router - @requirements = options.delete(:requirements) - @conditions = options.delete(:conditions) - @transformers = options.delete(:transformers) + @requirements = options && options.delete(:requirements) + @conditions = options && options.delete(:conditions) + @transformers = options && options.delete(:transformers) @paths = @router.splitter.split(@original_path, @requirements, @transformers).collect {|path| Path.new(self, path)} @primary_path = @paths.first + #FIXME params is poorly named. this shouldn't be an array @params = [] end # Sets +options+ on a route. Returns +self+. @@ -25,11 +26,11 @@ # Request = Struct.new(:path) # set = Usher.new # route = set.add_route('/test') # route.to(:controller => 'testing', :action => 'index') # set.recognize(Request.new('/test')).first.params => {:controller => 'testing', :action => 'index'} - def to(options) - @params << options + def to(options = nil, &block) + @params << (block_given? ? block : options) self end # Sets route as referenceable from +name+. Returns +self+. #