takenoko 0.2.4 → 0.2.5

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: 39ca231501ec0feba93d7146fc736cbd4f907635
4
- data.tar.gz: 504e85423e7f106b30a319031af27dbb74a3dadb
3
+ metadata.gz: f220dcc9791b09c92522d4e1d39e5bd4310761d5
4
+ data.tar.gz: 77ba082e4d9f2f4a5a5f3ee5485e272b033e4068
5
5
  SHA512:
6
- metadata.gz: 9e5a4736e99b58b0c715768aba5e0f08e7478d6cf86b23173457496a54a0d90aa0461ca5384a055599fa890a9ded8ad71963e406c4ace05232c3c48f3c06f049
7
- data.tar.gz: 55538bd7f9260ce5da22304b3cca49721db312d677f93fdb688f30acf59a95647021724b2e061cae60cbf3e0aad4bd4cf19200ce922d25a8fe3359702da32ebf
6
+ metadata.gz: 88cee4436b2d04ecb36c4773d165a76b998ff6af1a7081446d632472cdc62228eb9fd1c9fc26dd0277b95f6a0cc237a911f0cd3ac4962fa6fd3afe6cd6507c95
7
+ data.tar.gz: bc883341f1d73fe9e6336d8d984060a2cccb64b240094bf5f1055cb6c7657852a73ab435c4ab4d8d776352cac5311934b9d69816cc59402976e7e79a989e23a9
@@ -2,11 +2,24 @@ module Takenoko
2
2
  module AttachHelper
3
3
  extend self
4
4
  def download(table_data)
5
+ errors = []
6
+ table_name = table_data[:table_name]
7
+ takelog = "#{Takenoko.log_folder}/#{table_name}_log.yml"
8
+ log_data = (File.exist?(takelog) && YAML.load_file(takelog)) || {}
9
+
5
10
  table_data[:attach_files].each do |col|
6
- raise "Folder ID should be set" unless (folder_id = col[:folder_id] || table[:folder_id]).present?
11
+ unless (folder_id = col[:folder_id] || table[:folder_id]).present?
12
+ errors << "Folder ID should be set"
13
+ next
14
+ end
15
+
7
16
  column_name = col[:column_name]
8
- raise "Column #{column_name} not found" unless table_data[:header].include?(column_name)
9
- Rails.logger.info "Downloading file form table #{table_data[:table_name]}"
17
+ unless table_data[:header].include?(column_name)
18
+ errors << "Column #{column_name} not found"
19
+ next
20
+ end
21
+
22
+ Rails.logger.info "Downloading file form table #{table_name}"
10
23
  download_location = col[:download_location]
11
24
  FileUtils.mkdir_p(download_location) unless File.directory?(download_location)
12
25
  folder = Takenoko.google_client.folder_by_id col[:folder_id]
@@ -14,12 +27,22 @@ module Takenoko
14
27
  table_data[:rows].each do |row|
15
28
  next if row[column_name].blank?
16
29
  file_name = File.basename(row[column_name])
17
- raise "File: '#{file_name}' not found" unless file = folder.file_by_title(file_name)
30
+ unless file = folder.file_by_title(file_name)
31
+ errors << "Table[#{table_name}] - File: '#{file_name}' not found"
32
+ next
33
+ end
18
34
  full_path_name = download_location+"/"+file_name
35
+ find_col = row[table_data[:find_column]]
36
+ next if File.exist?(full_path_name) && log_data[find_col].present? && file.modified_date.to_i <= log_data[find_col][:last_modified]
37
+
19
38
  file.download_to_file(full_path_name)
20
39
  Rails.logger.info "Downloaded file: #{full_path_name}"
40
+ log_data[find_col] ||= {}
41
+ log_data[find_col][:last_modified] = file.modified_date.to_i
21
42
  end
22
43
  end
44
+ File.open(takelog, 'w') {|f| f.write log_data.to_yaml }
45
+ raise errors.join("\n") unless errors.empty?
23
46
  return true
24
47
  end
25
48
  end
@@ -1,3 +1,3 @@
1
1
  module Takenoko
2
- VERSION = "0.2.4"
2
+ VERSION = "0.2.5"
3
3
  end
data/lib/takenoko.rb CHANGED
@@ -45,6 +45,10 @@ module Takenoko
45
45
  mattr_accessor :download_location
46
46
  @@download_location = "tmp/attach_files"
47
47
 
48
+
49
+ mattr_writer :log_folder
50
+ @@log_folder = "tmp/takenoko"
51
+
48
52
  mattr_accessor :folder_id
49
53
  @@folder_id = nil
50
54
 
@@ -57,6 +61,10 @@ module Takenoko
57
61
  yield self
58
62
  end
59
63
 
64
+ def log_folder
65
+ FileUtils.mkdir_p(@@log_folder) unless File.directory?(@@log_folder)
66
+ @@log_folder
67
+ end
60
68
  def google_client
61
69
  @@google_client ||= GoogleClient.new(google_cridential_file)
62
70
  return @@google_client
@@ -84,10 +92,17 @@ module Takenoko
84
92
  end
85
93
 
86
94
  def download_all_files
95
+ errors = []
87
96
  mapping_config[:tables].each do |table,conf|
88
97
  next if conf[:attach_files].blank?
89
- download_table_files table
98
+ begin
99
+ download_table_files table
100
+ rescue Exception => e
101
+ errors << e.to_s
102
+ end
90
103
  end
104
+ raise errors.join("\n") unless errors.empty?
105
+
91
106
  return true
92
107
  end
93
108
 
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.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - KhiemNS
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-15 00:00:00.000000000 Z
11
+ date: 2016-10-18 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.2.4
92
+ homepage: https://github.com/khiemns54/takenoko/tree/release/0.2.5
93
93
  licenses: []
94
94
  metadata: {}
95
95
  post_install_message: