Commits

Michael Granger committed 0dc702f

Remove HTTP{Request,Response}#notes multi-level autovivification

  • Participants
  • Parent commits c844fb4

Comments (6)

  1. Michael Granger author

    Mahlon Smith What do you think of this? Does this break anything in StaticCling? I'm finding that the notes hash autovivifying more than one level deep is actually causing more harm than good, especially when checking for the absence of a note value in a template. Instead of:

    <?call request.notes[:nr][:rum_header] ?>
    

    I have to do:

    <?unless request.notes[:nr][:rum_header].empty? ?>
    <?call request.notes[:nr][:rum_header] ?>
    <?end unless ?>
    

    Otherwise I get a '{}' inserted into the template. If this is going to cause too much headache, I'll just keep this as a topic branch. Otherwise plz to Approve. :P

  2. Mahlon Smith

    Nothing broken. I think that's much more natural, expected behavior. Approved! :) Now, maybe on Wednesday we can discuss something similar over in Configurability-land.... :D

Files changed (4)

lib/strelka/httprequest.rb

 		@uri     = nil
 		@verb    = self.headers[:method].to_sym
 		@params  = nil
-		@notes   = Hash.new( &method(:autovivify) )
+		@notes   = Hash.new {|h,k| h[k] = {} }
 		@cookies = nil
 	end
 

lib/strelka/httpresponse.rb

 		@charset   = nil
 		@languages = []
 		@encodings = []
-		@notes     = Hash.new( &method(:autovivify) )
+		@notes     = Hash.new {|h,k| h[k] = {} }
 		@cookies   = nil
 
 		super

spec/strelka/app/filters_spec.rb

 				res = @app.new.handle( req )
 
 				req.notes[:saw][:request].should be_true()
-				res.notes[:saw][:response].should be_empty()
+				res.notes[:saw][:response].should be_nil()
 			end
 
 		end
 
 				res = @app.new.handle( req )
 
-				req.notes[:saw][:request].should be_empty()
+				req.notes[:saw][:request].should be_nil()
 				res.notes[:saw][:response].should be_true()
 			end
 

spec/strelka/httprequest_spec.rb

 		it "can get and set notes for communication between plugins" do
 			@req.notes.should be_a( Hash )
 			@req.notes[:routing].should be_a( Hash )
-			@req.notes[:routing][:route].should be_a( Hash )
 		end
 
 		it "can redirect the request to a different URI" do