importeer_plan 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +53 -0
- data/changelog.md +6 -0
- data/lib/importeer_plan.rb +15 -6
- data/lib/importeer_plan/configuration.rb +26 -0
- data/lib/importeer_plan/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 660fcbef0c424ea7fff40b2882b5004406bbe82d
|
4
|
+
data.tar.gz: 4c496274282bc4f4ffea7dbc652c0247ed5cdc3d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ffda67687aee4813755ac9887b70e7391052f3402f250e3e28c4252c286b8feeb14d91104f9c7cb5ba0ff882ea88ad6b1bcde2d25339df3ebe8ed2b99264ff5
|
7
|
+
data.tar.gz: 0c51a97d9105d4998884645500e5f8fa484b4a95e66332d36b6d0cb0512327e2516e048a86d30b4dcb8ba933c17dac5d721cc63b8c91c9eec8e011436927c64f
|
data/README.md
CHANGED
@@ -52,6 +52,59 @@ class ImporteerSomething < ImporteerPlan::MyXls
|
|
52
52
|
end
|
53
53
|
```
|
54
54
|
|
55
|
+
#### a very,very simple example: processing a file called 'example.xls'
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
|
59
|
+
e = ImporteerPlan::MyXls.new('example.xls')
|
60
|
+
|
61
|
+
e.importeer
|
62
|
+
|
63
|
+
```
|
64
|
+
|
65
|
+
this works, after you created a file like this:
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
#save this file as: importeer_example.rb
|
69
|
+
|
70
|
+
class ImporteerExample < ImporteerPlan::MyXls
|
71
|
+
|
72
|
+
def importeer_batch(batch)
|
73
|
+
batch.each do |row|
|
74
|
+
handle_my_model row
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
def handle_my_model ref
|
80
|
+
r=MyModel.new
|
81
|
+
r.attribute_one = ref[0] unless ref[0].blank?
|
82
|
+
r.another_attribute = ref[1] unless ref[1].blank?
|
83
|
+
|
84
|
+
r.save! if r.attributes.values.any? {|x| !x.blank?}
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
```
|
92
|
+
|
93
|
+
|
94
|
+
### configuration
|
95
|
+
|
96
|
+
Starting 0.3.0, i added some configuration-options. The most basic configuration is setting the path to find the files to import. The default is creating a folder in the 'public' folder, but you could so something like:
|
97
|
+
|
98
|
+
```ruby
|
99
|
+
|
100
|
+
ImporteerPlan.configure do |config|
|
101
|
+
config.dir = Rails.root.join('imports')
|
102
|
+
end
|
103
|
+
```
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
|
55
108
|
|
56
109
|
### methods
|
57
110
|
|
data/changelog.md
CHANGED
data/lib/importeer_plan.rb
CHANGED
@@ -1,30 +1,39 @@
|
|
1
1
|
require "importeer_plan/version"
|
2
|
+
require 'importeer_plan/configuration'
|
2
3
|
|
3
4
|
module ImporteerPlan
|
4
5
|
class Importeer
|
5
6
|
|
6
7
|
|
7
|
-
attr_accessor :path, :name, :dir, :size_batch, :sep, :initial
|
8
|
+
attr_accessor :path, :name, :dir, :size_batch, :sep, :initial, :options
|
8
9
|
#call importeer("filename") to import the file in batches of 1000, optional importeer("filename", size_)
|
9
10
|
|
10
11
|
|
11
12
|
|
12
|
-
def initialize(name, options
|
13
|
+
def initialize(name, options={})
|
14
|
+
@options = options
|
13
15
|
@name = name
|
14
16
|
@path = Importeer.dir.join( @name )
|
15
|
-
@size_batch = options[:size_batch]
|
16
|
-
@sep = options[:sep]
|
17
|
-
@initial = options[:initial]
|
17
|
+
@size_batch = options[:size_batch]||1000
|
18
|
+
@sep = options[:sep]|| ";"
|
19
|
+
@initial = options[:initial]|| false
|
18
20
|
end
|
19
21
|
|
20
22
|
def self.dir
|
21
|
-
Rails.root.join('public/imports/')
|
23
|
+
# Rails.root.join('public/imports/')
|
24
|
+
|
25
|
+
ImporteerPlan.configuration.dir
|
26
|
+
|
22
27
|
end
|
23
28
|
|
24
29
|
def bron
|
25
30
|
end
|
26
31
|
|
32
|
+
def sweep
|
33
|
+
end
|
34
|
+
|
27
35
|
def importeer
|
36
|
+
sweep
|
28
37
|
bron.each{|batch| importeer_batch batch}
|
29
38
|
end
|
30
39
|
|
@@ -0,0 +1,26 @@
|
|
1
|
+
#more on configuration on http://juanitofatas.com/2015/05/19/rubygem-configuration-pattern/
|
2
|
+
|
3
|
+
module ImporteerPlan
|
4
|
+
def self.configuration
|
5
|
+
@configuration ||= Configuration.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.configuration=(configuration)
|
9
|
+
@configuration = configuration
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.configure
|
13
|
+
yield configuration
|
14
|
+
end
|
15
|
+
|
16
|
+
class Configuration
|
17
|
+
attr_accessor :dir
|
18
|
+
|
19
|
+
def initialize
|
20
|
+
|
21
|
+
@dir = Rails.root.join('public/imports/')
|
22
|
+
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: importeer_plan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- rolf
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: spreadsheet
|
@@ -139,6 +139,7 @@ files:
|
|
139
139
|
- changelog.md
|
140
140
|
- importeer_plan.gemspec
|
141
141
|
- lib/importeer_plan.rb
|
142
|
+
- lib/importeer_plan/configuration.rb
|
142
143
|
- lib/importeer_plan/version.rb
|
143
144
|
homepage: http://www.l-plan.nl
|
144
145
|
licenses:
|
@@ -166,3 +167,4 @@ specification_version: 4
|
|
166
167
|
summary: only purpose is provide some reusable defaults for processing my (.xls-,
|
167
168
|
.csv-, .txt)files
|
168
169
|
test_files: []
|
170
|
+
has_rdoc:
|