acts_as_cleo 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +56 -1
- data/VERSION +1 -1
- data/acts_as_cleo.gemspec +2 -3
- data/config/cleo.yml +1 -4
- data/lib/acts_as_cleo.rb +0 -1
- data/lib/acts_methods.rb +2 -3
- data/lib/class_methods.rb +3 -0
- data/lib/cleo.rb +3 -4
- data/lib/generators/acts_as_cleo/templates/install.rb +0 -1
- data/lib/instance_methods.rb +8 -7
- data/test/db/migrate/007_cleo_table.rb +0 -1
- data/test/db/test.db +0 -0
- data/test/unit/test_cleo.rb +2 -2
- data/test/unit/test_common_methods.rb +11 -0
- data/test/unit/test_instance_methods.rb +3 -0
- metadata +22 -26
- data/lib/common_methods.rb +0 -7
data/README.rdoc
CHANGED
@@ -1,9 +1,64 @@
|
|
1
1
|
= acts_as_cleo
|
2
2
|
|
3
|
+
=== To enable
|
4
|
+
|
5
|
+
Create a cleo.yml in your config directory.
|
6
|
+
|
7
|
+
development:
|
8
|
+
|
9
|
+
url: "http://localhost:8080/cleo-primer/"
|
10
|
+
|
11
|
+
production:
|
12
|
+
|
13
|
+
url: "http://localhost:8080/cleo-primer/"
|
14
|
+
|
15
|
+
|
16
|
+
=== Usage
|
17
|
+
|
18
|
+
|
19
|
+
Cleo.find(int) # Find Cleo entry by Cleo native id
|
20
|
+
|
21
|
+
Cleo.update(Cleo::Result) # Pass any acts_as_cleo object to this method to have it update the Cleo entry
|
22
|
+
|
23
|
+
Cleo.delete(int) # Delete by Cleo id, also accepts any acts_as_cleo object or Cleo::Result
|
24
|
+
|
25
|
+
Cleo.create(obj) # Creates new entry on Cleo index. Accepts any acts_as_cleo object or Cleo::Result
|
26
|
+
|
27
|
+
Cleo.query(string) # Takes string search param and returns array of Cleo::Reference objects
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
To enable on an ActiveRecord::Base model:
|
32
|
+
|
33
|
+
acts_as_cleo
|
34
|
+
|
35
|
+
acts_as_cleo :terms => %w{terms to be stored}
|
36
|
+
|
37
|
+
acts_as_cleo :except => %w{columns to be ignored}
|
38
|
+
|
39
|
+
acts_as_cleo :score=> "method or column to be used"
|
40
|
+
|
41
|
+
acts_as_cleo :terms => %w{name value other}, :score => "my_score_method"
|
42
|
+
|
43
|
+
Default functionality takes all column_names and uses them as terms for Cleo search.
|
44
|
+
|
45
|
+
To specify terms to be stored in Cleo, pass :terms => [] with the column and/or method names to be stored
|
46
|
+
|
47
|
+
acts_as_cleo ignores updated_at, created_at, id by default.
|
48
|
+
|
49
|
+
You can specify more columns to ignore by passing :except => [] with column names.
|
50
|
+
|
51
|
+
By default, acts_as_cleo uses the column "name" from your model as the Cleo search name. To specify the name in Cleo, pass :name => "my_attribute_name"
|
52
|
+
|
53
|
+
To specify a Cleo score, pass :score => "name of column or function"
|
54
|
+
|
55
|
+
ActiveRecord::Base objects with acts_as_cleo get three callback functions:
|
56
|
+
|
57
|
+
set_cleo_id, sync_with_cleo and remove_from_cleo
|
3
58
|
|
4
59
|
= WARNING
|
5
60
|
|
6
|
-
This gem is still in beta.
|
61
|
+
This gem is still in beta.
|
7
62
|
|
8
63
|
* Cleo.find
|
9
64
|
* Cleo.update
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
data/acts_as_cleo.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "acts_as_cleo"
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Robert R. Meyer"]
|
12
|
-
s.date = "2012-03-
|
12
|
+
s.date = "2012-03-22"
|
13
13
|
s.description = "LinkedIn Open Source type ahead tool's REST API as a ruby gem"
|
14
14
|
s.email = "Blue.Dog.Archolite@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -33,7 +33,6 @@ Gem::Specification.new do |s|
|
|
33
33
|
"lib/cleo/reference.rb",
|
34
34
|
"lib/cleo/result.rb",
|
35
35
|
"lib/cleo/server.rb",
|
36
|
-
"lib/common_methods.rb",
|
37
36
|
"lib/generators/acts_as_cleo/install_generator.rb",
|
38
37
|
"lib/generators/acts_as_cleo/templates/install.rb",
|
39
38
|
"lib/instance_methods.rb",
|
data/config/cleo.yml
CHANGED
data/lib/acts_as_cleo.rb
CHANGED
@@ -5,7 +5,6 @@ require File.dirname(__FILE__) + '/cleo'
|
|
5
5
|
require File.dirname(__FILE__) + '/acts_methods'
|
6
6
|
require File.dirname(__FILE__) + '/class_methods'
|
7
7
|
require File.dirname(__FILE__) + '/instance_methods'
|
8
|
-
require File.dirname(__FILE__) + '/common_methods'
|
9
8
|
|
10
9
|
module ActsAsCleo
|
11
10
|
include ActsMethods
|
data/lib/acts_methods.rb
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
module ActsAsCleo
|
2
2
|
module ActsMethods
|
3
3
|
def acts_as_cleo(opts = {})
|
4
|
+
#Common class methods added
|
4
5
|
extend ClassMethods
|
5
|
-
extend CommonMethods
|
6
6
|
|
7
7
|
#Instance Methods Correctly Included
|
8
8
|
include InstanceMethods
|
9
9
|
|
10
|
-
|
11
|
-
after_commit :sync_with_cleo
|
10
|
+
after_commit :set_cleo_id, :sync_with_cleo
|
12
11
|
after_destroy :remove_from_cleo
|
13
12
|
|
14
13
|
cattr_accessor :cleo_config
|
data/lib/class_methods.rb
CHANGED
data/lib/cleo.rb
CHANGED
@@ -43,9 +43,7 @@ module Cleo
|
|
43
43
|
return good_response_code?(response)
|
44
44
|
end
|
45
45
|
|
46
|
-
def self.delete(
|
47
|
-
obj = obj.to_cleo_result unless obj.is_a?(Cleo::Result)
|
48
|
-
|
46
|
+
def self.delete(cleo_id)
|
49
47
|
=begin
|
50
48
|
|
51
49
|
|
@@ -189,7 +187,7 @@ module Cleo
|
|
189
187
|
|
190
188
|
=end
|
191
189
|
|
192
|
-
result = `curl -v -X DELETE #{Cleo::Server.url}#{
|
190
|
+
result = `curl -v -X DELETE #{Cleo::Server.url}#{cleo_id}`
|
193
191
|
|
194
192
|
#TODO I HATE THIS. Make this use Rails and not a fracking curl call
|
195
193
|
# uri = URI.parse Cleo::Server.url + "/#{obj.id}"
|
@@ -236,3 +234,4 @@ end
|
|
236
234
|
#require Result Class
|
237
235
|
require 'cleo/server'
|
238
236
|
require 'cleo/result'
|
237
|
+
require 'cleo/reference'
|
data/lib/instance_methods.rb
CHANGED
@@ -10,23 +10,24 @@ module ActsAsCleo
|
|
10
10
|
#after_update send the data to cleo
|
11
11
|
end
|
12
12
|
|
13
|
-
def set_cleo_id
|
14
|
-
#this needs to be rerolled to pull an Cleo::Reference record and persist it.
|
15
|
-
end
|
16
|
-
|
17
13
|
def remove_from_cleo
|
18
14
|
Cleo.delete(self) if self.persisted?
|
19
15
|
end
|
20
16
|
#end callback hooks
|
21
17
|
|
22
18
|
def cleo_id
|
19
|
+
return nil if self.id.nil?
|
23
20
|
record_type = self.cleo_config[:type]
|
24
|
-
|
25
|
-
|
21
|
+
cr = Cleo::Reference.find(:first, :conditions => ["record_type = ? and record_id = ?", record_type, self.id])
|
22
|
+
|
23
|
+
return nil if cr.nil?
|
24
|
+
return cr.id
|
26
25
|
end
|
27
26
|
|
28
|
-
def
|
27
|
+
def set_cleo_id
|
29
28
|
#this needs to be rerolled to pull an Cleo::Reference record and persist it.
|
29
|
+
cr = Cleo::Reference.find(:one, :conditions => ["record_type = ? and record_id = ?", record_type, self.id])
|
30
|
+
cr = Cleo::Reference.create(:record_type => record_type, :record_id => self.id) if cr.nil?
|
30
31
|
end#
|
31
32
|
|
32
33
|
def to_cleo_result
|
data/test/db/test.db
CHANGED
Binary file
|
data/test/unit/test_cleo.rb
CHANGED
@@ -20,7 +20,7 @@ class TestCleo < Test::Unit::TestCase
|
|
20
20
|
assert_not_nil wa
|
21
21
|
assert_equal @wedge.id, wa.id
|
22
22
|
|
23
|
-
assert Cleo.delete(wa)
|
23
|
+
assert Cleo.delete(wa.id)
|
24
24
|
end
|
25
25
|
|
26
26
|
should "get google results from qery" do
|
@@ -54,7 +54,7 @@ class TestCleo < Test::Unit::TestCase
|
|
54
54
|
wa_update = Cleo.find(@wedge.id)
|
55
55
|
assert_equal "Luke Skywalker", wa_update.name
|
56
56
|
|
57
|
-
assert Cleo.delete(wa)
|
57
|
+
assert Cleo.delete(wa.id)
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
@@ -4,4 +4,15 @@ class TestCommonMethods < Test::Unit::TestCase
|
|
4
4
|
should "respond to query call" do
|
5
5
|
assert Book.respond_to?("query")
|
6
6
|
end
|
7
|
+
|
8
|
+
should "find record with book name" do
|
9
|
+
book = Book.create(:name => "Otherland", :author => "Tad Williams")
|
10
|
+
assert Cleo.create(book)
|
11
|
+
book_cleo_id = book.cleo_id
|
12
|
+
assert Cleo.find(book_cleo_id)
|
13
|
+
|
14
|
+
assert Cleo.delete(book_cleo_id)
|
15
|
+
assert_nil Cleo.find(book_cleo_id)
|
16
|
+
end
|
7
17
|
end
|
18
|
+
|
@@ -4,9 +4,12 @@ class TestInstanceMethods < Test::Unit::TestCase
|
|
4
4
|
def setup
|
5
5
|
@b = Book.new
|
6
6
|
end
|
7
|
+
|
7
8
|
%w{cleo_id cleo_id= sync_with_cleo set_cleo_id remove_from_cleo to_cleo_result as_cleo}.each do |resp|
|
8
9
|
should "respond to cleo_id and cleo_id=" do
|
9
10
|
assert @b.respond_to?(resp), "ActiveRecord Model with acts_as_cleo should respond to #{resp}"
|
10
11
|
end
|
11
12
|
end
|
13
|
+
|
14
|
+
#TODO write tests for the functionality of each of the instance methods
|
12
15
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_cleo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-03-
|
12
|
+
date: 2012-03-22 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: happymapper
|
16
|
-
requirement: &
|
16
|
+
requirement: &70303817396620 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70303817396620
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rails
|
27
|
-
requirement: &
|
27
|
+
requirement: &70303817396140 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 3.1.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70303817396140
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: shoulda
|
38
|
-
requirement: &
|
38
|
+
requirement: &70303817395660 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70303817395660
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rdoc
|
49
|
-
requirement: &
|
49
|
+
requirement: &70303817395180 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '3.12'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70303817395180
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: bundler
|
60
|
-
requirement: &
|
60
|
+
requirement: &70303817394700 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 1.0.0
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70303817394700
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: jeweler
|
71
|
-
requirement: &
|
71
|
+
requirement: &70303817394220 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: 1.8.3
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70303817394220
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: simplecov
|
82
|
-
requirement: &
|
82
|
+
requirement: &70303817393740 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70303817393740
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: ruby-debug19
|
93
|
-
requirement: &
|
93
|
+
requirement: &70303817393260 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ! '>='
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: '0'
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *70303817393260
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: fixtures
|
104
|
-
requirement: &
|
104
|
+
requirement: &70303817392780 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ! '>='
|
@@ -109,10 +109,10 @@ dependencies:
|
|
109
109
|
version: '0'
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *70303817392780
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
114
|
name: sqlite3
|
115
|
-
requirement: &
|
115
|
+
requirement: &70303817392300 !ruby/object:Gem::Requirement
|
116
116
|
none: false
|
117
117
|
requirements:
|
118
118
|
- - ! '>='
|
@@ -120,7 +120,7 @@ dependencies:
|
|
120
120
|
version: '0'
|
121
121
|
type: :development
|
122
122
|
prerelease: false
|
123
|
-
version_requirements: *
|
123
|
+
version_requirements: *70303817392300
|
124
124
|
description: LinkedIn Open Source type ahead tool's REST API as a ruby gem
|
125
125
|
email: Blue.Dog.Archolite@gmail.com
|
126
126
|
executables: []
|
@@ -145,7 +145,6 @@ files:
|
|
145
145
|
- lib/cleo/reference.rb
|
146
146
|
- lib/cleo/result.rb
|
147
147
|
- lib/cleo/server.rb
|
148
|
-
- lib/common_methods.rb
|
149
148
|
- lib/generators/acts_as_cleo/install_generator.rb
|
150
149
|
- lib/generators/acts_as_cleo/templates/install.rb
|
151
150
|
- lib/instance_methods.rb
|
@@ -194,9 +193,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
194
193
|
- - ! '>='
|
195
194
|
- !ruby/object:Gem::Version
|
196
195
|
version: '0'
|
197
|
-
segments:
|
198
|
-
- 0
|
199
|
-
hash: 1569020174324415562
|
200
196
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
201
197
|
none: false
|
202
198
|
requirements:
|