acts_as_cleo 1.2.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -65,7 +65,18 @@ This gem is still in beta.
65
65
  * Cleo.delete
66
66
  * Cleo.create
67
67
 
68
- As of this moment you need to pass a constructed Cleo::Result object to the above methods for them to function correctly.
68
+ = Installing
69
+
70
+ Add acts_as_cleo to your Gemfile
71
+ gem 'acts_as_cleo'
72
+
73
+ After running bundle install execute the generate script to install acts_as_cleo
74
+ rails g acts_as_cleo:install
75
+
76
+ Verify server settings in config/cleo.yml
77
+
78
+ Run migrations
79
+ rake db:migrate
69
80
 
70
81
  Feel free to use this gem and provide feedback / patch requests.
71
82
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.0
1
+ 2.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 = "1.2.0"
8
+ s.version = "2.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"]
@@ -23,22 +23,22 @@ Gem::Specification.new do |s|
23
23
  "Rakefile",
24
24
  "VERSION",
25
25
  "acts_as_cleo.gemspec",
26
- "config/cleo_example.yml",
27
26
  "lib/acts_as_cleo.rb",
27
+ "lib/acts_as_cleo/acts_methods.rb",
28
+ "lib/acts_as_cleo/class_methods.rb",
29
+ "lib/acts_as_cleo/instance_methods.rb",
28
30
  "lib/acts_as_cleo/result.rb",
29
31
  "lib/acts_as_cleo/version.rb",
30
- "lib/acts_methods.rb",
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",
36
33
  "lib/cleo/reference.rb",
37
34
  "lib/cleo/result.rb",
38
35
  "lib/cleo/server.rb",
39
- "lib/generators/acts_as_cleo/install_generator.rb",
40
- "lib/generators/acts_as_cleo/templates/install.rb",
41
- "lib/instance_methods.rb",
36
+ "lib/generators/acts_as_cleo/install/install_generator.rb",
37
+ "lib/generators/acts_as_cleo/install/templates/cleo.yml",
38
+ "lib/generators/acts_as_cleo/install/templates/install.rb",
39
+ "lib/generators/acts_as_cleo/install/templates/jobs/create.rb",
40
+ "lib/generators/acts_as_cleo/install/templates/jobs/delete.rb",
41
+ "lib/generators/acts_as_cleo/install/templates/jobs/update.rb",
42
42
  "test/config/cleo.yml",
43
43
  "test/data/xml/cleo/element.xml",
44
44
  "test/data/xml/cleo/elements.xml",
@@ -4,7 +4,7 @@ module ActsAsCleo
4
4
  def create_cleo
5
5
  set_cleo_id
6
6
  if Cleo::Server.async?
7
- Resque.enqueue(Cleo::Resque::Create, self.record_type.classify, self.id)
7
+ Resque.enqueue(Cleo::ResqueCreate, record_type.classify, self.id)
8
8
  else
9
9
  Cleo.create(self)
10
10
  end
@@ -12,7 +12,7 @@ module ActsAsCleo
12
12
 
13
13
  def update_cleo
14
14
  if Cleo::Server.async?
15
- Resque.enqueue(Cleo::Resque::Update, self.record_type.classify, self.id)
15
+ Resque.enqueue(Cleo::ResqueUpdate, record_type.classify, self.id)
16
16
  else
17
17
  Cleo.update(self)
18
18
  end
@@ -20,7 +20,7 @@ module ActsAsCleo
20
20
 
21
21
  def remove_from_cleo
22
22
  if Cleo::Server.async?
23
- Resque.enqueue(Cleo::Resque::Delete, self.record_type.classify, self.id)
23
+ Resque.enqueue(Cleo::ResqueDelete, record_type.classify, self.id)
24
24
  else
25
25
  Cleo.delete(self.cleo_id)
26
26
  cr = cleo_reference
data/lib/acts_as_cleo.rb CHANGED
@@ -2,12 +2,14 @@
2
2
  require File.dirname(__FILE__) + '/cleo'
3
3
 
4
4
  #Load ActsAsCleo method load
5
- require File.dirname(__FILE__) + '/acts_methods'
6
- require File.dirname(__FILE__) + '/class_methods'
7
- require File.dirname(__FILE__) + '/instance_methods'
5
+ require File.dirname(__FILE__) + '/acts_as_cleo/acts_methods'
6
+ require File.dirname(__FILE__) + '/acts_as_cleo/class_methods'
7
+ require File.dirname(__FILE__) + '/acts_as_cleo/instance_methods'
8
8
 
9
9
  module ActsAsCleo
10
10
  include ActsMethods
11
+
12
+ require 'rails/railtie' if defined?(Rails)
11
13
  end
12
14
 
13
15
  ActiveRecord::Base.extend ActsAsCleo
data/lib/cleo/server.rb CHANGED
@@ -13,11 +13,6 @@ module Cleo
13
13
 
14
14
  env = ENV['QUEUE'] || ''
15
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
21
16
  end
22
17
 
23
18
  def self.load_configuration
@@ -25,8 +20,6 @@ module Cleo
25
20
 
26
21
  if File.exists?( cleo_file_path )
27
22
  Cleo::Server.configure(YAML::load_file( cleo_file_path )[Rails.env].symbolize_keys)
28
- else
29
- raise LoadError.new("No cleo.yml found. Please viery that you have a copy of cleo.yml in your config directory.")
30
23
  end
31
24
  end
32
25
 
@@ -0,0 +1,35 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/migration'
3
+ require 'active_record'
4
+ require 'rails/generators/active_record'
5
+
6
+ module ActsAsCleo
7
+ class InstallGenerator < Rails::Generators::Base
8
+ include Rails::Generators::Migration
9
+
10
+ source_root File.expand_path("../templates", __FILE__)
11
+
12
+ def copy_migration_and_config
13
+
14
+ #Config file
15
+ copy_file 'cleo.yml', "config/cleo.yml"
16
+
17
+ #Resque workers
18
+ %w{update create delete}.each do |life|
19
+ copy_file "jobs/#{life}.rb", "app/jobs/#{life}.rb"
20
+ end
21
+
22
+ #create migration
23
+ migration_template 'install.rb', 'db/migrate/install_acts_as_audited.rb'
24
+ end
25
+
26
+ def self.next_migration_number(dirname)
27
+ next_migration_number = current_migration_number(dirname) + 1
28
+ if ActiveRecord::Base.timestamped_migrations
29
+ [Time.now.utc.strftime("%Y%m%d%H%M%S"), "%.14d" % next_migration_number].max
30
+ else
31
+ "%.3d" % next_migration_number
32
+ end
33
+ end
34
+ end
35
+ end
@@ -1,6 +1,8 @@
1
1
  # Config file for the acts_as_cleo plugin.
2
2
  development:
3
3
  url: "http://localhost:8080/cleo-primer/"
4
+ run_async: true
5
+ queue: "cleo"
4
6
 
5
7
  test:
6
8
  url: "http://localhost:8080/cleo-primer/"
@@ -0,0 +1,10 @@
1
+ module Cleo
2
+ module ResqueCreate
3
+ @queue = Cleo::Server.queue
4
+
5
+ def self.perform(klass, klass_id)
6
+ to_create = Kernel.const_get(klass).find(klass_id)
7
+ Cleo.create(to_create)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,12 @@
1
+ module Cleo
2
+ module ResqueDelete
3
+ @queue = Cleo::Server.queue
4
+
5
+ def self.perform(klass, klass_id)
6
+ to_delete = Kernel.const_get(klass).find(klass_id)
7
+ Cleo.delete(to_delete.cleo_id)
8
+ cr = Cleo::Reference.find(:first, :conditions => ["record_type = ? and record_id = ?", klass, to_delete.id])
9
+ cr.delete
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ module Cleo
2
+ module ResqueUpdate
3
+ @queue = Cleo::Server.queue
4
+
5
+ def self.perform(klass, klass_id)
6
+ to_update = Kernel.const_get(klass).find(klass_id)
7
+ Cleo.update(to_update)
8
+ end
9
+ end
10
+ end
data/test/db/test.db CHANGED
Binary file
data/test/helper.rb CHANGED
@@ -2,6 +2,7 @@ require 'simplecov'
2
2
  SimpleCov.start
3
3
 
4
4
  require 'rails'
5
+ require 'resque'
5
6
  require 'rubygems'
6
7
  require 'bundler'
7
8
  require 'active_record'
@@ -35,5 +36,8 @@ require sqlite
35
36
  models_dir = File.join(file_dirname, 'models')
36
37
  Dir[ models_dir + '/*.rb'].each { |m| require m }
37
38
 
39
+ server_config = {:url => "http://localhost:8080/cleo-primer/", :run_async => false}
40
+ Cleo::Server.configure server_config
41
+
38
42
  class Test::Unit::TestCase
39
43
  end
@@ -1,10 +1,10 @@
1
1
  require 'helper'
2
- require 'generators/acts_as_cleo/install_generator'
2
+ require 'generators/acts_as_cleo/install/install_generator'
3
3
 
4
4
  class InstallGeneratorTest < Rails::Generators::TestCase
5
5
  destination File.expand_path('../../tmp', __FILE__)
6
6
  setup :prepare_destination
7
- tests ActsAsCleo::Generators::InstallGenerator
7
+ tests ActsAsCleo::InstallGenerator
8
8
 
9
9
  should "generate a migration" do
10
10
  run_generator %w(install)
@@ -58,13 +58,17 @@ class TestCleo < Test::Unit::TestCase
58
58
  end
59
59
 
60
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' )
61
+ server_config = {:url => "http://localhost:8080/cleo-primer/", :run_async => true, :queue => "cleo"}
63
62
 
64
- Cleo::Server.configure YAML::load_file( cleo_file_path )['async_test'].symbolize_keys
63
+ Cleo::Server.configure server_config
65
64
  assert Cleo::Server.async?
66
65
  assert "cleo", Cleo::Server.queue.to_s
67
66
 
67
+
68
+ server_config = {:url => "http://localhost:8080/cleo-primer/", :run_async => false}
69
+ Cleo::Server.configure server_config
70
+ assert_same false, Cleo::Server.async?
71
+ assert "cleo", Cleo::Server.queue.to_s
68
72
  end
69
73
  end
70
74
 
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.2.0
4
+ version: 2.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-03-23 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: happymapper
16
- requirement: &70251794879380 !ruby/object:Gem::Requirement
16
+ requirement: &70294157456900 !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: *70251794879380
24
+ version_requirements: *70294157456900
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rails
27
- requirement: &70251794878900 !ruby/object:Gem::Requirement
27
+ requirement: &70294157456420 !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: *70251794878900
35
+ version_requirements: *70294157456420
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: resque
38
- requirement: &70251794878420 !ruby/object:Gem::Requirement
38
+ requirement: &70294157455940 !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: :runtime
45
45
  prerelease: false
46
- version_requirements: *70251794878420
46
+ version_requirements: *70294157455940
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: shoulda
49
- requirement: &70251794877940 !ruby/object:Gem::Requirement
49
+ requirement: &70294157455460 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70251794877940
57
+ version_requirements: *70294157455460
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rdoc
60
- requirement: &70251794877460 !ruby/object:Gem::Requirement
60
+ requirement: &70294157454980 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '3.12'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70251794877460
68
+ version_requirements: *70294157454980
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: bundler
71
- requirement: &70251794876980 !ruby/object:Gem::Requirement
71
+ requirement: &70294157454500 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 1.0.0
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70251794876980
79
+ version_requirements: *70294157454500
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: jeweler
82
- requirement: &70251794876500 !ruby/object:Gem::Requirement
82
+ requirement: &70294157454020 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ~>
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: 1.8.3
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70251794876500
90
+ version_requirements: *70294157454020
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: simplecov
93
- requirement: &70251794876020 !ruby/object:Gem::Requirement
93
+ requirement: &70294157453540 !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: *70251794876020
101
+ version_requirements: *70294157453540
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: ruby-debug19
104
- requirement: &70251794875540 !ruby/object:Gem::Requirement
104
+ requirement: &70294157453060 !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: *70251794875540
112
+ version_requirements: *70294157453060
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: fixtures
115
- requirement: &70251794875060 !ruby/object:Gem::Requirement
115
+ requirement: &70294157452580 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ! '>='
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: '0'
121
121
  type: :development
122
122
  prerelease: false
123
- version_requirements: *70251794875060
123
+ version_requirements: *70294157452580
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: sqlite3
126
- requirement: &70251794874580 !ruby/object:Gem::Requirement
126
+ requirement: &70294157452100 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - ! '>='
@@ -131,7 +131,7 @@ dependencies:
131
131
  version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
- version_requirements: *70251794874580
134
+ version_requirements: *70294157452100
135
135
  description: LinkedIn Open Source type ahead tool's REST API as a ruby gem
136
136
  email: Blue.Dog.Archolite@gmail.com
137
137
  executables: []
@@ -146,22 +146,22 @@ files:
146
146
  - Rakefile
147
147
  - VERSION
148
148
  - acts_as_cleo.gemspec
149
- - config/cleo_example.yml
150
149
  - lib/acts_as_cleo.rb
150
+ - lib/acts_as_cleo/acts_methods.rb
151
+ - lib/acts_as_cleo/class_methods.rb
152
+ - lib/acts_as_cleo/instance_methods.rb
151
153
  - lib/acts_as_cleo/result.rb
152
154
  - lib/acts_as_cleo/version.rb
153
- - lib/acts_methods.rb
154
- - lib/class_methods.rb
155
155
  - lib/cleo.rb
156
- - lib/cleo/jobs/create.rb
157
- - lib/cleo/jobs/delete.rb
158
- - lib/cleo/jobs/update.rb
159
156
  - lib/cleo/reference.rb
160
157
  - lib/cleo/result.rb
161
158
  - lib/cleo/server.rb
162
- - lib/generators/acts_as_cleo/install_generator.rb
163
- - lib/generators/acts_as_cleo/templates/install.rb
164
- - lib/instance_methods.rb
159
+ - lib/generators/acts_as_cleo/install/install_generator.rb
160
+ - lib/generators/acts_as_cleo/install/templates/cleo.yml
161
+ - lib/generators/acts_as_cleo/install/templates/install.rb
162
+ - lib/generators/acts_as_cleo/install/templates/jobs/create.rb
163
+ - lib/generators/acts_as_cleo/install/templates/jobs/delete.rb
164
+ - lib/generators/acts_as_cleo/install/templates/jobs/update.rb
165
165
  - test/config/cleo.yml
166
166
  - test/data/xml/cleo/element.xml
167
167
  - test/data/xml/cleo/elements.xml
@@ -1,12 +0,0 @@
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
@@ -1,14 +0,0 @@
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
@@ -1,12 +0,0 @@
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
@@ -1,28 +0,0 @@
1
- require 'rails/generators'
2
- require 'rails/generators/migration'
3
- require 'active_record'
4
- require 'rails/generators/active_record'
5
-
6
- module ActsAsCleo
7
- module Generators
8
- class InstallGenerator < Rails::Generators::Base
9
- include Rails::Generators::Migration
10
-
11
- source_root File.expand_path("../templates", __FILE__)
12
-
13
- # Implement the required interface for Rails::Generators::Migration.
14
- def self.next_migration_number(dirname) #:nodoc:
15
- next_migration_number = current_migration_number(dirname) + 1
16
- if ActiveRecord::Base.timestamped_migrations
17
- [Time.now.utc.strftime("%Y%m%d%H%M%S"), "%.14d" % next_migration_number].max
18
- else
19
- "%.3d" % next_migration_number
20
- end
21
- end
22
-
23
- def copy_migration
24
- migration_template 'install.rb', 'db/migrate/install_acts_as_audited.rb'
25
- end
26
- end
27
- end
28
- end