picky 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
| @@ -4,8 +4,16 @@ class Hash | |
| 4 4 |  | 
| 5 5 | 
             
              # Dumps binary self to the path given.
         | 
| 6 6 | 
             
              #
         | 
| 7 | 
            +
              # TODO Still used? If yes, spec!
         | 
| 8 | 
            +
              #
         | 
| 7 9 | 
             
              def dump_to path
         | 
| 8 10 | 
             
                File.open(path, 'w:binary') { |out_file| Marshal.dump self, out_file }
         | 
| 9 11 | 
             
              end
         | 
| 10 12 |  | 
| 13 | 
            +
              # Use yajl's encoding.
         | 
| 14 | 
            +
              #
         | 
| 15 | 
            +
              def to_json options = {}
         | 
| 16 | 
            +
                Yajl::Encoder.encode self, options
         | 
| 17 | 
            +
              end
         | 
| 18 | 
            +
              
         | 
| 11 19 | 
             
            end
         | 
    
        data/lib/picky/results/base.rb
    CHANGED
    
    | @@ -1,6 +1,7 @@ | |
| 1 1 | 
             
            module Results
         | 
| 2 2 |  | 
| 3 | 
            -
              # This is the internal results object. Usually, to_marshal, or to_json | 
| 3 | 
            +
              # This is the internal results object. Usually, to_marshal, or to_json
         | 
| 4 | 
            +
              # is called on it to get a string for the answer.
         | 
| 4 5 | 
             
              #
         | 
| 5 6 | 
             
              class Base
         | 
| 6 7 |  | 
| @@ -32,10 +33,10 @@ module Results | |
| 32 33 | 
             
                              :duration    => duration,
         | 
| 33 34 | 
             
                              :total       => total)
         | 
| 34 35 | 
             
                end
         | 
| 35 | 
            -
                #  | 
| 36 | 
            +
                # The default format is json.
         | 
| 36 37 | 
             
                #
         | 
| 37 | 
            -
                def  | 
| 38 | 
            -
                   | 
| 38 | 
            +
                def to_response options = {}
         | 
| 39 | 
            +
                  to_json options
         | 
| 39 40 | 
             
                end
         | 
| 40 41 | 
             
                # Convert to json format.
         | 
| 41 42 | 
             
                #
         | 
    
        data/lib/picky/results/full.rb
    CHANGED
    
    
    
        data/prototype_project/Gemfile
    CHANGED
    
    
| @@ -4,7 +4,42 @@ describe Hash do | |
| 4 4 |  | 
| 5 5 | 
             
              describe 'dump_to' do
         | 
| 6 6 | 
             
                it 'should description' do
         | 
| 7 | 
            -
             | 
| 7 | 
            +
                  # TODO
         | 
| 8 | 
            +
                end
         | 
| 9 | 
            +
              end
         | 
| 10 | 
            +
              
         | 
| 11 | 
            +
              describe "to_json" do
         | 
| 12 | 
            +
                before(:each) do
         | 
| 13 | 
            +
                  # A very realistic example.
         | 
| 14 | 
            +
                  #
         | 
| 15 | 
            +
                  @obj = { :allocations => [
         | 
| 16 | 
            +
                      ['c', 17.53, 275179, [["name","s*","s"]],[]],
         | 
| 17 | 
            +
                      ['c', 15.01, 164576, [["category","s*","s"]],[]],
         | 
| 18 | 
            +
                      ['p', 12.94, 415634, [["street","s*","s"]],[]],
         | 
| 19 | 
            +
                      ['p', 12.89, 398247, [["name","s*","s"]],[]],
         | 
| 20 | 
            +
                      ['p', 12.67, 318912, [["city","s*","s"]],[]],
         | 
| 21 | 
            +
                      ['p', 12.37, 235933, [["first_name","s*","s"]],[]],
         | 
| 22 | 
            +
                      ["p", 11.76, 128259, [["maiden_name","s*","s"]],[]],
         | 
| 23 | 
            +
                      ['p', 11.73, 124479, [["occupation","s*","s"]],[]],
         | 
| 24 | 
            +
                      ['c', 11.35,  84807, [["street","s*","s"]],[]],
         | 
| 25 | 
            +
                      ['c', 11.15,  69301, [["city","s*","s"]],[]],
         | 
| 26 | 
            +
                      ['p', 4.34,      77, [["street_number","s*","s"]],[]],
         | 
| 27 | 
            +
                      ['c', 2.08,       8, [["street_number","s*","s"]],[]],
         | 
| 28 | 
            +
                      ['c', 1.61,       5, [["adword","s*","s"]],[]]
         | 
| 29 | 
            +
                    ],
         | 
| 30 | 
            +
                    :offset   => 0,
         | 
| 31 | 
            +
                    :duration => 0.04,
         | 
| 32 | 
            +
                    :total    => 2215417
         | 
| 33 | 
            +
                  }
         | 
| 34 | 
            +
                end
         | 
| 35 | 
            +
                it "should be correct" do
         | 
| 36 | 
            +
                  @obj.to_json.should == '{"allocations":[["c",17.53,275179,[["name","s*","s"]],[]],["c",15.01,164576,[["category","s*","s"]],[]],["p",12.94,415634,[["street","s*","s"]],[]],["p",12.89,398247,[["name","s*","s"]],[]],["p",12.67,318912,[["city","s*","s"]],[]],["p",12.37,235933,[["first_name","s*","s"]],[]],["p",11.76,128259,[["maiden_name","s*","s"]],[]],["p",11.73,124479,[["occupation","s*","s"]],[]],["c",11.35,84807,[["street","s*","s"]],[]],["c",11.15,69301,[["city","s*","s"]],[]],["p",4.34,77,[["street_number","s*","s"]],[]],["c",2.08,8,[["street_number","s*","s"]],[]],["c",1.61,5,[["adword","s*","s"]],[]]],"offset":0,"duration":0.04,"total":2215417}'
         | 
| 37 | 
            +
                end
         | 
| 38 | 
            +
                it "should take options" do
         | 
| 39 | 
            +
                  lambda { @obj.to_json(:some => :option) }.should_not raise_error
         | 
| 40 | 
            +
                end
         | 
| 41 | 
            +
                it "should be fast" do
         | 
| 42 | 
            +
                  Benchmark.realtime { @obj.to_json }.should < 0.00006
         | 
| 8 43 | 
             
                end
         | 
| 9 44 | 
             
              end
         | 
| 10 45 |  | 
| @@ -30,17 +30,6 @@ describe Results do | |
| 30 30 | 
             
                  end
         | 
| 31 31 | 
             
                end
         | 
| 32 32 | 
             
              end
         | 
| 33 | 
            -
              
         | 
| 34 | 
            -
              describe 'to_marshal' do
         | 
| 35 | 
            -
                before(:each) do
         | 
| 36 | 
            -
                  @results = Results::Base.new
         | 
| 37 | 
            -
                end
         | 
| 38 | 
            -
                it 'should do it correctly' do
         | 
| 39 | 
            -
                  @results.stub! :serialize => :serialized
         | 
| 40 | 
            -
             | 
| 41 | 
            -
                  @results.to_marshal.should == "\x04\b:\x0Fserialized"
         | 
| 42 | 
            -
                end
         | 
| 43 | 
            -
              end
         | 
| 44 33 |  | 
| 45 34 | 
             
              describe 'to_json' do
         | 
| 46 35 | 
             
                before(:each) do
         | 
    
        data/spec/lib/routing_spec.rb
    CHANGED
    
    | @@ -88,7 +88,7 @@ describe Routing do | |
| 88 88 | 
             
                  @routing.route '/searches/some_route' => Query::Full.new(:some_index, :some_other_index)
         | 
| 89 89 |  | 
| 90 90 | 
             
                  @routing.routes.freeze
         | 
| 91 | 
            -
                  @routing.call(env).should == [200, {"Content-Type"=>"application/octet-stream", "Content-Length"=>" | 
| 91 | 
            +
                  @routing.call(env).should == [200, {"Content-Type"=>"application/octet-stream", "Content-Length"=>"52"}, ["{\"allocations\":[],\"offset\":0,\"duration\":0,\"total\":0}"]]
         | 
| 92 92 | 
             
                end
         | 
| 93 93 | 
             
                it 'should route correctly' do
         | 
| 94 94 | 
             
                  env = rack_defaults_for '/searches/some_route?query=some_query&type=some_type'
         | 
| @@ -100,7 +100,7 @@ describe Routing do | |
| 100 100 | 
             
                  @routing.route '/searches/some_route' => Query::Full.new(:some_index, :some_other_index), :query => { :type => :some_type }
         | 
| 101 101 |  | 
| 102 102 | 
             
                  @routing.routes.freeze
         | 
| 103 | 
            -
                  @routing.call(env).should == [200, {"Content-Type"=>"application/octet-stream", "Content-Length"=>" | 
| 103 | 
            +
                  @routing.call(env).should == [200, {"Content-Type"=>"application/octet-stream", "Content-Length"=>"52"}, ["{\"allocations\":[],\"offset\":0,\"duration\":0,\"total\":0}"]]
         | 
| 104 104 | 
             
                end
         | 
| 105 105 | 
             
                it 'should route correctly' do
         | 
| 106 106 | 
             
                  env = rack_defaults_for '/searches/some_wrong_route?query=some_query'
         |