active_model_archive 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
@@ -8,7 +8,9 @@ module ActiveModelArchive
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def encode(object)
|
11
|
-
object.as_archive.values_at(*object.archive_attributes).
|
11
|
+
object.as_archive.values_at(*object.archive_attributes).map do |value|
|
12
|
+
value.respond_to?(:any?) && value.any? ? ActiveSupport::JSON.encode(value) : value
|
13
|
+
end.to_csv
|
12
14
|
end
|
13
15
|
|
14
16
|
def parse(io)
|
@@ -19,7 +21,10 @@ module ActiveModelArchive
|
|
19
21
|
first_line = false
|
20
22
|
header = line.parse_csv
|
21
23
|
else
|
22
|
-
|
24
|
+
values = line.parse_csv.map do |value|
|
25
|
+
begin ActiveSupport::JSON.decode(value) rescue value end
|
26
|
+
end
|
27
|
+
yield Hash[header.zip(values)]
|
23
28
|
end
|
24
29
|
end
|
25
30
|
end
|
data/test/attributes_test.rb
CHANGED
@@ -16,4 +16,12 @@ class ActiveModelArchive::AttributesTest < MiniTest::Spec
|
|
16
16
|
model.to_archive
|
17
17
|
)
|
18
18
|
end
|
19
|
+
|
20
|
+
def test_to_archive_header
|
21
|
+
model = TestModel.new(id: 5, color: 'blue')
|
22
|
+
assert_equal(
|
23
|
+
model.class.archiver.header(model),
|
24
|
+
model.to_archive_header
|
25
|
+
)
|
26
|
+
end
|
19
27
|
end
|
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.
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-04-
|
12
|
+
date: 2012-04-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirement: &70140718024440 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,15 +21,10 @@ dependencies:
|
|
21
21
|
version: '3'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ~>
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '3'
|
24
|
+
version_requirements: *70140718024440
|
30
25
|
- !ruby/object:Gem::Dependency
|
31
26
|
name: yajl-ruby
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
27
|
+
requirement: &70140718023620 !ruby/object:Gem::Requirement
|
33
28
|
none: false
|
34
29
|
requirements:
|
35
30
|
- - ! '>='
|
@@ -37,12 +32,7 @@ dependencies:
|
|
37
32
|
version: '0'
|
38
33
|
type: :runtime
|
39
34
|
prerelease: false
|
40
|
-
version_requirements:
|
41
|
-
none: false
|
42
|
-
requirements:
|
43
|
-
- - ! '>='
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: '0'
|
35
|
+
version_requirements: *70140718023620
|
46
36
|
description: Adds dump and restore functionality to activemodel classes
|
47
37
|
email:
|
48
38
|
- grantr@gmail.com
|
@@ -88,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
78
|
version: '0'
|
89
79
|
requirements: []
|
90
80
|
rubyforge_project: active_model_archive
|
91
|
-
rubygems_version: 1.8.
|
81
|
+
rubygems_version: 1.8.17
|
92
82
|
signing_key:
|
93
83
|
specification_version: 3
|
94
84
|
summary: Dump and restore activemodel objects
|