takenoko 0.3.0 → 0.4.0

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: 0800fcd0030d1d6957b0e985dd35ed047a7a3eb2
4
- data.tar.gz: be5fdcf97505ea59d88a591ae776bea20265a20e
3
+ metadata.gz: 64c9a9a89b8e04024d094e39f9cbe6eb346ebc90
4
+ data.tar.gz: 75f9c6bc1993085a69b370166220eb390a0b8219
5
5
  SHA512:
6
- metadata.gz: 9f7a9f0caf702576ab6e523f9574c507c96bef46a4b82903c98ab79c44368563175acbb85d8274d85c05ee1c375f70da8c102b5e31fa8638260c947afc8110c6
7
- data.tar.gz: 8155b61ff44308363c2a93de03e38dfe23720bbabba1086c4cda5c204b1857e9dc81fd4f3d16a9c766cff7a7cfc0da38602f724ffaeff4a13b2373beefb2093b
6
+ metadata.gz: 8cf9383df5364e09eee896205d7bd701429e80e1c3ba1a602771eef471591f0dd690cc2982e6322968b24a1312ceacd2ca9c38e2376339edc056af5f135868f2
7
+ data.tar.gz: 155b37748457641958da7333bdc457bf1541c128e76a06f38c451a86a60a9c893a4d61e3d52a3c28c6ac8584ef80666647c5e04e20fc896f13df2f46fa18d8c2
@@ -15,15 +15,12 @@ Takenoko.config do |conf|
15
15
  # Export file format, default :csv, support: csv,yaml,json
16
16
  # conf.file_extension = :csv
17
17
 
18
- # Truncate all data before saving, default: false
19
- # conf.truncate_all_data = false
18
+ # Import strategy, default: truncate_all (overwrite, fill_empty, :insert_only)
19
+ # conf.import_strategy = :truncate_all
20
20
 
21
21
  # Export file location, default: db/spreadsheet
22
22
  # conf.export_file_location = "db/spreadsheet"
23
23
 
24
- # Allow overwrite duplicated row, default: true
25
- # conf.allow_overwrite = true
26
-
27
24
  # Enable post processing after get row from spreadsheet, default false
28
25
  # Define three more method on your post process class to handle it
29
26
  # spreadsheet_row_valid? : skip invalid rows, return bool (Optional)
@@ -43,4 +40,4 @@ Takenoko.config do |conf|
43
40
 
44
41
  # Google drive folder id, where your attached files're stored
45
42
  # conf.folder_id = nil
46
- end
43
+ end
@@ -3,7 +3,7 @@ require 'google_drive'
3
3
  require 'google_drive/google_drive'
4
4
  require 'google_drive/google_drive/session'
5
5
 
6
- module Takenoko
6
+ module Takenoko
7
7
  extend self
8
8
  mattr_accessor :google_cridential_file
9
9
  @@google_cridential_file = nil
@@ -27,11 +27,8 @@ module Takenoko
27
27
  mattr_accessor :export_file_location
28
28
  @@export_file_location = "db/spreadsheet"
29
29
 
30
- mattr_accessor :truncate_all_data
31
- @@truncate_all_data = false
32
-
33
- mattr_accessor :allow_overwrite
34
- @@allow_overwrite = true
30
+ mattr_accessor :import_strategy
31
+ @@import_strategy = :truncate_all # overwrite, fill_empty, :insert_only
35
32
 
36
33
  mattr_accessor :sheet_id
37
34
  @@sheet_id = nil
@@ -102,7 +99,7 @@ module Takenoko
102
99
  end
103
100
  end
104
101
  raise errors.join("\n") unless errors.empty?
105
-
102
+
106
103
  return true
107
104
  end
108
105
 
@@ -126,4 +123,4 @@ module Takenoko
126
123
  load "tasks/takenoko.rake"
127
124
  end
128
125
  end
129
- end
126
+ end
@@ -5,11 +5,23 @@ module Takenoko
5
5
  extend self
6
6
  def table_to_db(table)
7
7
  tb_class = Object.const_get("::"+table[:class_name])
8
+ import_strategy = table[:import_strategy]
8
9
  raise "Class not found:#{table[:class_name]}" unless tb_class <= ActiveRecord::Base
9
- tb_class.destroy_all if table[:truncate_all_data]
10
+ tb_class.destroy_all if import_strategy == :truncate_all
10
11
  table[:rows].each do |r|
11
12
  if db_r = tb_class.find_by(table[:find_column] => r[table[:find_column]])
12
- db_r.update(r) if table[:allow_overwrite]
13
+ case import_strategy
14
+ when :overwrite
15
+ db_r.update(r)
16
+ when :fill_empty
17
+ tmp_r = r.clone
18
+ tmp_r.delete_if do |k,v|
19
+ v.blank? || db_r.send(k).present?
20
+ end
21
+ db_r.update(tmp_r)
22
+ when :insert_only
23
+ next
24
+ end
13
25
  else
14
26
  tb_class.new(r).save!
15
27
  end
@@ -5,8 +5,7 @@ module Takenoko
5
5
 
6
6
  mattr_accessor :allowed_overwrite_fields
7
7
  @@allowed_overwrite_fields = [
8
- :allow_overwrite,
9
- :truncate_all_data,
8
+ :import_strategy,
10
9
  :file_extension,
11
10
  :export_file_location,
12
11
  :enable_postprocess,
@@ -42,6 +41,10 @@ module Takenoko
42
41
  end
43
42
  }],
44
43
 
44
+ [:import_strategy, ->(name, table){
45
+ table[:import_strategy] = table[:import_strategy].to_sym
46
+ }],
47
+
45
48
  [:set_postprocess_class, ->(name, table){
46
49
  table[:postprocess_class] ||= table[:class_name]
47
50
  }],
@@ -1,3 +1,3 @@
1
1
  module Takenoko
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: takenoko
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - KhiemNS
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-28 00:00:00.000000000 Z
11
+ date: 2018-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -89,7 +89,7 @@ files:
89
89
  - lib/tasks/takenoko.rake
90
90
  - test/takenoko_test.rb
91
91
  - test/test_helper.rb
92
- homepage: https://github.com/khiemns54/takenoko/tree/release/0.3.0
92
+ homepage: https://github.com/khiemns54/takenoko
93
93
  licenses: []
94
94
  metadata: {}
95
95
  post_install_message: