better_record 0.14.2 → 0.14.3

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
  SHA256:
3
- metadata.gz: 10693339476d84da7e105549ee3479725c69bc9dd3960bfbfafd7f3f94716387
4
- data.tar.gz: da86ab0688c1204e84814744dcf29e4aad44a825de7341286b406cdd11b6c006
3
+ metadata.gz: 7a2ed3d62e84a39ecb61ad3477e689758e95b22a369ffcc79d6fbcae6499b455
4
+ data.tar.gz: bcaa6746d5cda1499bc80fb45c72ad20c3c1023711f8e784a719768425ae1340
5
5
  SHA512:
6
- metadata.gz: a8c4bc986a04d078db1a5caae062dce3493ac4346140c6f63e4dc1e12052efefe16ed4140f1bcc05bc5a9eecece16580861e0f9a6348d302ef34852036fd835b
7
- data.tar.gz: a651c863574c81a8b85412bd6f0dfe2e50ddcbaa5ab1fd31a94c129a627d4ce38516a0ac97d3475839f5ed97915dd0a676cbb1e80b90628056d1230ea83ce73b
6
+ metadata.gz: a66740d53fbec76869ab77a58764244a80e5f84742a2bf1ac9a5f960cf41120877e1579b5e799217a338545be42160db7d533d872f6feef3d532f662d53a4a0f
7
+ data.tar.gz: 539875e24030c254395ac8e1b50f3f4951017677eed9a5b6e8ed34eeedc817d89a2db2520d4301a5f1f62c075178bd51a333edee1a5574db25ec49832648b16c
@@ -1,68 +1,70 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Uploadable
4
- extend ActiveSupport::Concern
3
+ module BetterRecord
4
+ module Uploadable
5
+ extend ActiveSupport::Concern
5
6
 
6
- def whitelisted_upload_params
7
- params.require(:upload).permit(:file, :staff_id)
8
- end
7
+ def whitelisted_upload_params
8
+ params.require(:upload).permit(:file, :staff_id)
9
+ end
9
10
 
10
- def csv_upload(job, whitelisted_params, upload_key, prefix, job_sym = :staff_id, redirecting = false)
11
- p whitelisted_params
12
- uploaded = whitelisted_params[upload_key]
13
- job_id = whitelisted_params[job_sym]
14
- @file_stats = {
15
- name: uploaded.original_filename,
16
- "mime-type" => uploaded.content_type,
17
- size: view_context.number_to_human_size(uploaded.size)
18
- }
19
- if verify_file(whitelisted_params, upload_key)
20
- File.open(Rails.root.join('public', 'import_csv', "#{prefix}_#{Time.now.to_i}#{rand(1000..100000)}.csv"), 'wb') do |file|
21
- uploaded = BetterRecord::Encoder.new(uploaded.read).to_utf8
22
- file.write(uploaded)
23
- job.perform_later file.path, job_id, @file_stats[:name]
24
- end
25
- if redirecting
26
- flash[:success] ||= []
27
- flash[:success] << 'File Uploaded'
11
+ def csv_upload(job, whitelisted_params, upload_key, prefix, job_sym = :staff_id, redirecting = false)
12
+ p whitelisted_params
13
+ uploaded = whitelisted_params[upload_key]
14
+ job_id = whitelisted_params[job_sym]
15
+ @file_stats = {
16
+ name: uploaded.original_filename,
17
+ "mime-type" => uploaded.content_type,
18
+ size: view_context.number_to_human_size(uploaded.size)
19
+ }
20
+ if verify_file(whitelisted_params, upload_key)
21
+ File.open(Rails.root.join('public', 'import_csv', "#{prefix}_#{Time.now.to_i}#{rand(1000..100000)}.csv"), 'wb') do |file|
22
+ uploaded = BetterRecord::Encoder.new(uploaded.read).to_utf8
23
+ file.write(uploaded)
24
+ job.perform_later file.path, job_id, @file_stats[:name]
25
+ end
26
+ if redirecting
27
+ flash[:success] ||= []
28
+ flash[:success] << 'File Uploaded'
29
+ else
30
+ flash.now[:success] ||= []
31
+ flash.now[:success] << 'File Uploaded'
32
+ end
33
+ return true
28
34
  else
29
- flash.now[:success] ||= []
30
- flash.now[:success] << 'File Uploaded'
31
- end
32
- return true
33
- else
34
- msg = [
35
- 'something went wrong',
36
- 'Only csv files with the correct headers are supported',
37
- "content type: #{whitelisted_params[upload_key].content_type}", "file name: #{whitelisted_params[upload_key].original_filename}"
38
- ]
35
+ msg = [
36
+ 'something went wrong',
37
+ 'Only csv files with the correct headers are supported',
38
+ "content type: #{whitelisted_params[upload_key].content_type}", "file name: #{whitelisted_params[upload_key].original_filename}"
39
+ ]
39
40
 
40
- if redirecting
41
- flash[:danger] = msg
42
- else
43
- flash.now[:danger] = msg
41
+ if redirecting
42
+ flash[:danger] = msg
43
+ else
44
+ flash.now[:danger] = msg
44
45
 
45
- render :show
46
+ render :show
47
+ end
46
48
  end
47
49
  end
48
- end
49
50
 
50
- private
51
- def verify_file(whitelisted_params, upload_key)
52
- correct_mime_type(whitelisted_params, upload_key) && /\.csv/ =~ whitelisted_params[upload_key].original_filename
53
- end
51
+ private
52
+ def verify_file(whitelisted_params, upload_key)
53
+ correct_mime_type(whitelisted_params, upload_key) && /\.csv/ =~ whitelisted_params[upload_key].original_filename
54
+ end
54
55
 
55
- def correct_mime_type(whitelisted_params, upload_key)
56
- [
57
- "text/csv",
58
- "text/plain",
59
- "application/vnd.ms-excel",
60
- "text/x-csv",
61
- "application/csv",
62
- "application/x-csv",
63
- "text/csv",
64
- "text/comma-separated-values",
65
- "text/x-comma-separated-values"
66
- ].any? {|mime| mime == whitelisted_params[upload_key].content_type}
67
- end
56
+ def correct_mime_type(whitelisted_params, upload_key)
57
+ [
58
+ "text/csv",
59
+ "text/plain",
60
+ "application/vnd.ms-excel",
61
+ "text/x-csv",
62
+ "application/csv",
63
+ "application/x-csv",
64
+ "text/csv",
65
+ "text/comma-separated-values",
66
+ "text/x-comma-separated-values"
67
+ ].any? {|mime| mime == whitelisted_params[upload_key].content_type}
68
+ end
69
+ end
68
70
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BetterRecord
4
- VERSION = '0.14.2'
4
+ VERSION = '0.14.3'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: better_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.2
4
+ version: 0.14.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sampson Crowley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-08 00:00:00.000000000 Z
11
+ date: 2018-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails