airblade-acts-as-importable 1.0.0 → 1.0.2

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.
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
1
  spec/debug.log
2
2
  pkg/
3
+ Gemfile.lock
@@ -32,15 +32,15 @@ module AMC
32
32
  end
33
33
 
34
34
  # This requires a numeric primary key for the legacy tables
35
- def import_all_in_batches
36
- each do |legacy_model|
35
+ def import_all_in_batches(*args)
36
+ find_each(*args) do |legacy_model|
37
37
  legacy_model.import
38
38
  end
39
39
  end
40
40
 
41
41
  def lookup(id)
42
42
  lookup_class = read_inheritable_attribute(:importable_to) || "#{self.to_s.split('::').last}"
43
- lookups[id] ||= Kernel.const_get(lookup_class).first(:conditions => {:legacy_id => id, :legacy_class => self.to_s}).try(:id__)
43
+ lookups[id] ||= Kernel.const_get(lookup_class).first(:conditions => {:legacy_id => id, :legacy_class => self.to_s}).try(:id)
44
44
  end
45
45
 
46
46
  def flush_lookups!
@@ -58,16 +58,13 @@ module AMC
58
58
  module InstanceMethods
59
59
 
60
60
  def import
61
- returning to_model do |new_model|
61
+ to_model.tap do |new_model|
62
62
  if new_model
63
63
  new_model.legacy_id = self.id if new_model.respond_to?(:"legacy_id=")
64
64
  new_model.legacy_class = self.class.to_s if new_model.respond_to?(:"legacy_class=")
65
65
 
66
66
  if !new_model.save
67
- p new_model.errors
68
- # TODO log an error that the model failed to save
69
- # TODO remove the raise once we're out of the development cycle
70
- raise
67
+ puts "#{new_model.errors.full_messages} <#{self.class.name}:#{id}>"
71
68
  end
72
69
  end
73
70
  end
@@ -78,5 +75,4 @@ module AMC
78
75
  end
79
76
  end
80
77
 
81
- require 'core_extensions'
82
78
  ActiveRecord::Base.class_eval { include AMC::Acts::Importable }
data/lib/version.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module AMC
2
2
  module Acts
3
3
  module Importable
4
- VERSION = '1.0.0'
4
+ VERSION = '1.0.2'
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: airblade-acts-as-importable
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 0
10
- version: 1.0.0
9
+ - 2
10
+ version: 1.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tim Riley, Andrew Stewart
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-08-02 00:00:00 +02:00
18
+ date: 2011-08-18 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -50,7 +50,6 @@ files:
50
50
  - airblade-acts-as-importable.gemspec
51
51
  - init.rb
52
52
  - lib/acts_as_importable.rb
53
- - lib/core_extensions.rb
54
53
  - lib/version.rb
55
54
  - spec/acts_as_importable_spec.rb
56
55
  - spec/database.yml
@@ -1,18 +0,0 @@
1
- # See http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/212639
2
- # And http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/210633 for alternative [:id] notation
3
- class ActiveRecord::Base
4
- alias_method :id__, :id if method_defined? :id
5
- end
6
-
7
-
8
- # From http://weblog.jamisbuck.org/2007/4/6/faking-cursors-in-activerecord
9
- class <<ActiveRecord::Base
10
- def each(limit=1000)
11
- rows = find(:all, :conditions => ["#{primary_key} > ?", 0], :limit => limit)
12
- while rows.any?
13
- rows.each { |record| yield record }
14
- rows = find(:all, :conditions => ["#{primary_key} > ?", rows.last.id], :limit => limit)
15
- end
16
- self
17
- end
18
- end