active_model_archive 0.0.1 → 0.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.
@@ -1,3 +1,3 @@
1
1
  module ActiveModelArchive
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -79,6 +79,16 @@ module ActiveModel
79
79
  # executes the block with each restored record if given
80
80
  # the block can be used to log progress and warn about invalid objects
81
81
  def restore!(stream, options={}, &block)
82
+
83
+ # for each hash read, create an object
84
+ each_archive(stream) do |hash|
85
+ o = from_archive(hash)
86
+ o.save(:validate => !!options[:validate])
87
+ yield o if block_given?
88
+ end
89
+ end
90
+
91
+ def each_archive(stream, &block)
82
92
  # check magic byte
83
93
  magic = archive_read_int(stream)
84
94
  raise "Not an archive stream" unless magic == MAGIC
@@ -89,21 +99,7 @@ module ActiveModel
89
99
 
90
100
  count = 0
91
101
  parser = Yajl::Parser.new
92
-
93
- if options[:check]
94
- # if we are just checking, increment but do not create anything
95
- parser.on_parse_complete = lambda do |hash|
96
- count += 1
97
- end
98
- else
99
- # for each hash read, create an object
100
- parser.on_parse_complete = lambda do |hash|
101
- o = from_archive(hash)
102
- o.save(:validate => !!options[:validate])
103
- block.call(o) if block_given?
104
- count += 1
105
- end
106
- end
102
+ parser.on_parse_complete = block if block_given?
107
103
 
108
104
  # loop through records until a null is read
109
105
  record_size = archive_read_int(stream)
@@ -126,7 +122,7 @@ module ActiveModel
126
122
  # returns true if the archive is valid
127
123
  def valid_archive?(stream)
128
124
  begin
129
- restore!(stream, :check => true)
125
+ each_archive(stream)
130
126
  rescue
131
127
  return false
132
128
  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: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-03-09 00:00:00.000000000 -08:00
12
+ date: 2011-03-16 00:00:00.000000000 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
17
- requirement: &14070060 !ruby/object:Gem::Requirement
17
+ requirement: &23233620 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '3'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *14070060
25
+ version_requirements: *23233620
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: yajl-ruby
28
- requirement: &14069320 !ruby/object:Gem::Requirement
28
+ requirement: &23232860 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *14069320
36
+ version_requirements: *23232860
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: rspec
39
- requirement: &14068620 !ruby/object:Gem::Requirement
39
+ requirement: &23232140 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,7 +44,7 @@ dependencies:
44
44
  version: '2'
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *14068620
47
+ version_requirements: *23232140
48
48
  description: Adds dump and restore functionality to activemodel classes
49
49
  email:
50
50
  - grantr@gmail.com