crewait 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest +1 -0
- data/README.rdoc +2 -0
- data/Rakefile +1 -1
- data/crewait.gemspec +3 -3
- data/lib/crewait.rb +37 -32
- metadata +5 -5
data/Manifest
CHANGED
data/README.rdoc
CHANGED
@@ -4,6 +4,8 @@ Check out http://jonah.org/articles/crewait_go_.html for a guide to Crewait.
|
|
4
4
|
|
5
5
|
= Heroes
|
6
6
|
|
7
|
+
Geoff Davis pointed out how much memory was being eaten by the singleton methods!
|
8
|
+
_capsized added support for the mysql2 adapter!
|
7
9
|
alexkalish made it possible to have namespaced models!
|
8
10
|
choffstein added Postgresql support!
|
9
11
|
jakemack resolved some conflicts with Array#to_sql!
|
data/Rakefile
CHANGED
@@ -3,7 +3,7 @@ require 'rubygems'
|
|
3
3
|
require 'rake'
|
4
4
|
require 'echoe'
|
5
5
|
|
6
|
-
Echoe.new('crewait', '0.1.
|
6
|
+
Echoe.new('crewait', '0.1.7') do |p|
|
7
7
|
p.description = "Intuitive and fast bulk insertion in ActiveRecord"
|
8
8
|
p.url = "http://github.com/theAlmanac/crewait"
|
9
9
|
p.author = "Jonah Bloch-Johnson"
|
data/crewait.gemspec
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{crewait}
|
5
|
-
s.version = "0.1.
|
5
|
+
s.version = "0.1.7"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Jonah Bloch-Johnson"]
|
9
|
-
s.date = %q{2010-
|
9
|
+
s.date = %q{2010-10-18}
|
10
10
|
s.description = %q{Intuitive and fast bulk insertion in ActiveRecord}
|
11
11
|
s.email = %q{me@jonah.org}
|
12
12
|
s.extra_rdoc_files = ["README.rdoc", "lib/crewait.rb"]
|
13
|
-
s.files = ["Manifest", "README.rdoc", "Rakefile", "
|
13
|
+
s.files = ["Manifest", "README.rdoc", "Rakefile", "crewait.gemspec", "lib/crewait.rb"]
|
14
14
|
s.homepage = %q{http://github.com/theAlmanac/crewait}
|
15
15
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Crewait", "--main", "README.rdoc"]
|
16
16
|
s.require_paths = ["lib"]
|
data/lib/crewait.rb
CHANGED
@@ -2,7 +2,8 @@
|
|
2
2
|
# The idea is the you start a Crewait session, you use ActiveRecord::Base#crewait instead of #create, and then at some point you tell it to go!, which bulk inserts all those created records into SQL.
|
3
3
|
module Crewait
|
4
4
|
|
5
|
-
def self.start_waiting
|
5
|
+
def self.start_waiting(config = {})
|
6
|
+
config(config)
|
6
7
|
# clear our all important hash caches
|
7
8
|
@@hash_of_hashes = {}
|
8
9
|
@@hash_of_next_inserts = {}
|
@@ -15,16 +16,17 @@ module Crewait
|
|
15
16
|
# if this class is new, create a new hash to receive it
|
16
17
|
@@hash_of_hashes[model] ||= {}
|
17
18
|
@@hash_of_hashes[model].respectively_insert(hash)
|
19
|
+
hash[:id] = @@hash_of_next_inserts[model] + @@hash_of_hashes[model].inner_length - 1
|
18
20
|
# add dummy methods
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
21
|
+
unless @@config[:no_methods]
|
22
|
+
eigenclass = class << hash; self; end
|
23
|
+
eigenclass.class_eval {
|
24
|
+
hash.each do |key, value|
|
25
|
+
define_method(key) { value }
|
26
|
+
# define_method(key.to_s + '=') { set_value(fake_id, )}
|
27
|
+
end
|
28
|
+
}
|
29
|
+
end
|
28
30
|
hash
|
29
31
|
end
|
30
32
|
|
@@ -36,35 +38,38 @@ module Crewait
|
|
36
38
|
@@hash_of_next_inserts = {}
|
37
39
|
end
|
38
40
|
|
41
|
+
def self.config(hash)
|
42
|
+
@@config = {} unless defined?(@@config)
|
43
|
+
@@config.merge!(hash)
|
44
|
+
end
|
45
|
+
|
39
46
|
module BaseMethods
|
40
47
|
def next_insert_id
|
41
48
|
connection = ActiveRecord::Base.connection
|
42
|
-
database = connection.current_database
|
43
|
-
|
49
|
+
database, adapter = connection.current_database, connection.adapter_name
|
50
|
+
sql = case adapter.downcase
|
51
|
+
when 'postgresql'
|
52
|
+
"SELECT nextval('#{self.table_name}_id_seq')"
|
53
|
+
when /mysql/
|
54
|
+
"SELECT auto_increment FROM information_schema.tables WHERE table_name='#{self.table_name}' AND table_schema ='#{database}'"
|
55
|
+
else
|
56
|
+
raise "your database/adapter (#{adapter}) is not supported by crewait! want to write a patch?"
|
57
|
+
end
|
58
|
+
results = ActiveRecord::Base.connection.execute(sql)
|
44
59
|
case adapter.downcase
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
" ).fetch_hash['auto_increment'].to_i
|
54
|
-
else
|
55
|
-
raise "your database is not supported by crewait! want to write a patch?"
|
60
|
+
when 'postgresql'
|
61
|
+
results[0]["nextval"].to_i
|
62
|
+
when 'mysql'
|
63
|
+
results.fetch_hash['auto_increment'].to_i
|
64
|
+
when 'mysql2'
|
65
|
+
results.map {|x| x[0]}[0].to_i
|
66
|
+
else
|
67
|
+
raise "your database/adapter (#{adapter}) is not supported by crewait! want to write a patch?"
|
56
68
|
end
|
57
69
|
end
|
58
70
|
|
59
71
|
def crewait(hash)
|
60
|
-
|
61
|
-
unless stay_a_hash
|
62
|
-
Crewait.for(self, hash)
|
63
|
-
else
|
64
|
-
object = self.new(hash)
|
65
|
-
object.before_validation
|
66
|
-
Crewait.for(object.class, object.attributes)
|
67
|
-
end
|
72
|
+
Crewait.for(self, hash)
|
68
73
|
end
|
69
74
|
end
|
70
75
|
|
@@ -122,4 +127,4 @@ end
|
|
122
127
|
|
123
128
|
class Array
|
124
129
|
include Crewait::ArrayMethods
|
125
|
-
end
|
130
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crewait
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 7
|
10
|
+
version: 0.1.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jonah Bloch-Johnson
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-10-18 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -32,8 +32,8 @@ files:
|
|
32
32
|
- Manifest
|
33
33
|
- README.rdoc
|
34
34
|
- Rakefile
|
35
|
-
- lib/crewait.rb
|
36
35
|
- crewait.gemspec
|
36
|
+
- lib/crewait.rb
|
37
37
|
has_rdoc: true
|
38
38
|
homepage: http://github.com/theAlmanac/crewait
|
39
39
|
licenses: []
|