acts_as_cleo 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -18,3 +18,4 @@ end
18
18
 
19
19
  gem 'happymapper'
20
20
  gem 'rails', '>= 3.1.0'
21
+ gem 'resque'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.1.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 = "1.0.0"
8
+ s.version = "1.1.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"]
@@ -23,13 +23,16 @@ Gem::Specification.new do |s|
23
23
  "Rakefile",
24
24
  "VERSION",
25
25
  "acts_as_cleo.gemspec",
26
- "config/cleo.yml",
26
+ "config/cleo_example.yml",
27
27
  "lib/acts_as_cleo.rb",
28
28
  "lib/acts_as_cleo/result.rb",
29
29
  "lib/acts_as_cleo/version.rb",
30
30
  "lib/acts_methods.rb",
31
31
  "lib/class_methods.rb",
32
32
  "lib/cleo.rb",
33
+ "lib/cleo/jobs/create.rb",
34
+ "lib/cleo/jobs/delete.rb",
35
+ "lib/cleo/jobs/update.rb",
33
36
  "lib/cleo/reference.rb",
34
37
  "lib/cleo/result.rb",
35
38
  "lib/cleo/server.rb",
@@ -81,6 +84,7 @@ Gem::Specification.new do |s|
81
84
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
82
85
  s.add_runtime_dependency(%q<happymapper>, [">= 0"])
83
86
  s.add_runtime_dependency(%q<rails>, [">= 3.1.0"])
87
+ s.add_runtime_dependency(%q<resque>, [">= 0"])
84
88
  s.add_development_dependency(%q<shoulda>, [">= 0"])
85
89
  s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
86
90
  s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
@@ -92,6 +96,7 @@ Gem::Specification.new do |s|
92
96
  else
93
97
  s.add_dependency(%q<happymapper>, [">= 0"])
94
98
  s.add_dependency(%q<rails>, [">= 3.1.0"])
99
+ s.add_dependency(%q<resque>, [">= 0"])
95
100
  s.add_dependency(%q<shoulda>, [">= 0"])
96
101
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
97
102
  s.add_dependency(%q<bundler>, [">= 1.0.0"])
@@ -104,6 +109,7 @@ Gem::Specification.new do |s|
104
109
  else
105
110
  s.add_dependency(%q<happymapper>, [">= 0"])
106
111
  s.add_dependency(%q<rails>, [">= 3.1.0"])
112
+ s.add_dependency(%q<resque>, [">= 0"])
107
113
  s.add_dependency(%q<shoulda>, [">= 0"])
108
114
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
109
115
  s.add_dependency(%q<bundler>, [">= 1.0.0"])
@@ -1,7 +1,11 @@
1
1
  # Config file for the acts_as_cleo plugin.
2
- #
3
2
  development:
4
3
  url: "http://localhost:8080/cleo-primer/"
5
4
 
5
+ test:
6
+ url: "http://localhost:8080/cleo-primer/"
7
+
6
8
  production:
7
9
  url: "http://localhost:8080/cleo-primer/"
10
+ run_async: true
11
+ queue: "cleo"
data/lib/acts_as_cleo.rb CHANGED
@@ -12,11 +12,12 @@ end
12
12
 
13
13
  ActiveRecord::Base.extend ActsAsCleo
14
14
 
15
- root_path = Rails.root.nil? ? "#{File.dirname(File.expand_path(__FILE__))}/../" : Rails.root
15
+ root_path = Rails.root.nil? ? "#{File.dirname(File.expand_path(__FILE__))}/../test" : Rails.root
16
16
  cleo_file_path = File.join( root_path, 'config', 'cleo.yml' )
17
17
 
18
18
  if File.exists?( cleo_file_path )
19
- Cleo::Server.server_locations = YAML::load_file( cleo_file_path )[Rails.env].symbolize_keys
19
+ puts cleo_file_path
20
+ Cleo::Server.configure(YAML::load_file( cleo_file_path )[Rails.env].symbolize_keys)
20
21
  else
21
22
  raise LoadError.new("No cleo.yml found. Please viery that you have a copy of cleo.yml in your config directory.")
22
23
  end
@@ -0,0 +1,12 @@
1
+ module Cleo
2
+ module Resque
3
+ module Update
4
+ @queue = Cleo::Server.queue
5
+
6
+ def self.perform(klass, klass_id)
7
+ to_create = Kernel.const_get(klass).find(klass_id)
8
+ Cleo.create(to_create)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ module Cleo
2
+ module Resque
3
+ module Update
4
+ @queue = Cleo::Server.queue
5
+
6
+ def self.perform(klass, klass_id)
7
+ to_delete = Kernel.const_get(klass).find(klass_id)
8
+ Cleo.delete(to_delete.cleo_id)
9
+ cr = Cleo::Reference.find(:first, :conditions => ["record_type = ? and record_id = ?", klass, to_delete.id])
10
+ cr.delete
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ module Cleo
2
+ module Resque
3
+ module Update
4
+ @queue = Cleo::Server.queue
5
+
6
+ def self.perform(klass, klass_id)
7
+ to_update = Kernel.const_get(klass).find(klass_id)
8
+ Cleo.update(to_update)
9
+ end
10
+ end
11
+ end
12
+ end
data/lib/cleo/server.rb CHANGED
@@ -1,16 +1,36 @@
1
1
  module Cleo
2
2
  class Server
3
- @@server_location = {:url => 'http://cleo.testingserver.com/cleo-primer/' }
3
+ @@configuration= {:url => 'http://cleo.testingserver.com/cleo-primer/', :run_async => false, :queue => "cleo"}
4
4
 
5
- def self.server_locations=(new_locations)
6
- parts = new_locations[:url].split("/")
5
+ def self.configure(new_config)
6
+ parts = new_config[:url].split("/")
7
7
  parts -= %w{rest elements}
8
8
  parts += %w{rest elements}
9
- @@server_location[:url] = parts.join('/') + '/'
9
+ @@configuration[:url] = parts.join('/') + '/'
10
+
11
+ @@configuration[:run_async] = new_config.has_key?(:run_async) ? new_config[:run_async] : false
12
+ @@configuration[:queue] = new_config.has_key?(:queue) ? new_config[:queue] : "cleo"
13
+
14
+ env = ENV['QUEUE'] || ''
15
+ ENV['QUEUE'] = (env.split(',') << @@configuration[:queue]).uniq.join(',')
16
+
17
+ if @@configuration[:run_async]
18
+ require 'resque'
19
+ %w{create update delete}.each{|life| require File.dirname(__FILE__) + "/jobs/#{life}" }
20
+ end
10
21
  end
11
22
 
23
+ #meta these out
12
24
  def self.url
13
- @@server_location[:url]
25
+ @@configuration[:url]
26
+ end
27
+
28
+ def self.async?
29
+ @@configuration[:run_async]
30
+ end
31
+
32
+ def self.queue
33
+ @@configuration[:queue].to_sym
14
34
  end
15
35
  end
16
36
  end
@@ -3,17 +3,29 @@ module ActsAsCleo
3
3
  # callback hooks to keep cleo insync with data
4
4
  def create_cleo
5
5
  set_cleo_id
6
- Cleo.create(self)
6
+ if Cleo::Server.async?
7
+ Resque.enqueue(Cleo::Resque::Create, self.record_type.classify, self.id)
8
+ else
9
+ Cleo.create(self)
10
+ end
7
11
  end
8
12
 
9
13
  def update_cleo
14
+ if Cleo::Server.async?
15
+ Resque.enqueue(Cleo::Resque::Update, self.record_type.classify, self.id)
16
+ else
10
17
  Cleo.update(self)
18
+ end
11
19
  end
12
20
 
13
21
  def remove_from_cleo
14
- Cleo.delete(self.cleo_id)
15
- cr = cleo_reference
16
- cr.delete
22
+ if Cleo::Server.async?
23
+ Resque.enqueue(Cleo::Resque::Delete, self.record_type.classify, self.id)
24
+ else
25
+ Cleo.delete(self.cleo_id)
26
+ cr = cleo_reference
27
+ cr.delete
28
+ end
17
29
  end
18
30
 
19
31
  def set_cleo_id
@@ -30,8 +42,6 @@ module ActsAsCleo
30
42
  return cr.id
31
43
  end
32
44
 
33
-
34
-
35
45
  def to_cleo_result
36
46
  #take self and change it into a Cleo::Result and return
37
47
  cr = Cleo::Result.new
data/test/config/cleo.yml CHANGED
@@ -1,2 +1,16 @@
1
+ # Config file for the acts_as_cleo plugin.
2
+ development:
3
+ url: "http://localhost:8080/cleo-primer/"
4
+
1
5
  test:
2
- url: http://localhost:8080/cleo-primer
6
+ url: "http://localhost:8080/cleo-primer/"
7
+
8
+ production:
9
+ url: "http://localhost:8080/cleo-primer/"
10
+ run_async: true
11
+ queue: "cleo"
12
+
13
+ async_test:
14
+ url: "http://localhost:8080/cleo-primer/"
15
+ run_async: true
16
+ queue: "cleo"
data/test/db/test.db CHANGED
Binary file
@@ -56,5 +56,15 @@ class TestCleo < Test::Unit::TestCase
56
56
 
57
57
  assert Cleo.delete(wa.id)
58
58
  end
59
+
60
+ should "change the configuration of the server" do
61
+ root_path = Rails.root.nil? ? "#{File.dirname(File.expand_path(__FILE__))}/../" : Rails.root
62
+ cleo_file_path = File.join( root_path, 'config', 'cleo.yml' )
63
+
64
+ Cleo::Server.configure YAML::load_file( cleo_file_path )['async_test'].symbolize_keys
65
+ assert Cleo::Server.async?
66
+ assert "cleo", Cleo::Server.queue.to_s
67
+
68
+ end
59
69
  end
60
70
 
@@ -5,8 +5,8 @@ class TestInstanceMethods < Test::Unit::TestCase
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|
9
- should "respond to cleo_id and cleo_id=" do
8
+ %w{cleo_id update_cleo remove_from_cleo create_cleo set_cleo_id to_cleo_result as_cleo}.each do |resp|
9
+ should "respond to #{resp}" do
10
10
  assert @b.respond_to?(resp), "ActiveRecord Model with acts_as_cleo should respond to #{resp}"
11
11
  end
12
12
  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: 1.0.0
4
+ version: 1.1.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: &70333743273900 !ruby/object:Gem::Requirement
16
+ requirement: &70302933187960 !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: *70333743273900
24
+ version_requirements: *70302933187960
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rails
27
- requirement: &70333743273420 !ruby/object:Gem::Requirement
27
+ requirement: &70302933187480 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,21 @@ dependencies:
32
32
  version: 3.1.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70333743273420
35
+ version_requirements: *70302933187480
36
+ - !ruby/object:Gem::Dependency
37
+ name: resque
38
+ requirement: &70302933187000 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70302933187000
36
47
  - !ruby/object:Gem::Dependency
37
48
  name: shoulda
38
- requirement: &70333743272940 !ruby/object:Gem::Requirement
49
+ requirement: &70302933186520 !ruby/object:Gem::Requirement
39
50
  none: false
40
51
  requirements:
41
52
  - - ! '>='
@@ -43,10 +54,10 @@ dependencies:
43
54
  version: '0'
44
55
  type: :development
45
56
  prerelease: false
46
- version_requirements: *70333743272940
57
+ version_requirements: *70302933186520
47
58
  - !ruby/object:Gem::Dependency
48
59
  name: rdoc
49
- requirement: &70333743272460 !ruby/object:Gem::Requirement
60
+ requirement: &70302933186040 !ruby/object:Gem::Requirement
50
61
  none: false
51
62
  requirements:
52
63
  - - ~>
@@ -54,10 +65,10 @@ dependencies:
54
65
  version: '3.12'
55
66
  type: :development
56
67
  prerelease: false
57
- version_requirements: *70333743272460
68
+ version_requirements: *70302933186040
58
69
  - !ruby/object:Gem::Dependency
59
70
  name: bundler
60
- requirement: &70333743271980 !ruby/object:Gem::Requirement
71
+ requirement: &70302933185560 !ruby/object:Gem::Requirement
61
72
  none: false
62
73
  requirements:
63
74
  - - ! '>='
@@ -65,10 +76,10 @@ dependencies:
65
76
  version: 1.0.0
66
77
  type: :development
67
78
  prerelease: false
68
- version_requirements: *70333743271980
79
+ version_requirements: *70302933185560
69
80
  - !ruby/object:Gem::Dependency
70
81
  name: jeweler
71
- requirement: &70333743271500 !ruby/object:Gem::Requirement
82
+ requirement: &70302933185080 !ruby/object:Gem::Requirement
72
83
  none: false
73
84
  requirements:
74
85
  - - ~>
@@ -76,10 +87,10 @@ dependencies:
76
87
  version: 1.8.3
77
88
  type: :development
78
89
  prerelease: false
79
- version_requirements: *70333743271500
90
+ version_requirements: *70302933185080
80
91
  - !ruby/object:Gem::Dependency
81
92
  name: simplecov
82
- requirement: &70333743271020 !ruby/object:Gem::Requirement
93
+ requirement: &70302933184600 !ruby/object:Gem::Requirement
83
94
  none: false
84
95
  requirements:
85
96
  - - ! '>='
@@ -87,10 +98,10 @@ dependencies:
87
98
  version: '0'
88
99
  type: :development
89
100
  prerelease: false
90
- version_requirements: *70333743271020
101
+ version_requirements: *70302933184600
91
102
  - !ruby/object:Gem::Dependency
92
103
  name: ruby-debug19
93
- requirement: &70333743270540 !ruby/object:Gem::Requirement
104
+ requirement: &70302933184120 !ruby/object:Gem::Requirement
94
105
  none: false
95
106
  requirements:
96
107
  - - ! '>='
@@ -98,10 +109,10 @@ dependencies:
98
109
  version: '0'
99
110
  type: :development
100
111
  prerelease: false
101
- version_requirements: *70333743270540
112
+ version_requirements: *70302933184120
102
113
  - !ruby/object:Gem::Dependency
103
114
  name: fixtures
104
- requirement: &70333743270060 !ruby/object:Gem::Requirement
115
+ requirement: &70302933183640 !ruby/object:Gem::Requirement
105
116
  none: false
106
117
  requirements:
107
118
  - - ! '>='
@@ -109,10 +120,10 @@ dependencies:
109
120
  version: '0'
110
121
  type: :development
111
122
  prerelease: false
112
- version_requirements: *70333743270060
123
+ version_requirements: *70302933183640
113
124
  - !ruby/object:Gem::Dependency
114
125
  name: sqlite3
115
- requirement: &70333743269580 !ruby/object:Gem::Requirement
126
+ requirement: &70302933183160 !ruby/object:Gem::Requirement
116
127
  none: false
117
128
  requirements:
118
129
  - - ! '>='
@@ -120,7 +131,7 @@ dependencies:
120
131
  version: '0'
121
132
  type: :development
122
133
  prerelease: false
123
- version_requirements: *70333743269580
134
+ version_requirements: *70302933183160
124
135
  description: LinkedIn Open Source type ahead tool's REST API as a ruby gem
125
136
  email: Blue.Dog.Archolite@gmail.com
126
137
  executables: []
@@ -135,13 +146,16 @@ files:
135
146
  - Rakefile
136
147
  - VERSION
137
148
  - acts_as_cleo.gemspec
138
- - config/cleo.yml
149
+ - config/cleo_example.yml
139
150
  - lib/acts_as_cleo.rb
140
151
  - lib/acts_as_cleo/result.rb
141
152
  - lib/acts_as_cleo/version.rb
142
153
  - lib/acts_methods.rb
143
154
  - lib/class_methods.rb
144
155
  - lib/cleo.rb
156
+ - lib/cleo/jobs/create.rb
157
+ - lib/cleo/jobs/delete.rb
158
+ - lib/cleo/jobs/update.rb
145
159
  - lib/cleo/reference.rb
146
160
  - lib/cleo/result.rb
147
161
  - lib/cleo/server.rb