rails-archiver 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rails-archiver/archiver.rb +2 -2
- data/lib/rails-archiver/transport/base.rb +6 -2
- data/lib/rails-archiver/transport/in_memory.rb +1 -1
- data/lib/rails-archiver/transport/s3.rb +18 -4
- data/lib/rails-archiver/unarchiver.rb +5 -2
- data/rails-archiver.gemspec +6 -6
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0d76121c6ff0a8777277b47da964fc253096491
|
4
|
+
data.tar.gz: ee9dcbe2c0d1ec468ba44dc2e86b4f5f5b3c9f17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eaf86068fff7d987a7098be77ec1cc25653525f973cc8abe4a97210a108feb2050d8f2ebba3bd8f35bae34c8f30c878aa1c3d7dc172ed2fd1e24d620001fb031
|
7
|
+
data.tar.gz: 14b088a8db577c782628458dadc86e40db6b551cb2d31a8bdff9391973469c1624dba5d82ba2c826dc42750a1ae946d2c9cc2a34a358fc83879c63d7f3ad32f1
|
@@ -15,7 +15,7 @@ module RailsArchiver
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
attr_accessor :transport
|
18
|
+
attr_accessor :transport, :archive_location
|
19
19
|
|
20
20
|
# Create a new Archiver with the given model.
|
21
21
|
# @param model [ActiveRecord::Base] the model to archive or unarchive.
|
@@ -41,7 +41,7 @@ module RailsArchiver
|
|
41
41
|
@hash = {}
|
42
42
|
_visit_association(@model)
|
43
43
|
@logger.info('Completed loading data')
|
44
|
-
@transport.store_archive(@hash)
|
44
|
+
@archive_location = @transport.store_archive(@hash)
|
45
45
|
if @model.attribute_names.include?('archived')
|
46
46
|
@model.update_attribute(:archived, true)
|
47
47
|
end
|
@@ -5,7 +5,8 @@ module RailsArchiver
|
|
5
5
|
class Base
|
6
6
|
|
7
7
|
# @param model [ActiveRecord::Base] the model we will be working with.
|
8
|
-
|
8
|
+
# @param logger [Logger]
|
9
|
+
def initialize(model=nil, logger=nil)
|
9
10
|
@model = model
|
10
11
|
@options = {}
|
11
12
|
@logger = logger || ::Logger.new(STDOUT)
|
@@ -27,8 +28,11 @@ module RailsArchiver
|
|
27
28
|
|
28
29
|
# To be implemented by subclasses. Retrieve the archive that was previously
|
29
30
|
# created.
|
31
|
+
# @param location [String] if given, the location of the archive (e.g.
|
32
|
+
# S3 key). Otherwise will be figured out from the existing model
|
33
|
+
# in the database.
|
30
34
|
# @return [Hash] the retrieved hash.
|
31
|
-
def retrieve_archive
|
35
|
+
def retrieve_archive(location=nil)
|
32
36
|
raise NotImplementedError
|
33
37
|
end
|
34
38
|
|
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'aws-sdk'
|
2
2
|
require 'securerandom'
|
3
|
+
require 'tmpdir'
|
4
|
+
|
3
5
|
# Transport that stores to S3. Uses an archived_s3_key attribute.
|
4
6
|
module RailsArchiver
|
5
7
|
module Transport
|
@@ -38,14 +40,26 @@ module RailsArchiver
|
|
38
40
|
@logger.info("Uploading file to #{s3_key}")
|
39
41
|
_save_archive_to_s3(s3_key, filename)
|
40
42
|
end
|
43
|
+
if @model.respond_to?(:archived_s3_key)
|
44
|
+
@model.update_attribute(:archived_s3_key, s3_key)
|
45
|
+
end
|
41
46
|
s3_key
|
42
|
-
@model.update_attribute(:archived_s3_key, s3_key)
|
43
47
|
end
|
44
48
|
|
45
|
-
|
49
|
+
# @param location [String]
|
50
|
+
def retrieve_archive(location=nil)
|
46
51
|
Dir.mktmpdir do |dir|
|
47
|
-
|
48
|
-
|
52
|
+
s3_key = location
|
53
|
+
filename = nil
|
54
|
+
if @model
|
55
|
+
if @model.respond_to?(:archived_s3_key)
|
56
|
+
s3_key ||= @model.archived_s3_key
|
57
|
+
end
|
58
|
+
filename = "#{dir}/#{@model.id}.json"
|
59
|
+
else
|
60
|
+
filename = File.basename(s3_key)
|
61
|
+
end
|
62
|
+
_get_archive_from_s3(s3_key, "#{filename}.gz")
|
49
63
|
@logger.info('Unzipping file')
|
50
64
|
gunzip("#{filename}.gz")
|
51
65
|
@logger.info('Parsing JSON')
|
@@ -27,10 +27,13 @@ module RailsArchiver
|
|
27
27
|
end
|
28
28
|
|
29
29
|
# Unarchive a model.
|
30
|
-
|
30
|
+
# @param location [String] if given, uses the given location to unarchive.
|
31
|
+
# Otherwise uses the existing model in the database (e.g. attribute on the
|
32
|
+
# model) depending on the transport being used.
|
33
|
+
def unarchive(location=nil)
|
31
34
|
@errors = []
|
32
35
|
@logger.info('Downloading JSON file')
|
33
|
-
hash = @transport.retrieve_archive
|
36
|
+
hash = @transport.retrieve_archive(location)
|
34
37
|
@logger.info("Loading #{@model.class.name}")
|
35
38
|
load_classes(hash)
|
36
39
|
@model.reload
|
data/rails-archiver.gemspec
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'rails-archiver'
|
3
3
|
s.require_paths = %w(. lib lib/rails-archiver)
|
4
|
-
s.version = '0.1.
|
5
|
-
s.date = '2018-05-
|
4
|
+
s.version = '0.1.3'
|
5
|
+
s.date = '2018-05-28'
|
6
6
|
s.summary = 'Fully archive a Rails model'
|
7
7
|
s.description = <<-EOF
|
8
|
-
EOF
|
8
|
+
EOF
|
9
9
|
s.authors = ['Daniel Orner']
|
10
10
|
s.email = 'daniel.orner@wishabi.com'
|
11
|
-
s.files = `git ls-files`.split(
|
11
|
+
s.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
12
12
|
s.homepage = 'https://github.com/dorner/rails-archiver'
|
13
|
-
s.license
|
13
|
+
s.license = 'MIT'
|
14
14
|
|
15
15
|
s.add_dependency 'rails', '>= 3.0'
|
16
|
-
s.
|
16
|
+
s.add_development_dependency 'aws-sdk-s3', '~> 1.13'
|
17
17
|
|
18
18
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-archiver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Orner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-05-
|
11
|
+
date: 2018-05-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -25,19 +25,19 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '3.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name: aws-sdk
|
28
|
+
name: aws-sdk-s3
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
34
|
-
type: :
|
33
|
+
version: '1.13'
|
34
|
+
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '1.13'
|
41
41
|
description: ''
|
42
42
|
email: daniel.orner@wishabi.com
|
43
43
|
executables: []
|