picky-client 4.6.3 → 4.6.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -36,7 +36,7 @@ module Picky
36
36
 
37
37
  @current_text = ''
38
38
  @id_amount = id_amount && Integer(id_amount) || 20
39
- @client = Picky::Client.new :host => (uri.host || 'localhost'), :port => (uri.port || 8080), :path => uri.path
39
+ @client = Picky::Client.new uri
40
40
 
41
41
  install_trap
42
42
  end
@@ -31,7 +31,7 @@ module Picky
31
31
  @cursor_offset = 0
32
32
  @last_ids = ''
33
33
  @id_amount = id_amount && Integer(id_amount) || 20
34
- @client = Picky::Client.new :host => (uri.host || 'localhost'), :port => (uri.port || 8080), :path => uri.path
34
+ @client = Picky::Client.new uri
35
35
 
36
36
  install_trap
37
37
  end
@@ -52,36 +52,41 @@ module Picky
52
52
  #
53
53
  client = options[:client] ||
54
54
  (options[:path] ||= '/') && Picky::Client.new(options)
55
-
56
- self.class.class_eval do
57
- index_name = options[:index]
55
+ index_name = options[:index]
58
56
 
59
- define_method :extended do |model|
60
- attributes = nil if attributes.empty?
61
- index_name ||= model.table_name
57
+ # Install.
58
+ #
59
+ install_extended_on client, index_name, attributes
60
+ end
61
+
62
+ # Installs an extended method on client which
63
+ # handles the model passed to it.
64
+ #
65
+ def install_extended_on client, index_name, attributes
66
+ self.class.send :define_method, :extended do |model|
67
+ attributes = nil if attributes.empty?
68
+ index_name ||= model.table_name
62
69
 
63
- # Only after the database has actually
64
- # updated the data do we want to index.
65
- #
66
- model.after_commit do |object|
67
- data = { 'id' => object.id }
70
+ # Only after the database has actually
71
+ # updated the data do we want to index.
72
+ #
73
+ model.after_commit do |object|
74
+ data = { 'id' => object.id }
68
75
 
69
- if object.destroyed?
70
- client.remove index_name, data
71
- else
72
- (attributes || object.attributes.keys).each do |attr|
73
- data[attr] = object.respond_to?(attr) &&
74
- object.send(attr) ||
75
- object[attr]
76
- end
77
-
78
- client.replace index_name, data
76
+ if object.destroyed?
77
+ client.remove index_name, data
78
+ else
79
+ (attributes || object.attributes.keys).each do |attr|
80
+ data[attr] = object.respond_to?(attr) &&
81
+ object.send(attr) ||
82
+ object[attr]
79
83
  end
84
+
85
+ client.replace index_name, data
80
86
  end
81
-
82
87
  end
88
+
83
89
  end
84
-
85
90
  end
86
91
 
87
92
  end
@@ -49,7 +49,20 @@ module Picky
49
49
  class Client
50
50
  attr_accessor :host, :port, :path
51
51
 
52
- def initialize options = {}
52
+ def initialize hash_or_uri = {}
53
+ if hash_or_uri.respond_to? :to_hash
54
+ initialize_from_hash hash_or_uri
55
+ else
56
+ initialize_from_uri hash_or_uri
57
+ end
58
+ end
59
+ def initialize_from_uri uri
60
+ initialize_from_hash :host => uri.host,
61
+ :port => uri.port,
62
+ :path => uri.path
63
+
64
+ end
65
+ def initialize_from_hash options
53
66
  options = default_configuration.merge options
54
67
 
55
68
  @host = options[:host]
@@ -0,0 +1,3 @@
1
+ ENV['PICKY_ENV'] ||= ENV['RUBY_ENV'] || ENV['RACK_ENV']
2
+ PICKY_ENVIRONMENT = ENV['PICKY_ENV'] || 'development' unless defined? PICKY_ENVIRONMENT
3
+ PICKY_ROOT = Dir.pwd unless defined? PICKY_ROOT
@@ -4,21 +4,41 @@ module Picky
4
4
  #
5
5
  class Helper
6
6
 
7
- @@localized_input = lambda { |options|
7
+ # Returns a standard search interface for easy starting.
8
+ #
9
+ # ... aka scaffolding ;)
10
+ #
11
+ # Options:
12
+ # * button: The search button text.
13
+ # * no_results: The text shown when there are no results.
14
+ # * more: The text shown when there are more than X results.
15
+ #
16
+ # Usage, in Views:
17
+ #
18
+ # = Picky::Helper.interface :button => 'Go go go!'
19
+ #
20
+ #
21
+ def self.interface options = {}
22
+ <<-HTML
23
+ <section class="picky">
24
+ #{input(options)}
25
+ #{results(options)}
26
+ </section>
27
+ HTML
28
+ end
29
+ def self.input options = {}
8
30
  search_button_text = options[:button] || 'search'
9
31
  placeholder_text = options[:placeholder] || 'Search here...'
10
32
  <<-HTML
11
33
  <form class="empty" onkeypress="return event.keyCode != 13;">
12
- <!-- <div class="feedback"> -->
13
34
  <div class="status"></div>
14
35
  <input type="search" placeholder="#{placeholder_text}" autocorrect="off" class="query"/>
15
36
  <a class="reset" title="clear"></a>
16
- <!-- </div> -->
17
37
  <input type="button" value="#{search_button_text}"/>
18
38
  </form>
19
39
  HTML
20
- }
21
- @@localized_results = lambda { |options|
40
+ end
41
+ def self.results options = {}
22
42
  no_results = options[:no_results] || 'Sorry, no results found!'
23
43
  more_allocations = options[:more] || 'more'
24
44
  <<-HTML
@@ -30,38 +50,6 @@ HTML
30
50
  <ol class="hidden"></ol>
31
51
  </div>
32
52
  HTML
33
- }
34
- @@localized_interface = lambda { |options|
35
- <<-HTML
36
- <section class="picky">
37
- #{@@localized_input[options]}
38
- #{@@localized_results[options]}
39
- </section>
40
- HTML
41
- }
42
-
43
- # Returns a standard search interface for easy starting.
44
- #
45
- # ... aka scaffolding ;)
46
- #
47
- # Options:
48
- # * button: The search button text.
49
- # * no_results: The text shown when there are no results.
50
- # * more: The text shown when there are more than X results.
51
- #
52
- # Usage, in Views:
53
- #
54
- # = Picky::Helper.interface :button => 'Go go go!'
55
- #
56
- #
57
- def self.interface options = {}
58
- @@localized_interface[options]
59
- end
60
- def self.input options = {}
61
- @@localized_input[options]
62
- end
63
- def self.results options = {}
64
- @@localized_results[options]
65
53
  end
66
54
 
67
55
  # Returns a cached version if you always use a single language.
data/lib/picky-client.rb CHANGED
@@ -4,6 +4,7 @@ require 'rubygems'
4
4
  require 'yajl'
5
5
 
6
6
  dir = File.dirname __FILE__
7
+ require File.expand_path('picky-client/constants', dir)
7
8
  require File.expand_path('picky-client/client', dir)
8
9
  require File.expand_path('picky-client/client_index', dir)
9
10
  require File.expand_path('picky-client/convenience', dir)
@@ -19,28 +19,28 @@ describe Picky::Helper do
19
19
 
20
20
  describe "input" do
21
21
  it "should return good html" do
22
- Picky::Helper.input.should == "<form class=\"empty\" onkeypress=\"return event.keyCode != 13;\">\n <!-- <div class=\"feedback\"> -->\n <div class=\"status\"></div>\n <input type=\"search\" placeholder=\"Search here...\" autocorrect=\"off\" class=\"query\"/>\n <a class=\"reset\" title=\"clear\"></a>\n <!-- </div> -->\n <input type=\"button\" value=\"search\"/>\n</form>\n"
22
+ Picky::Helper.input.should == "<form class=\"empty\" onkeypress=\"return event.keyCode != 13;\">\n <div class=\"status\"></div>\n <input type=\"search\" placeholder=\"Search here...\" autocorrect=\"off\" class=\"query\"/>\n <a class=\"reset\" title=\"clear\"></a>\n <input type=\"button\" value=\"search\"/>\n</form>\n"
23
23
  end
24
24
  it "should return good html" do
25
- Picky::Helper.input(:button => 'find').should == "<form class=\"empty\" onkeypress=\"return event.keyCode != 13;\">\n <!-- <div class=\"feedback\"> -->\n <div class=\"status\"></div>\n <input type=\"search\" placeholder=\"Search here...\" autocorrect=\"off\" class=\"query\"/>\n <a class=\"reset\" title=\"clear\"></a>\n <!-- </div> -->\n <input type=\"button\" value=\"find\"/>\n</form>\n"
25
+ Picky::Helper.input(:button => 'find').should == "<form class=\"empty\" onkeypress=\"return event.keyCode != 13;\">\n <div class=\"status\"></div>\n <input type=\"search\" placeholder=\"Search here...\" autocorrect=\"off\" class=\"query\"/>\n <a class=\"reset\" title=\"clear\"></a>\n <input type=\"button\" value=\"find\"/>\n</form>\n"
26
26
  end
27
27
  end
28
28
 
29
29
  describe "results" do
30
30
  it "should return good html" do
31
- Picky::Helper.input.should == "<form class=\"empty\" onkeypress=\"return event.keyCode != 13;\">\n <!-- <div class=\"feedback\"> -->\n <div class=\"status\"></div>\n <input type=\"search\" placeholder=\"Search here...\" autocorrect=\"off\" class=\"query\"/>\n <a class=\"reset\" title=\"clear\"></a>\n <!-- </div> -->\n <input type=\"button\" value=\"search\"/>\n</form>\n"
31
+ Picky::Helper.input.should == "<form class=\"empty\" onkeypress=\"return event.keyCode != 13;\">\n <div class=\"status\"></div>\n <input type=\"search\" placeholder=\"Search here...\" autocorrect=\"off\" class=\"query\"/>\n <a class=\"reset\" title=\"clear\"></a>\n <input type=\"button\" value=\"search\"/>\n</form>\n"
32
32
  end
33
33
  it "should return good html" do
34
- Picky::Helper.input(:no_results => 'SORRY!', :more => 'Click for more!').should == "<form class=\"empty\" onkeypress=\"return event.keyCode != 13;\">\n <!-- <div class=\"feedback\"> -->\n <div class=\"status\"></div>\n <input type=\"search\" placeholder=\"Search here...\" autocorrect=\"off\" class=\"query\"/>\n <a class=\"reset\" title=\"clear\"></a>\n <!-- </div> -->\n <input type=\"button\" value=\"search\"/>\n</form>\n"
34
+ Picky::Helper.input(:no_results => 'SORRY!', :more => 'Click for more!').should == "<form class=\"empty\" onkeypress=\"return event.keyCode != 13;\">\n <div class=\"status\"></div>\n <input type=\"search\" placeholder=\"Search here...\" autocorrect=\"off\" class=\"query\"/>\n <a class=\"reset\" title=\"clear\"></a>\n <input type=\"button\" value=\"search\"/>\n</form>\n"
35
35
  end
36
36
  end
37
37
 
38
38
  describe "interface" do
39
39
  it "should return good html" do
40
- Picky::Helper.interface.should == "<section class=\"picky\">\n <form class=\"empty\" onkeypress=\"return event.keyCode != 13;\">\n <!-- <div class=\"feedback\"> -->\n <div class=\"status\"></div>\n <input type=\"search\" placeholder=\"Search here...\" autocorrect=\"off\" class=\"query\"/>\n <a class=\"reset\" title=\"clear\"></a>\n <!-- </div> -->\n <input type=\"button\" value=\"search\"/>\n</form>\n\n <div class=\"results\"></div>\n<div class=\"no_results\">Sorry, no results found!</div>\n<div class=\"allocations\">\n <ol class=\"shown\"></ol>\n <ol class=\"more\">more</ol>\n <ol class=\"hidden\"></ol>\n</div>\n\n</section>\n"
40
+ Picky::Helper.interface.should == "<section class=\"picky\">\n <form class=\"empty\" onkeypress=\"return event.keyCode != 13;\">\n <div class=\"status\"></div>\n <input type=\"search\" placeholder=\"Search here...\" autocorrect=\"off\" class=\"query\"/>\n <a class=\"reset\" title=\"clear\"></a>\n <input type=\"button\" value=\"search\"/>\n</form>\n\n <div class=\"results\"></div>\n<div class=\"no_results\">Sorry, no results found!</div>\n<div class=\"allocations\">\n <ol class=\"shown\"></ol>\n <ol class=\"more\">more</ol>\n <ol class=\"hidden\"></ol>\n</div>\n\n</section>\n"
41
41
  end
42
42
  it "should return good html" do
43
- Picky::Helper.interface(:button => 'find', :no_results => 'SORRY!', :more => 'Click for more!').should == "<section class=\"picky\">\n <form class=\"empty\" onkeypress=\"return event.keyCode != 13;\">\n <!-- <div class=\"feedback\"> -->\n <div class=\"status\"></div>\n <input type=\"search\" placeholder=\"Search here...\" autocorrect=\"off\" class=\"query\"/>\n <a class=\"reset\" title=\"clear\"></a>\n <!-- </div> -->\n <input type=\"button\" value=\"find\"/>\n</form>\n\n <div class=\"results\"></div>\n<div class=\"no_results\">SORRY!</div>\n<div class=\"allocations\">\n <ol class=\"shown\"></ol>\n <ol class=\"more\">Click for more!</ol>\n <ol class=\"hidden\"></ol>\n</div>\n\n</section>\n"
43
+ Picky::Helper.interface(:button => 'find', :no_results => 'SORRY!', :more => 'Click for more!').should == "<section class=\"picky\">\n <form class=\"empty\" onkeypress=\"return event.keyCode != 13;\">\n <div class=\"status\"></div>\n <input type=\"search\" placeholder=\"Search here...\" autocorrect=\"off\" class=\"query\"/>\n <a class=\"reset\" title=\"clear\"></a>\n <input type=\"button\" value=\"find\"/>\n</form>\n\n <div class=\"results\"></div>\n<div class=\"no_results\">SORRY!</div>\n<div class=\"allocations\">\n <ol class=\"shown\"></ol>\n <ol class=\"more\">Click for more!</ol>\n <ol class=\"hidden\"></ol>\n</div>\n\n</section>\n"
44
44
  end
45
45
  end
46
46
 
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.6.3
4
+ version: 4.6.4
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: 2012-08-12 00:00:00.000000000 Z
12
+ date: 2012-09-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: yajl-ruby
@@ -55,6 +55,7 @@ files:
55
55
  - lib/picky-client/client/active_record.rb
56
56
  - lib/picky-client/client.rb
57
57
  - lib/picky-client/client_index.rb
58
+ - lib/picky-client/constants.rb
58
59
  - lib/picky-client/convenience.rb
59
60
  - lib/picky-client/extensions/object.rb
60
61
  - lib/picky-client/helper.rb
@@ -114,3 +115,4 @@ test_files:
114
115
  - spec/picky-client/helper_spec.rb
115
116
  - spec/picky-client/spec/test_client_integration_spec.rb
116
117
  - spec/picky-client/spec/test_client_spec.rb
118
+ has_rdoc: false