rseed 1.0.4 → 1.0.5

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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NmM0NmU2ZmY1OWMwZDcwOWMyYjQzMGQxOTViM2I5ZGQ5NGU2M2I5MQ==
4
+ OGI0MmQ1MjQ1NDBjM2Q4YTk1Zjc4ZTgyNWEyYjc3YjNmZjZiNWQ5Mg==
5
5
  data.tar.gz: !binary |-
6
- NTdiYWIzZTRmMDdiNGYyZmRkNzNkNzgyMzc4NjhiYjQ4ZWU3OTExYQ==
6
+ ZDRmODFkM2EwNTE2NWY4YjFiYmUzZDM1YzlmYWZjYTNmMjYxYWMxNQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MjNlN2E4Mjc5OTYzMzg4NzM1NWQ0NTMxNGM0Y2MxZmFjOTgyODczMmI2ODI5
10
- YjI1NTJmNzkwZTI1ZThiNGZkNjA0MDkxNWQ3MDAzNjRiZGE0MzZiMWY0YjY1
11
- OGFmZjMyM2Y1ZTI5NTdlZmJiZjdlZDViM2RjOGMzNzQwZWJmMTk=
9
+ MGNiODY1NWZmMmIzZjQxY2VkYTAwYTZjM2IxNzI5OTVkNmQyYWFhMmY5NzE5
10
+ YTNmNDI5YjcwNWE0NGQ2MTlhNzkxZDA2MmUzZjJhMmJkMDRiMDNmMjIyMTQ3
11
+ ZTZkNWJiNTM5NGI5MjY3ODVkNDRmMmY2Y2U1YTcwNDJjYmI1MTQ=
12
12
  data.tar.gz: !binary |-
13
- ZDQxN2YwMzk3ZGYzYTU5YTkxZDRmNWQ2MDFlYzFiZGQ1NTA0ZWI0NzgxYjMz
14
- ZWQ3ZTVmODE1ZDBmNWJkYjJjOTcyZTRhNjNkYzc1YjY2Y2JmNjRlYThmZWQ2
15
- ZDBlMzkzOWQwYWYwNTk5MDY4MGMzNTQ1NTFhZjYxZTFiMmZmZmY=
13
+ MmI2MTk0ZmQyZjNlMTAxNzk0NGExMTYzNGFjYTVjOTVlZmE1NWMwYzc2OTJk
14
+ NzFkOGE3ODg2MmYyNWZjZDFmMGVjY2RhNGI2NThkNjlhOWIwOThlNjA1MTlj
15
+ YjAzNWY1YWVjYzlmMjA4MTU3ZjZkNWQ2NmQ0ZGE5ZjBlOTc5NDY=
data/README.rdoc CHANGED
@@ -45,36 +45,6 @@ This will cause the generator to create a file with fewer
45
45
 
46
46
  == The Converter File
47
47
 
48
- === before_deserialize
49
-
50
- If you define a function called before_serialize you can do any preprocessing you require. One example of this is
51
- marking an archive flag on existing data:
52
-
53
- def before_deserialize
54
- HtmlColor.where(import_archive: true).update_all({:import_archive => false})
55
- true
56
- end
57
-
58
- Note that you must return true from this function. Returning false will cause the processor to give up and log an error.
59
- Thus you can also use the following:
60
-
61
- def before_deserialize
62
- return fail_with_error "Mandatory option is missing" unless options["mandatory_option"]
63
- true
64
- end
65
-
66
- === after_deserialize
67
-
68
- You can define this function to be called at the end of processing. Following from the example above, if you set
69
- *import_archive* to be false for each model in the deserialize method, you could do the following to remove old
70
- records:
71
-
72
- def after_deserialize
73
- HtmlColor.where(import_archive: true).destroy_all
74
- end
75
-
76
- This is obviously fairly destructive and there are better ways to deal with this situation than destroying the records.
77
-
78
48
  === Attribute Options
79
49
 
80
50
  * :header
@@ -107,6 +77,37 @@ You may use any active record method in this case, such as :first_or_create, or
107
77
  * :optional
108
78
  Defines the attribute as optionsal. This has no effect in the *HashAdapter*.
109
79
 
80
+ === before_deserialize
81
+
82
+ If you define a function called before_serialize you can do any preprocessing you require. One example of this is
83
+ marking an archive flag on existing data:
84
+
85
+ def before_deserialize
86
+ HtmlColor.where(import_archive: true).update_all({:import_archive => false})
87
+ true
88
+ end
89
+
90
+ Note that you must return true from this function. Returning false will cause the processor to give up and log an error.
91
+ Thus you can also use the following:
92
+
93
+ def before_deserialize
94
+ return fail_with_error "Mandatory option is missing" unless options["mandatory_option"]
95
+ true
96
+ end
97
+
98
+ === after_deserialize
99
+
100
+ You can define this function to be called at the end of processing. Following from the example above, if you set
101
+ *import_archive* to be false for each model in the deserialize method, you could do the following to remove old
102
+ records:
103
+
104
+ def after_deserialize
105
+ HtmlColor.where(import_archive: true).destroy_all
106
+ end
107
+
108
+ This example is obviously fairly destructive and there are better ways to deal with this situation than destroying the
109
+ records.
110
+
110
111
  == Rake Tasks
111
112
 
112
113
  These rake tasks allow you to run seeds manually:
@@ -39,7 +39,7 @@ class <%= @converter_name.camelize %>Converter < Rseed::Converter
39
39
  # <%= @model_name %> = ::<%= @class_name %>.new
40
40
  #
41
41
  # For create or update, use the following instead and change the match attribute name as required
42
- # <%= @model_name %> = ::<%= @class_name %>.where(:id => values[:id]).first_or_initialize
42
+ # <%= @model_name %> = ::<%= @class_name %>.where(id: values[:id]).first_or_initialize
43
43
  <% end -%>
44
44
 
45
45
  <% if @match_attribute -%>
@@ -51,7 +51,7 @@ class <%= @converter_name.camelize %>Converter < Rseed::Converter
51
51
  success = <%= @model_name %>.update_attributes <%= @model_name %>_attributes(values)
52
52
 
53
53
  # This will return false and set errors if the record fails to update, signalling a failed import
54
- return fail_with_error <%= @model_name %>.errors unless success
54
+ return fail_with_error <%= @model_name %>.errors.to_a.join(', ') unless success
55
55
 
56
56
  # Return true signalling a successful import
57
57
  true
@@ -49,7 +49,7 @@ module Rseed
49
49
  # Takes the raw values coming out of an adapter and converts them based on the attribute definitions in the
50
50
  # converter.
51
51
  def deserialize_raw values
52
- converted_values = {}
52
+ converted_values = HashWithIndifferentAccess.new
53
53
  self.class.converter_attributes.each do |attribute|
54
54
  converted_values[attribute.name] = attribute.deserialize(values)
55
55
  end
data/lib/rseed/helpers.rb CHANGED
@@ -19,7 +19,7 @@ module Rseed
19
19
  title = options[:title] ? options[:title].dup : "Seed"
20
20
  title = "#{processor.converter.name.cyan} #{title.blue}"
21
21
  record_count = 0
22
- progress_bar = ProgressBar.create(starting_at: nil, total: nil, format: "#{"Preprocessing".magenta} %t <%B>", title: title)
22
+ progress_bar = ProgressBar.create(starting_at: nil, total: nil, format: "#{"Preprocessing".magenta} %t <%B>", title: title, throttle_rate: 1)
23
23
  processor.logger = Logger.new(ProgressBarLogger.new(progress_bar))
24
24
  processor.deserialize do |status, result, meta|
25
25
  eta = meta ? meta[:eta] : nil
@@ -47,8 +47,10 @@ module Rseed
47
47
  end
48
48
 
49
49
  def from_file file, options = {}
50
- f = import_file(file)
51
- return false unless f
50
+ unless f = import_file(file)
51
+ logger.error "Cannot locate file: ".red + file.to_s
52
+ return false
53
+ end
52
54
  p = Processor.new(options)
53
55
  return nil unless p
54
56
  p.adapter.file = f
@@ -20,7 +20,7 @@ module Rseed
20
20
  converter_options[s[0].strip] = s[1].strip
21
21
  end
22
22
  end
23
- converter.options = converter_options
23
+ converter.options = HashWithIndifferentAccess.new(converter_options)
24
24
  end
25
25
  @adapter = adapter
26
26
  @converter = converter
@@ -72,7 +72,7 @@ module Rseed
72
72
  unless result[:success]
73
73
  logger.error result[:message].to_s.red
74
74
  logger.error result[:error].to_s.red
75
- logger.error result[:backtrace].to_s
75
+ logger.error result[:backtrace].to_s unless result[:backtrace].to_s.blank?
76
76
  end
77
77
  yield :processing, result, meta
78
78
  end
data/lib/rseed/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rseed
2
- VERSION = "1.0.4"
2
+ VERSION = "1.0.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rseed
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Monagle
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-10 00:00:00.000000000 Z
11
+ date: 2013-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize