takenoko 0.2.5 → 0.2.6

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: f220dcc9791b09c92522d4e1d39e5bd4310761d5
4
- data.tar.gz: 77ba082e4d9f2f4a5a5f3ee5485e272b033e4068
3
+ metadata.gz: f9585a154baef8437a43f497bc18de665f1824fc
4
+ data.tar.gz: 8dab39802e20d59c6e97177d6916bb21af10a58a
5
5
  SHA512:
6
- metadata.gz: 88cee4436b2d04ecb36c4773d165a76b998ff6af1a7081446d632472cdc62228eb9fd1c9fc26dd0277b95f6a0cc237a911f0cd3ac4962fa6fd3afe6cd6507c95
7
- data.tar.gz: bc883341f1d73fe9e6336d8d984060a2cccb64b240094bf5f1055cb6c7657852a73ab435c4ab4d8d776352cac5311934b9d69816cc59402976e7e79a989e23a9
6
+ metadata.gz: 3987057c1ee11165f6e757ddedc808f9764cfb2c3281320406a34a203414048af4e32368f511d94985853300c12666e35ba513841089b50a78aeb88f1cea1c1a
7
+ data.tar.gz: 9cd9bb7943f4a9583229c8e8c8131c9c0917291cfa620c3217bf5b26613a0267749ae60b28519da8f2dbd92b613cc8b844c9da42408408d14c10ec71eb5a4cfd
@@ -6,7 +6,7 @@ module Takenoko
6
6
  table_name = table_data[:table_name]
7
7
  takelog = "#{Takenoko.log_folder}/#{table_name}_log.yml"
8
8
  log_data = (File.exist?(takelog) && YAML.load_file(takelog)) || {}
9
-
9
+ folders = {}
10
10
  table_data[:attach_files].each do |col|
11
11
  unless (folder_id = col[:folder_id] || table[:folder_id]).present?
12
12
  errors << "Folder ID should be set"
@@ -22,28 +22,44 @@ module Takenoko
22
22
  Rails.logger.info "Downloading file form table #{table_name}"
23
23
  download_location = col[:download_location]
24
24
  FileUtils.mkdir_p(download_location) unless File.directory?(download_location)
25
- folder = Takenoko.google_client.folder_by_id col[:folder_id]
25
+
26
+ unless ls_files = folders[col[:folder_id]]
27
+ ls_files = folders[col[:folder_id]] = get_drive_files_list Takenoko.google_client.folder_by_id col[:folder_id]
28
+ end
26
29
 
27
30
  table_data[:rows].each do |row|
28
31
  next if row[column_name].blank?
29
32
  file_name = File.basename(row[column_name])
30
- unless file = folder.file_by_title(file_name)
33
+ unless file = ls_files[file_name]
31
34
  errors << "Table[#{table_name}] - File: '#{file_name}' not found"
32
35
  next
33
36
  end
34
37
  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]
38
+ log_key = "#{col[:folder_id]}_#{file_name}"
39
+ next if File.exist?(full_path_name) && log_data[log_key].present? && file.modified_date.to_i <= log_data[log_key][:last_modified]
37
40
 
38
41
  file.download_to_file(full_path_name)
39
42
  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
43
+ log_data[log_key] ||= {}
44
+ log_data[log_key][:last_modified] = file.modified_date.to_i
42
45
  end
43
46
  end
44
47
  File.open(takelog, 'w') {|f| f.write log_data.to_yaml }
45
48
  raise errors.join("\n") unless errors.empty?
46
49
  return true
47
50
  end
51
+
52
+ #Get all file from drive folder
53
+ def get_drive_files_list(folder)
54
+ ls = Hash.new
55
+ page_token = nil
56
+ begin
57
+ (files, page_token) = folder.files("pageToken" => page_token)
58
+ files.each do |f|
59
+ ls[f.original_filename] = f
60
+ end
61
+ end while page_token
62
+ return ls
63
+ end
48
64
  end
49
65
  end
@@ -1,3 +1,3 @@
1
1
  module Takenoko
2
- VERSION = "0.2.5"
2
+ VERSION = "0.2.6"
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.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - KhiemNS
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-18 00:00:00.000000000 Z
11
+ date: 2016-10-25 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.5
92
+ homepage: https://github.com/khiemns54/takenoko/tree/release/0.2.6
93
93
  licenses: []
94
94
  metadata: {}
95
95
  post_install_message: