active_model_archive 1.1.2 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,2 +1,12 @@
1
- require 'bundler'
2
- Bundler::GemHelper.install_tasks
1
+ require 'bundler/setup'
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+
5
+ task default: :test
6
+
7
+ Rake::TestTask.new(:test) do |t|
8
+ t.libs << 'lib'
9
+ t.libs << 'test'
10
+ t.pattern = 'test/unit/**/*_test.rb'
11
+ t.verbose = true
12
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "active_model_archive"
5
- s.version = '1.1.2'
5
+ s.version = '1.2.0'
6
6
  s.platform = Gem::Platform::RUBY
7
7
  s.authors = ["Grant Rodgers"]
8
8
  s.email = ["grantr@gmail.com"]
@@ -0,0 +1,7 @@
1
+ module ActiveModelArchive
2
+ class Railtie < Rails::Railtie
3
+ rake_tasks do
4
+ load 'active_model_archive/tasks/archive.rake'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,56 @@
1
+ namespace :archive do
2
+ # == Example:
3
+ # rake archive:dump CLASS=Widgets FORMAT=tabs PER_FILE=10000 FILE=/mnt/widgets.tsv
4
+ desc "archive CLASS, using PER_FILE for number of records per FILE"
5
+ task dump: :environment do
6
+ filename = ENV['FILE'] || (raise "FILE required.")
7
+ model = (ENV['CLASS'] || (raise "CLASS required")).camelize.constantize
8
+
9
+ if ENV['PER_FILE']
10
+ per_file = ENV['PER_FILE'].to_i
11
+ else
12
+ per_file = nil
13
+ end
14
+
15
+ if ENV['FORMAT']
16
+ model.archiver_type = ENV['FORMAT']
17
+ end
18
+
19
+ logger.info "Dumping to #{filename}"
20
+ count = model.dump!(filename, per_file: per_file) do |object|
21
+ begin
22
+ logger.info object.id
23
+ rescue => e
24
+ logger.error "OBJECT #{object.id} caused dump to fail"
25
+ raise e
26
+ end
27
+ end
28
+ logger.info "#{count} records dumped."
29
+ end
30
+
31
+ # == Example:
32
+ # rake archive:restore CLASS=Widgets FORMAT=tabs FILE=/mnt/widgets.tsv
33
+ desc "restore a dump from FILE"
34
+ task restore: :environment do
35
+ filename = ENV['FILE'] || (raise "FILE required.")
36
+ model = (ENV['CLASS'] || (raise "CLASS required")).camelize.constantize
37
+
38
+ no_publish = (ENV['PUBLISH'] != 'true')
39
+ model.disable_publishing! if no_publish && model.respond_to?(:disable_publishing!)
40
+
41
+ start = Time.now
42
+
43
+ File.open(filename) do |file|
44
+ logger.info "Restoring from #{file.path}. indexing=#{!no_index}, publishing=#{!no_publish}"
45
+ count = model.each_instance(file) do |record|
46
+ logger.info "Saving #{record.id}"
47
+ record.save(validate: false)
48
+ unless record.persisted?
49
+ puts "Error saving record: #{record.inspect}"
50
+ end
51
+ end
52
+
53
+ puts "#{count} records restored in #{Time.now - start}."
54
+ end
55
+ end
56
+ end
@@ -44,3 +44,5 @@ module ActiveModel
44
44
  end
45
45
  end
46
46
  end
47
+
48
+ require 'active_model_archive/railtie'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_model_archive
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-25 00:00:00.000000000 Z
12
+ date: 2012-06-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -62,7 +62,9 @@ files:
62
62
  - lib/active_model_archive/attributes.rb
63
63
  - lib/active_model_archive/dump.rb
64
64
  - lib/active_model_archive/file_manager.rb
65
+ - lib/active_model_archive/railtie.rb
65
66
  - lib/active_model_archive/restore.rb
67
+ - lib/active_model_archive/tasks/archive.rake
66
68
  - test/archiver/csv_test.rb
67
69
  - test/archiver/tabs_test.rb
68
70
  - test/attributes_test.rb