picky-client 4.12.6 → 4.12.7

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.
@@ -11,8 +11,8 @@ p(b,n)};var o=w?h:a,e,q=function(){var b=c.text();d("live",b,o,{});clearInterval
11
11
  c=a.enclosingSelector||".picky";var i=a.formSelector||c+" form";a.form=$(i);a.input=$(a.inputSelector||i+" input[type=search]");a.reset=$(a.resetSelector||i+" div.reset");a.button=$(a.buttonSelector||i+" input[type=button]");a.counter=$(a.counterSelector||i+" div.status");a.results=$(a.resultsSelector||c+" div.results");a.noResults=$(a.noResultsSelector||c+" div.no_results");a.moreSelector=a.moreSelector||c+" div.results div.addination:last";a.allocations=$(a.allocationsSelector||c+" .allocations");
12
12
  a.shownAllocations=a.allocations.find(".shown");a.showMoreAllocations=a.allocations.find(".more");a.hiddenAllocations=a.allocations.find(".hidden");a.maxSuggestions=a.maxSuggestions||3;a.results=$(a.resultsSelector||c+" div.results");a.resultsDivider=a.resultsDivider||"";a.nonPartial=a.nonPartial||[];a.wrapResults=a.wrapResults||"<ol></ol>";var g=a.controller&&new a.controller(a)||new PickyController(a);var j=this.insert=function(k,p,r){g.insert(k,p||{},r||true)};this.resend=g.resend;this.insertFromURL=
13
13
  function(k){if(k)j(k);else(k=g.lastFullQuery())&&j(k)}};var PickyAddination=function(a,c){this.remove=function(){c.find(".addination").remove()};this.render=function(i){var g=i.total,j,k=i.renderedAmount();j=i.offset+k;k=j+k;i=i.total;if(i<k)k=i;j={offset:j,start:j+1,end:k};if(j.offset<g){g=$("<div class='addination'>"+t("results.addination.more")+"</div>");g.bind("click",{offset:j.offset},a.addinationClicked);return g}else return""}};var PickyResultsRenderer=function(a,c){var i=c.locale,g=c.explanations||{},j=c.explanation_delimiters||{},k=c.resultsDivider,p=c.wrapResults,r=c.nonPartial,w=function(d){var h=d[d.length-1];if(h===undefined)return[];d=d.slice(0,d.length-1);if(d==[])d=[d];if(!r.include(h[0]))if(h[1].match(/[^\*~]$/))h[1]+="*";d.push(h);return d};this.asteriskifyLastToken=w;var v=function(d){for(var h=g[i]||{},m=[],o,e=0,q=d.length;e<q;e++){o=d[e];var u=o[0];u=h[u]||u;m.push([u,o[1]])}return m};this.explainCategory=
14
- v;var s=function(d,h){return[d.replace(/([\w\s\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00e9\u00e8\u00e0\,]+)/,"<strong>$1</strong>"),h].join(" ")};this.strongify=s;var y=function(d,h){var m=j[i],o="",e=[],q=[];v(w(h)).each(function(u,b){var n=b[0],A=b[1];A=A.replace(/[\w,]+:(.+)/,"$1");if(o==""||n==o){e.push(A);o=n}else{var x=s(o,e.join(" "));e=[];e.push(A);o=n;q.push(x)}});q.push(s(o,e.join(" ")));q=q.join(" "+m+" ");return q='<span class="explanation">'+d+" "+q+"</span>"};this.explain=y;var f=function(d,
15
- h){var m='<div class="header">';m+=y(h.type,h.combination);if(d.offset>0)m+='<div class="tothetop"><a href="#" onclick="javascript:$(\'body\').animate({scrollTop: 0}, 500);">&uarr;</a></div>';m+="</div>";return m};this.renderHeader=f;this.render=function(d,h){h.allocations.each(function(m,o){if(o.entries.length>0){d.append(f(h,o)).append(o.entries.join(k));d.children("li").wrapAll(p)}});d.append(a.render(h))}};function AllocationRenderer(a){function c(f){var d={},h={},m={},o=[],e;e=0;for(l=f.length;e<l;e++){var q=f[e][0];if(q in d){d[q].push(f[e][1]);h[q].push(f[e][2]);o.push(e)}else{d[q]=[f[e][1]];h[q]=[f[e][2]];m[e]=q}}for(e in m){f[e][1]=d[m[e]];f[e][2]=h[m[e]]}for(e=o.length-1;e>=0;e--)f.remove(o[e]);return f}function i(f){f.map(function(d){return"%"+(d+1)+"$s"});return f.join(" ")}function g(f){if(f.length==0)return"";f=c(f);f.sort(function(u,b){return u[0]<b[0]?-1:1});for(var d=[],h=0,m=f.length;h<
14
+ v;var s=function(d,h){return["<strong>"+d+"</strong>",h].join(" ")};this.strongify=s;var y=function(d,h){var m=j[i],o="",e=[],q=[];v(w(h)).each(function(u,b){var n=b[0],A=b[1];A=A.replace(/[\w,]+:(.+)/,"$1");if(o==""||n==o){e.push(A);o=n}else{var x=s(o,e.join(" "));e=[];e.push(A);o=n;q.push(x)}});q.push(s(o,e.join(" ")));q=q.join(" "+m+" ");return q='<span class="explanation">'+d+" "+q+"</span>"};this.explain=y;var f=function(d,h){var m='<div class="header">';m+=y(h.type,h.combination);if(d.offset>
15
+ 0)m+='<div class="tothetop"><a href="#" onclick="javascript:$(\'body\').animate({scrollTop: 0}, 500);">&uarr;</a></div>';m+="</div>";return m};this.renderHeader=f;this.render=function(d,h){h.allocations.each(function(m,o){if(o.entries.length>0){d.append(f(h,o)).append(o.entries.join(k));d.children("li").wrapAll(p)}});d.append(a.render(h))}};function AllocationRenderer(a){function c(f){var d={},h={},m={},o=[],e;e=0;for(l=f.length;e<l;e++){var q=f[e][0];if(q in d){d[q].push(f[e][1]);h[q].push(f[e][2]);o.push(e)}else{d[q]=[f[e][1]];h[q]=[f[e][2]];m[e]=q}}for(e in m){f[e][1]=d[m[e]];f[e][2]=h[m[e]]}for(e=o.length-1;e>=0;e--)f.remove(o[e]);return f}function i(f){f.map(function(d){return"%"+(d+1)+"$s"});return f.join(" ")}function g(f){if(f.length==0)return"";f=c(f);f.sort(function(u,b){return u[0]<b[0]?-1:1});for(var d=[],h=0,m=f.length;h<
16
16
  m;h++)d.push(f[h][0]);var o=d.length==1,e=s[d.join(",")];if(e===undefined)e=s[d]=i(d);if(typeof e==="string"){s[d]={format:e,ignoreSingle:true};e=s[d]}var q=e.format;f.each(function(u,b){var n=b[0],A=b[1],x=b[2];x.map(function(z,B){var C=A[z];if(C.charAt(C.length-1)=="*")B+="...";return B});e.filter&&x.map(function(z,B){return e.filter(B)});if(o&&!(e&&e.ignoreSingle)){n=w[n]||n;return q=x.join("&nbsp;")+"&nbsp;("+n+")"}x.map(function(z,B){return B.replace(/[\w,]+:(.+)/,"$1")});q=q.replace(RegExp("%"+
17
17
  (u+1)+"\\$s","g"),x.join("&nbsp;"))});return q}function j(f){for(var d=[],h=0,m=v.length;h<m;h++)d.push([]);d.push([]);h=0;for(m=f.length;h<m;h++){for(var o=f[h],e=o[0],q=false,u=0,b=v.length;u<b;u++)if(v[u].include(e)){d[u].push(o);q=true;break}q||d[d.length-1].push(o)}var n;for(f=d.length-1;f>=0;f--){n=d[f];if(n.length>0)break}n=n[n.length-1];y.include(n[0])||(n[1]=n[1].valueOf()+"*");return d}function k(f){var d=[];j(f).each(function(h,m){var o=g(m);o&&d.push(o)});return d.join(" ")}var p=a.locale,
18
18
  r=a.qualifiers&&a.qualifiers[p]||{},w=a.explanations&&a.explanations[p]||{},v=a.groups||[],s=a.choices&&a.choices[p]||{},y=a.nonPartial||[];this.explanation=this.query=this.text="";this.contract=c;this.makeUpMissingFormat=i;this.rendered=g;this.groupify=j;this.querify=function(f){var d=[],h,m,o;for(o in f){h=f[o][0];h=r[h]||h;m=(m=f[o][1])||"";m=m.charAt(m.length-1)=="*"?"*":"";d[o]=h+":"+f[o][2]+m}return d.join(" ")};this.suggestify=k;this.render=function(f){return k(f.combination)}};var PickyAllocationsCloud=function(a,c){var i=c.allocations,g=c.shownAllocations,j=c.showMoreAllocations,k=c.hiddenAllocations,p=c.maxSuggestions,r=function(){i.hide()},w=function(f){r();a.allocationChosen(f)},v=new AllocationRenderer(c),s=function(f){var d=[];f.each(function(h,m){var o=v.querify(m.combination),e=v.render(m);e=$('<li><div class="text">'+e+'</div><div class="count">'+m.count+"</div></li>");e.bind("click",{query:o},w);d.push(e)});return d},y=function(f){if(f.length==0)return i.hide();
@@ -47,6 +47,7 @@ require 'net/http'
47
47
  module Picky
48
48
 
49
49
  class Client
50
+
50
51
  attr_accessor :host, :port, :path
51
52
 
52
53
  def initialize hash_or_uri = {}
@@ -123,6 +124,12 @@ module Picky
123
124
  params = defaultize params
124
125
  ::Net::HTTP.get self.host, "#{self.path}?#{params.to_query}", self.port
125
126
  end
127
+
128
+ #
129
+ #
130
+ def to_s
131
+ "#{self.class}(http://#{host}:#{port}#{path})"
132
+ end
126
133
 
127
134
  end
128
135
 
@@ -1,19 +1,17 @@
1
1
  module Picky
2
2
  class Client
3
3
 
4
- # TODO Rename?
4
+ # Replaces an item in the index (adds it if not indexed yet).
5
5
  #
6
6
  # Parameters:
7
7
  # * index_name: An index that exists in the Picky server.
8
8
  # * data: A hash in the form of { :id => 1234, :attr1 => 'attr1', :attr2 => 'attr2', ... }.
9
9
  #
10
- # TODO This should be a PUT.
11
- #
12
10
  def replace index_name, data
13
- send_off Net::HTTP::Post.new(self.path), index_name, data
11
+ send_off Net::HTTP::Put.new(self.path), index_name, data
14
12
  end
15
13
 
16
- # TODO Rename?
14
+ # Removes an item from the index.
17
15
  #
18
16
  # Parameters:
19
17
  # * index_name: An index that exists in the Picky server.
@@ -27,7 +25,7 @@ module Picky
27
25
  #
28
26
  # Note: Data is JSON encoded.
29
27
  #
30
- def send_off request, index_name, data
28
+ def send_off request, index_name, data = {}
31
29
  request.form_data = { :index => index_name, :data => ActiveSupport::JSON.encode(data) }
32
30
  Net::HTTP.new(self.host, self.port).start { |http| http.request request }
33
31
  end
@@ -2,6 +2,25 @@ require 'spec_helper'
2
2
 
3
3
  describe Picky::Client do
4
4
 
5
+ describe 'to_s' do
6
+ context 'default' do
7
+ let(:client) { described_class.new }
8
+ it 'spits out an informative string' do
9
+ client.to_s.should == 'Picky::Client(http://localhost:8080/searches)'
10
+ end
11
+ end
12
+ context 'customized' do
13
+ let(:client) do
14
+ described_class.new :host => 'somehost.com',
15
+ :port => '1234',
16
+ :path => '/hello/this/is/path'
17
+ end
18
+ it 'spits out an informative string' do
19
+ client.to_s.should == 'Picky::Client(http://somehost.com:1234/hello/this/is/path)'
20
+ end
21
+ end
22
+ end
23
+
5
24
  describe 'defaultize' do
6
25
  context 'no default params' do
7
26
  before(:each) do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: picky-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.12.6
4
+ version: 4.12.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-02 00:00:00.000000000 Z
12
+ date: 2013-01-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: yajl-ruby