batch_insert 0.2 → 0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. data/Rakefile +35 -38
  2. data/init.rb +1 -3
  3. data/lib/batch_insert.rb +16 -12
  4. metadata +16 -16
  5. data/rails/init.rb +0 -3
data/Rakefile CHANGED
@@ -1,46 +1,43 @@
1
1
  require 'rake'
2
- require 'spec/rake/spectask'
2
+ require 'rake/testtask'
3
+ require 'rdoc/task'
4
+ require 'rspec/core/rake_task'
3
5
 
4
- require 'rubygems'
5
- require 'rake/gempackagetask'
6
+ desc 'Default: run unit tests.'
7
+ task :default => :test
6
8
 
7
- PKG_FILES = FileList[
8
- '[a-zA-Z]*',
9
- 'generators/**/*',
10
- 'lib/**/*',
11
- 'rails/**/*',
12
- 'spec/**/*'
13
- ]
14
-
15
- spec = Gem::Specification.new do |s|
16
- s.name = 'batch_insert'
17
- s.version = '0.2'
18
- s.author = 'Shaun Mangelsdorf'
19
- s.email = 's.mangelsdorf@gmail.com'
20
- s.homepage = 'http://smangelsdorf.github.com'
21
- s.platform = Gem::Platform::RUBY
22
- s.summary = 'Extends ActiveRecord to provide batch insertion capabilities'
23
- s.files = PKG_FILES.to_a
24
- s.require_path = 'lib'
25
- s.has_rdoc = false
26
- s.extra_rdoc_files = ['README.md']
27
- s.rubyforge_project = 'batch_insert'
28
- s.description = <<EOF
29
- Adds batch insertion capabilities to ActiveRecord model classes.
30
- EOF
9
+ desc 'Generate documentation for the batch_insert plugin.'
10
+ RDoc::Task.new(:rdoc) do |rdoc|
11
+ rdoc.rdoc_dir = 'rdoc'
12
+ rdoc.title = 'BatchInsert'
13
+ rdoc.options << '--line-numbers' << '--inline-source'
14
+ rdoc.rdoc_files.include('README')
15
+ rdoc.rdoc_files.include('lib/**/*.rb')
31
16
  end
32
17
 
33
- desc 'Default: run specs.'
34
- task :default => :spec
35
-
36
- desc 'Run the specs'
37
- Spec::Rake::SpecTask.new(:spec) do |t|
38
- t.spec_opts = ['--colour --format progress --loadby mtime --reverse']
39
- t.spec_files = FileList['spec/**/*_spec.rb']
18
+ RSpec::Core::RakeTask.new do |t|
19
+ t.rspec_opts = ["-c", "-f progress", "-r ./spec/spec_helper.rb"]
20
+ t.pattern = 'spec/*_spec.rb'
40
21
  end
41
22
 
42
- desc 'Turn this plugin into a gem.'
43
- Rake::GemPackageTask.new(spec) do |pkg|
44
- pkg.gem_spec = spec
23
+ begin
24
+ require 'jeweler'
25
+ Jeweler::Tasks.new do |gem|
26
+ gem.name = 'batch_insert'
27
+ gem.summary = 'Extends ActiveRecord to provide batch insertion capabilities'
28
+ gem.description = 'Adds batch insertion capabilities to ActiveRecord model classes.'
29
+ gem.files = Dir[
30
+ '[a-zA-Z]*',
31
+ 'generators/**/*',
32
+ 'lib/**/*',
33
+ 'rails/**/*',
34
+ 'spec/**/*'
35
+ ]
36
+ gem.extra_rdoc_files = ['README.md']
37
+ gem.authors = ['Shaun Mangelsdorf']
38
+ gem.homepage = 'http://smangelsdorf.github.com'
39
+ gem.version = '0.3'
40
+ end
41
+ rescue LoadError
42
+ puts "Jeweler could not be sourced"
45
43
  end
46
-
data/init.rb CHANGED
@@ -1,3 +1 @@
1
- # Released under the MIT license. See the LICENSE file for details
2
-
3
- require File.join(File.dirname(__FILE__), 'rails', 'init')
1
+ # Include hook code here
data/lib/batch_insert.rb CHANGED
@@ -1,18 +1,12 @@
1
1
  # Released under the MIT license. See the MIT-LICENSE file for details
2
- module ActiveRecord
3
- module BatchInsert
4
- def self.included(base)
5
- base.class_inheritable_accessor :batched_inserts
6
- base.class_inheritable_accessor :batched_insert_opts
7
- base.extend ClassMethods
8
- end
9
-
2
+ module BatchInsert
3
+ module ActiveRecordExtension
10
4
  module ClassMethods
11
5
  def batch_insert(opts={})
12
- self.batched_inserts = returning(batched_inserts) do
6
+ self.batched_inserts = batched_inserts.tap do
13
7
  self.batched_inserts = []
14
8
 
15
- self.batched_insert_opts = returning(batched_insert_opts) do
9
+ self.batched_insert_opts = batched_insert_opts.tap do
16
10
  self.batched_insert_opts = opts
17
11
  yield
18
12
  end
@@ -42,8 +36,8 @@ module ActiveRecord
42
36
  end
43
37
 
44
38
  def insert(opts={})
45
- returning new(opts) do |obj|
46
- raise RecordInvalid.new(obj) unless obj.valid?
39
+ new(opts).tap do |obj|
40
+ raise ActiveRecord::RecordInvalid.new(obj) unless obj.valid?
47
41
  self.batched_inserts << obj.attributes
48
42
 
49
43
  limit = batched_insert_opts[:batch_size].to_i
@@ -52,4 +46,14 @@ module ActiveRecord
52
46
  end
53
47
  end
54
48
  end
49
+
50
+ class Railtie < Rails::Railtie
51
+ initializer 'batch_insert.install_active_record_mixins' do
52
+ ActiveRecord::Base.instance_eval do
53
+ send :extend, ::BatchInsert::ActiveRecordExtension::ClassMethods
54
+ class_inheritable_accessor :batched_inserts
55
+ class_inheritable_accessor :batched_insert_opts
56
+ end
57
+ end
58
+ end
55
59
  end
metadata CHANGED
@@ -1,11 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: batch_insert
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 13
5
+ prerelease:
5
6
  segments:
6
7
  - 0
7
- - 2
8
- version: "0.2"
8
+ - 3
9
+ version: "0.3"
9
10
  platform: ruby
10
11
  authors:
11
12
  - Shaun Mangelsdorf
@@ -13,14 +14,11 @@ autorequire:
13
14
  bindir: bin
14
15
  cert_chain: []
15
16
 
16
- date: 2010-11-18 00:00:00 +10:00
17
- default_executable:
17
+ date: 2011-08-16 00:00:00 Z
18
18
  dependencies: []
19
19
 
20
- description: |
21
- Adds batch insertion capabilities to ActiveRecord model classes.
22
-
23
- email: s.mangelsdorf@gmail.com
20
+ description: Adds batch insertion capabilities to ActiveRecord model classes.
21
+ email:
24
22
  executables: []
25
23
 
26
24
  extensions: []
@@ -28,15 +26,13 @@ extensions: []
28
26
  extra_rdoc_files:
29
27
  - README.md
30
28
  files:
31
- - uninstall.rb
32
- - init.rb
33
29
  - MIT-LICENSE
34
- - Rakefile
35
30
  - README.md
31
+ - Rakefile
32
+ - init.rb
36
33
  - install.rb
37
34
  - lib/batch_insert.rb
38
- - rails/init.rb
39
- has_rdoc: true
35
+ - uninstall.rb
40
36
  homepage: http://smangelsdorf.github.com
41
37
  licenses: []
42
38
 
@@ -46,23 +42,27 @@ rdoc_options: []
46
42
  require_paths:
47
43
  - lib
48
44
  required_ruby_version: !ruby/object:Gem::Requirement
45
+ none: false
49
46
  requirements:
50
47
  - - ">="
51
48
  - !ruby/object:Gem::Version
49
+ hash: 3
52
50
  segments:
53
51
  - 0
54
52
  version: "0"
55
53
  required_rubygems_version: !ruby/object:Gem::Requirement
54
+ none: false
56
55
  requirements:
57
56
  - - ">="
58
57
  - !ruby/object:Gem::Version
58
+ hash: 3
59
59
  segments:
60
60
  - 0
61
61
  version: "0"
62
62
  requirements: []
63
63
 
64
- rubyforge_project: batch_insert
65
- rubygems_version: 1.3.6
64
+ rubyforge_project:
65
+ rubygems_version: 1.8.5
66
66
  signing_key:
67
67
  specification_version: 3
68
68
  summary: Extends ActiveRecord to provide batch insertion capabilities
data/rails/init.rb DELETED
@@ -1,3 +0,0 @@
1
- require 'batch_insert'
2
-
3
- ActiveRecord::Base.send :include, ActiveRecord::BatchInsert