beam 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/README.md +17 -1
- data/beam.gemspec +1 -1
- data/config/initializers/beam.rb +8 -0
- data/lib/beam/upload.rb +44 -11
- data/lib/beam/version.rb +1 -1
- data/lib/generators/beam/install_generator.rb +14 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 58e6c2bf43f67b5f0f1b96c2220babda0120320d
|
4
|
+
data.tar.gz: 8fe1ccd8320c5b03875c9e8ea7de2f2315b9d824
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 373dc353a9f0f00002a4c4a1df2fde2d3aba08adbc8fc78f0b178618297d9afda5ade0bc7f1800f277d8eb6acc1b919dce7290013a73ffd8b524239d5d0306bc
|
7
|
+
data.tar.gz: f3efa60222fd1d9686aeb3fd0f8fe00ad06389c063faf3fc6f7791af3d02e6fe32c83f4024b8fac5464a7f8e39fe4a4f2dbe19b2caf864d596d2eab620b21594
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Beam
|
2
2
|
|
3
|
-
A rubygem to simplifiy repetitive csv upload process for ActiveRecord models.
|
3
|
+
A rubygem to simplifiy repetitive csv upload process for ActiveRecord models in rails applications.
|
4
4
|
Supports bulk upload with [activerecord-import](http://rubygems.org/gems/activerecord-import)
|
5
5
|
|
6
6
|
## Usage
|
@@ -9,6 +9,18 @@ Supports bulk upload with [activerecord-import](http://rubygems.org/gems/activer
|
|
9
9
|
```ruby
|
10
10
|
gem 'beam'
|
11
11
|
```
|
12
|
+
|
13
|
+
Run the generator
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
rails g beam:install
|
17
|
+
```
|
18
|
+
|
19
|
+
This will create a config file for you to over-ride default options of upload process.
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
create config/initializers/beam.rb
|
23
|
+
```
|
12
24
|
|
13
25
|
Add [activerecord-import gem](http://rubygems.org/gems/activerecord-import) to the application's Gemfile:
|
14
26
|
|
@@ -49,6 +61,10 @@ Supports bulk upload with [activerecord-import](http://rubygems.org/gems/activer
|
|
49
61
|
|
50
62
|
See beam/upload.rb for more details
|
51
63
|
|
64
|
+
## TO DO
|
65
|
+
|
66
|
+
SPECS!
|
67
|
+
|
52
68
|
## Contributing
|
53
69
|
|
54
70
|
1. Fork it
|
data/beam.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["gouravtiwari21@gmail.com"]
|
11
11
|
spec.homepage = "https://github.com/gouravtiwari/beam"
|
12
12
|
spec.summary = "CSV uploader library for fast and easy upload"
|
13
|
-
spec.description = "CSV uploader library for fast and easy upload"
|
13
|
+
spec.description = "CSV uploader library for fast and easy upload for Rails applications"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
data/lib/beam/upload.rb
CHANGED
@@ -1,27 +1,55 @@
|
|
1
1
|
require 'csv'
|
2
|
+
|
2
3
|
module Beam
|
4
|
+
# error_file_needed:true if you need error file to be created, default is true
|
5
|
+
# batch_process: default is true, set to false if you do not use activerecord-import
|
6
|
+
# for batch processing
|
7
|
+
# batch_size: default is 1_000, change it to batch of records you want to upload
|
8
|
+
# zipped: set it to true if uploaded file is zipped
|
9
|
+
@config = {
|
10
|
+
error_file_needed: true,
|
11
|
+
batch_process: true,
|
12
|
+
batch_size: 1_000,
|
13
|
+
zipped: true
|
14
|
+
}
|
15
|
+
|
16
|
+
@valid_config_keys = @config.keys
|
17
|
+
|
18
|
+
# Configure through hash
|
19
|
+
def self.configure(opts = {})
|
20
|
+
opts.each {|k,v| @config[k.to_sym] = v if @valid_config_keys.include? k.to_sym}
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.config
|
24
|
+
configure(@config)
|
25
|
+
end
|
26
|
+
|
3
27
|
module Upload
|
28
|
+
def upload_config
|
29
|
+
@error_file_needed = Beam.config[:error_file_needed]
|
30
|
+
@batch_process = Beam.config[:batch_process]
|
31
|
+
@batch_size = Beam.config[:batch_size]
|
32
|
+
@zipped = Beam.config[:zipped]
|
33
|
+
end
|
34
|
+
|
4
35
|
# params:
|
5
36
|
# file_name: zip file name, e.g. users.csv.zip
|
6
37
|
# file_path: path/to/zip-file, e.g. Rails.root/tmp
|
7
|
-
# error_file_needed:true if you need error file to be created, default is true
|
8
38
|
# callback_method: method which does the job to load records, default is parse method
|
9
|
-
|
10
|
-
# for batch processing
|
11
|
-
def upload_file(file_name, file_path, error_file_needed=true, callback_method = "parse", batch_process=true)
|
39
|
+
def upload_file(file_name, file_path, callback_method='parse')
|
12
40
|
status = {}
|
41
|
+
upload_config
|
13
42
|
@file_name = file_name
|
14
|
-
@file_path = file_path
|
15
|
-
@error_file_needed = error_file_needed
|
43
|
+
@file_path = file_path
|
16
44
|
@original_zip_file = "#{@file_path}/#{@file_name}"
|
17
45
|
@csv_file_name = @file_name.gsub(/\.zip/,'')
|
18
|
-
@batch_process = batch_process
|
19
|
-
@batch_size = 1_1000
|
20
46
|
|
21
47
|
begin
|
22
|
-
|
23
|
-
|
24
|
-
|
48
|
+
if @zipped
|
49
|
+
delete_csv_if_present
|
50
|
+
unzip_file
|
51
|
+
end
|
52
|
+
|
25
53
|
status = self.send(callback_method)
|
26
54
|
rescue Exception => e
|
27
55
|
error_in_upload([[invalid_file_message]]) if @error_file_needed
|
@@ -31,6 +59,11 @@ module Beam
|
|
31
59
|
status
|
32
60
|
end
|
33
61
|
|
62
|
+
# unzips a zipped-csv-file in a given directory
|
63
|
+
def unzip_file
|
64
|
+
`unzip #{@file_path}/#{@file_name} -d #{@file_path}`
|
65
|
+
end
|
66
|
+
|
34
67
|
# deletes csv file upfront before we unzip the file
|
35
68
|
def delete_csv_if_present
|
36
69
|
File.delete "#{@file_path}/#{@csv_file_name}" if File.exists? "#{@file_path}/#{@csv_file_name}"
|
data/lib/beam/version.rb
CHANGED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rails'
|
2
|
+
|
3
|
+
module Beam
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < ::Rails::Generators::Base
|
6
|
+
source_root File.expand_path('../../../../config/initializers', __FILE__)
|
7
|
+
|
8
|
+
desc "This generator adds beam.rb to initializers with default config"
|
9
|
+
def copy_beam_config
|
10
|
+
copy_file "beam.rb", "config/initializers/beam.rb"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: beam
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gourav Tiwari
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,7 +38,7 @@ dependencies:
|
|
38
38
|
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
description: CSV uploader library for fast and easy upload
|
41
|
+
description: CSV uploader library for fast and easy upload for Rails applications
|
42
42
|
email:
|
43
43
|
- gouravtiwari21@gmail.com
|
44
44
|
executables: []
|
@@ -52,10 +52,12 @@ files:
|
|
52
52
|
- README.md
|
53
53
|
- Rakefile
|
54
54
|
- beam.gemspec
|
55
|
+
- config/initializers/beam.rb
|
55
56
|
- lib/beam.rb
|
56
57
|
- lib/beam/extensions/exception.rb
|
57
58
|
- lib/beam/upload.rb
|
58
59
|
- lib/beam/version.rb
|
60
|
+
- lib/generators/beam/install_generator.rb
|
59
61
|
homepage: https://github.com/gouravtiwari/beam
|
60
62
|
licenses:
|
61
63
|
- MIT
|