csv_import_magic 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2ae480281a547b7efbd60c64d4b1e0e0e825bd37
4
- data.tar.gz: a3536a24a78375f15846e17ebf5686363c515a60
3
+ metadata.gz: 91e56866df8de25c3b9bda2ccbaa09e60dc4b101
4
+ data.tar.gz: dde09d1e79b7073f4f7edfff4fc1477200c0d580
5
5
  SHA512:
6
- metadata.gz: 30ed14a1f60c59fc07a17edfd39a959fc3605913eb38dbcea63687a8adf7cb674a5f80f82039237b062dfa42a95fb9a82d47556d236002a8257ff2c3cd13f21f
7
- data.tar.gz: b4cdabaf4481a3f18199f8eb9eec4b530f9ac7c534237c68193ef361253275e2dee76ea22e84df4ec621b6cc55bd4f5baf7a56a65a4398eb719baac087f3cacc
6
+ metadata.gz: 0476a7842f3867cbd9af27f4477747465ce2b515f9a44a56e7ce98382b1dd851c543488143ee45dc88d4e5c77f64ddc6cdba4f431c3b4c8e6fba8d2b5488f7d2
7
+ data.tar.gz: 883ce8c45cd32013ef1d6af10dec64030a675ba3925834cf2134d3504630d08a5ca10e24b9aac2c71c5050d056cdea5b32dc5b81214d9d9da0f67a9c9e0c4394
@@ -4,6 +4,7 @@ class Importer < ActiveRecord::Base
4
4
  STATUS = %w(pending success error).freeze
5
5
 
6
6
  serialize :columns, Array
7
+ serialize :additional_data, JSON
7
8
 
8
9
  has_attached_file :attachment
9
10
  has_attached_file :attachment_error
@@ -30,9 +30,17 @@ module CsvImportMagic
30
30
 
31
31
  def csv_parsed
32
32
  model = @model
33
+ importer = @importer
33
34
 
34
35
  @csv_parsed ||= csv_parser_class.new(content: content_with_new_header) do
35
36
  model model
37
+
38
+ after_build do |model|
39
+ if importer.additional_data
40
+ additional_data = JSON.parse(importer.additional_data)
41
+ model.assign_attributes(additional_data) rescue nil
42
+ end
43
+ end
36
44
  end
37
45
  end
38
46
 
@@ -0,0 +1,5 @@
1
+ class AddsAdditionalDataToImporters < ActiveRecord::Migration
2
+ def change
3
+ add_column :importers, :additional_data, :string
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ class AddsAdditionalAttributesToCompany < ActiveRecord::Migration
2
+ def change
3
+ add_column :companies, :one_additional_attribute, :string
4
+ add_column :companies, :other_additional_attribute, :string
5
+ end
6
+ end
@@ -1,3 +1,3 @@
1
1
  module CsvImportMagic
2
- VERSION = '0.0.1'.freeze
2
+ VERSION = '0.0.2'.freeze
3
3
  end
@@ -42,6 +42,7 @@ module CsvImportMagic
42
42
  t.string :columns
43
43
  t.string :message
44
44
  t.string :status, default: 'pending'
45
+ t.string :additional_data
45
46
  t.references :importable, polymorphic: true
46
47
  RUBY
47
48
  end
@@ -11,41 +11,46 @@
11
11
  #
12
12
  # It's strongly recommended that you check this file into your version control system.
13
13
 
14
- ActiveRecord::Schema.define(version: 20_170_112_125_734) do
15
- create_table 'companies', force: :cascade do |t|
16
- t.integer 'user_id'
17
- t.string 'name'
18
- t.string 'street'
19
- t.string 'number'
20
- t.string 'neighborhood'
21
- t.string 'city'
22
- t.string 'state'
23
- t.string 'country'
24
- t.boolean 'active'
14
+ ActiveRecord::Schema.define(version: 20170505100034) do
15
+
16
+ create_table "companies", force: :cascade do |t|
17
+ t.integer "user_id"
18
+ t.string "name"
19
+ t.string "street"
20
+ t.string "number"
21
+ t.string "neighborhood"
22
+ t.string "city"
23
+ t.string "state"
24
+ t.string "country"
25
+ t.boolean "active"
26
+ t.string "one_additional_attribute"
27
+ t.string "other_additional_attribute"
25
28
  end
26
29
 
27
- create_table 'importers', force: :cascade do |t|
28
- t.string 'attachment_file_name'
29
- t.string 'attachment_content_type'
30
- t.integer 'attachment_file_size'
31
- t.datetime 'attachment_updated_at'
32
- t.string 'attachment_error_file_name'
33
- t.string 'attachment_error_content_type'
34
- t.integer 'attachment_error_file_size'
35
- t.datetime 'attachment_error_updated_at'
36
- t.string 'source'
37
- t.string 'parser'
38
- t.string 'columns'
39
- t.string 'message'
40
- t.string 'status', default: 'pending'
41
- t.integer 'importable_id'
42
- t.string 'importable_type'
43
- t.datetime 'created_at'
44
- t.datetime 'updated_at'
30
+ create_table "importers", force: :cascade do |t|
31
+ t.string "attachment_file_name"
32
+ t.string "attachment_content_type"
33
+ t.integer "attachment_file_size"
34
+ t.datetime "attachment_updated_at"
35
+ t.string "attachment_error_file_name"
36
+ t.string "attachment_error_content_type"
37
+ t.integer "attachment_error_file_size"
38
+ t.datetime "attachment_error_updated_at"
39
+ t.string "source"
40
+ t.string "parser"
41
+ t.string "columns"
42
+ t.string "message"
43
+ t.string "status", default: "pending"
44
+ t.integer "importable_id"
45
+ t.string "importable_type"
46
+ t.datetime "created_at"
47
+ t.datetime "updated_at"
48
+ t.string "additional_data"
45
49
  end
46
50
 
47
- create_table 'users', force: :cascade do |t|
48
- t.string 'name'
49
- t.string 'email'
51
+ create_table "users", force: :cascade do |t|
52
+ t.string "name"
53
+ t.string "email"
50
54
  end
55
+
51
56
  end
Binary file