acts_as_cleo 0.0.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +0 -1
- data/VERSION +1 -1
- data/acts_as_cleo.gemspec +3 -3
- data/lib/acts_methods.rb +3 -2
- data/lib/cleo.rb +12 -1
- data/lib/instance_methods.rb +25 -14
- data/test/db/test.db +0 -0
- data/test/models/category.rb +1 -0
- data/test/models/electronic.rb +1 -1
- data/test/unit/test_active_record_callback_hooks.rb +35 -0
- data/test/unit/{test_common_methods.rb → test_class_methods.rb} +7 -3
- metadata +23 -23
- data/test/test_acts_as_cleo.rb +0 -7
data/Gemfile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
1.0.0
|
data/acts_as_cleo.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "acts_as_cleo"
|
8
|
-
s.version = "0.0
|
8
|
+
s.version = "1.0.0"
|
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"]
|
@@ -60,11 +60,11 @@ Gem::Specification.new do |s|
|
|
60
60
|
"test/models/category.rb",
|
61
61
|
"test/models/electronic.rb",
|
62
62
|
"test/models/movie.rb",
|
63
|
-
"test/test_acts_as_cleo.rb",
|
64
63
|
"test/test_install_generator.rb",
|
64
|
+
"test/unit/test_active_record_callback_hooks.rb",
|
65
65
|
"test/unit/test_acts_methods.rb",
|
66
|
+
"test/unit/test_class_methods.rb",
|
66
67
|
"test/unit/test_cleo.rb",
|
67
|
-
"test/unit/test_common_methods.rb",
|
68
68
|
"test/unit/test_instance_methods.rb",
|
69
69
|
"test/unit/test_model_to_cleo.rb",
|
70
70
|
"test/unit/test_result_parser.rb"
|
data/lib/acts_methods.rb
CHANGED
@@ -7,8 +7,9 @@ module ActsAsCleo
|
|
7
7
|
#Instance Methods Correctly Included
|
8
8
|
include InstanceMethods
|
9
9
|
|
10
|
-
|
11
|
-
|
10
|
+
after_create :create_cleo
|
11
|
+
after_update :update_cleo
|
12
|
+
before_destroy :remove_from_cleo
|
12
13
|
|
13
14
|
cattr_accessor :cleo_config
|
14
15
|
|
data/lib/cleo.rb
CHANGED
@@ -19,6 +19,8 @@ module Cleo
|
|
19
19
|
uri = URI.parse(Cleo::Server.url + "#{id}")
|
20
20
|
response = self.get(uri)
|
21
21
|
|
22
|
+
return nil if response.body.blank?
|
23
|
+
|
22
24
|
Cleo::Result.parse(response.body, :single => true)
|
23
25
|
end
|
24
26
|
|
@@ -43,7 +45,7 @@ module Cleo
|
|
43
45
|
return good_response_code?(response)
|
44
46
|
end
|
45
47
|
|
46
|
-
def self.delete(
|
48
|
+
def self.delete(obj_or_id)
|
47
49
|
=begin
|
48
50
|
|
49
51
|
|
@@ -187,6 +189,15 @@ module Cleo
|
|
187
189
|
|
188
190
|
=end
|
189
191
|
|
192
|
+
cleo_id = nil
|
193
|
+
if obj_or_id.is_a?(Cleo::Result)
|
194
|
+
cleo_id = obj_or_id.id
|
195
|
+
elsif obj_or_id.is_a?(Fixnum)
|
196
|
+
cleo_id = obj_or_id
|
197
|
+
elsif obj_or_id.responds_to?("cleo_id")
|
198
|
+
cleo_id = obj_or_id.cleo_id
|
199
|
+
end
|
200
|
+
|
190
201
|
result = `curl -v -X DELETE #{Cleo::Server.url}#{cleo_id}`
|
191
202
|
|
192
203
|
#TODO I HATE THIS. Make this use Rails and not a fracking curl call
|
data/lib/instance_methods.rb
CHANGED
@@ -1,34 +1,36 @@
|
|
1
1
|
module ActsAsCleo
|
2
2
|
module InstanceMethods
|
3
3
|
# callback hooks to keep cleo insync with data
|
4
|
-
def
|
5
|
-
|
4
|
+
def create_cleo
|
5
|
+
set_cleo_id
|
6
|
+
Cleo.create(self)
|
7
|
+
end
|
8
|
+
|
9
|
+
def update_cleo
|
6
10
|
Cleo.update(self)
|
7
|
-
else
|
8
|
-
Cleo.create(self)
|
9
|
-
end
|
10
|
-
#after_update send the data to cleo
|
11
11
|
end
|
12
12
|
|
13
13
|
def remove_from_cleo
|
14
|
-
Cleo.delete(self)
|
14
|
+
Cleo.delete(self.cleo_id)
|
15
|
+
cr = cleo_reference
|
16
|
+
cr.delete
|
15
17
|
end
|
18
|
+
|
19
|
+
def set_cleo_id
|
20
|
+
cr = Cleo::Reference.find(:first, :conditions => ["record_type = ? and record_id = ?", record_type, self.id])
|
21
|
+
cr = Cleo::Reference.create(:record_type => record_type, :record_id => self.id) if cr.nil?
|
22
|
+
end#
|
16
23
|
#end callback hooks
|
17
24
|
|
18
25
|
def cleo_id
|
19
26
|
return nil if self.id.nil?
|
20
|
-
|
21
|
-
cr = Cleo::Reference.find(:first, :conditions => ["record_type = ? and record_id = ?", record_type, self.id])
|
27
|
+
cr = cleo_reference
|
22
28
|
|
23
29
|
return nil if cr.nil?
|
24
30
|
return cr.id
|
25
31
|
end
|
26
32
|
|
27
|
-
|
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?
|
31
|
-
end#
|
33
|
+
|
32
34
|
|
33
35
|
def to_cleo_result
|
34
36
|
#take self and change it into a Cleo::Result and return
|
@@ -59,5 +61,14 @@ module ActsAsCleo
|
|
59
61
|
end
|
60
62
|
|
61
63
|
alias :as_cleo :to_cleo_result
|
64
|
+
|
65
|
+
private
|
66
|
+
def record_type
|
67
|
+
self.cleo_config[:type]
|
68
|
+
end
|
69
|
+
|
70
|
+
def cleo_reference
|
71
|
+
Cleo::Reference.find(:first, :conditions => ["record_type = ? and record_id = ?", record_type, self.id])
|
72
|
+
end
|
62
73
|
end
|
63
74
|
end
|
data/test/db/test.db
CHANGED
Binary file
|
data/test/models/category.rb
CHANGED
data/test/models/electronic.rb
CHANGED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestActiveRecordCallbacHooks < Test::Unit::TestCase
|
4
|
+
should "have all callbacks functioning properly" do
|
5
|
+
book = Book.new(:name => "set cleo id", :author => "Rob Meyer")
|
6
|
+
assert_nil book.cleo_id
|
7
|
+
assert_nil Cleo::Reference.find(:first, :conditions => ["record_type = ? and record_id = ?", "Book", book.id])
|
8
|
+
|
9
|
+
assert book.save!
|
10
|
+
book_id = book.id
|
11
|
+
|
12
|
+
assert book.cleo_id
|
13
|
+
ref = Cleo::Reference.find(:first, :conditions => ["record_type = ? and record_id = ?", "Book", book_id])
|
14
|
+
assert_not_nil ref
|
15
|
+
|
16
|
+
assert book.destroy
|
17
|
+
assert_nil Cleo::Reference.find(:first, :conditions => ["record_type = ? and record_id = ?", "Book", book_id])
|
18
|
+
assert_nil Cleo.find(ref.id)
|
19
|
+
end
|
20
|
+
|
21
|
+
should "update cleo on record update" do
|
22
|
+
book = Book.new(:name => "update cleo", :author => "Rob Meyer")
|
23
|
+
assert book.save!
|
24
|
+
cleo_record = Cleo.find(book.cleo_id)
|
25
|
+
assert_not_nil cleo_record
|
26
|
+
book.name = "Updated my Cleo"
|
27
|
+
assert book.save!
|
28
|
+
|
29
|
+
updated_cleo_record = Cleo.find(book.cleo_id)
|
30
|
+
assert_equal book.name, updated_cleo_record.name
|
31
|
+
assert_not_equal cleo_record.name, updated_cleo_record.name
|
32
|
+
|
33
|
+
assert book.destroy
|
34
|
+
end
|
35
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class TestClassMethods < Test::Unit::TestCase
|
4
4
|
should "respond to query call" do
|
5
5
|
assert Book.respond_to?("query")
|
6
6
|
end
|
@@ -12,7 +12,11 @@ class TestCommonMethods < Test::Unit::TestCase
|
|
12
12
|
assert Cleo.find(book_cleo_id)
|
13
13
|
|
14
14
|
assert Cleo.delete(book_cleo_id)
|
15
|
-
assert_nil Cleo.find(book_cleo_id)
|
16
15
|
end
|
17
|
-
end
|
18
16
|
|
17
|
+
should "be able to query from Klass" do
|
18
|
+
books = Book.query("goog")
|
19
|
+
assert_not_nil books
|
20
|
+
assert_kind_of Array, books
|
21
|
+
end
|
22
|
+
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: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ 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: &70333743273900 !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: *70333743273900
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rails
|
27
|
-
requirement: &
|
27
|
+
requirement: &70333743273420 !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: *70333743273420
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: shoulda
|
38
|
-
requirement: &
|
38
|
+
requirement: &70333743272940 !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: *70333743272940
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rdoc
|
49
|
-
requirement: &
|
49
|
+
requirement: &70333743272460 !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: *70333743272460
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: bundler
|
60
|
-
requirement: &
|
60
|
+
requirement: &70333743271980 !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: *70333743271980
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: jeweler
|
71
|
-
requirement: &
|
71
|
+
requirement: &70333743271500 !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: *70333743271500
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: simplecov
|
82
|
-
requirement: &
|
82
|
+
requirement: &70333743271020 !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: *70333743271020
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: ruby-debug19
|
93
|
-
requirement: &
|
93
|
+
requirement: &70333743270540 !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: *70333743270540
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: fixtures
|
104
|
-
requirement: &
|
104
|
+
requirement: &70333743270060 !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: *70333743270060
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
114
|
name: sqlite3
|
115
|
-
requirement: &
|
115
|
+
requirement: &70333743269580 !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: *70333743269580
|
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: []
|
@@ -172,11 +172,11 @@ files:
|
|
172
172
|
- test/models/category.rb
|
173
173
|
- test/models/electronic.rb
|
174
174
|
- test/models/movie.rb
|
175
|
-
- test/test_acts_as_cleo.rb
|
176
175
|
- test/test_install_generator.rb
|
176
|
+
- test/unit/test_active_record_callback_hooks.rb
|
177
177
|
- test/unit/test_acts_methods.rb
|
178
|
+
- test/unit/test_class_methods.rb
|
178
179
|
- test/unit/test_cleo.rb
|
179
|
-
- test/unit/test_common_methods.rb
|
180
180
|
- test/unit/test_instance_methods.rb
|
181
181
|
- test/unit/test_model_to_cleo.rb
|
182
182
|
- test/unit/test_result_parser.rb
|
data/test/test_acts_as_cleo.rb
DELETED