data_imp 0.3.0 → 0.4.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4c6777102891d246c75858d7cb7b60bc85c880990e6564a81bddc871241ae9d1
4
- data.tar.gz: fc0e1a5a3d6aa1ec738fbd3f8dfb9b51a58185a08f9831e25f359f60c5724a54
3
+ metadata.gz: 5f0439c9288775b796fde25b0df3ca58dea69d5cec9a657ddf7ee3fc6ebc685e
4
+ data.tar.gz: d6b13a0de84abe385cf41e78f3ec4987d89562022737dc41d39e74b9374251d6
5
5
  SHA512:
6
- metadata.gz: 21ef743537443b66646dbf1558f5cbbb22b712c131a1aecd7318282c31a3ecc2ebc8bc5db4d101651678387b757ae6ae699abd6f19fcd3aaaccf3ca646081bcc
7
- data.tar.gz: efa9c8697c30157e4685a465371cae73c24c7d8ea60260bdf50c346559b6161ad4567ac6e64fa08979964ed49ce5163724186e31e3dfc746940d7ed8f6c28d23
6
+ metadata.gz: 2d3e93db677416e1bdb7d865ca7e0a0980d750c15701647c9350f8f292dd6fe1c60bb8e6b2430a30587dc157c8c24a91ee6e0fc85a3f8a211bd7bcb06630c3bc
7
+ data.tar.gz: dd0f6839002332342b3b425b8f237eb28547cf45d3f5017ba2e98182b788de76e9042848356c7c0b35f9c8381ef33a93373783650c2de558e0925694453e0696
@@ -0,0 +1,11 @@
1
+ require_relative "finders"
2
+ require_relative "options"
3
+ require_relative "import"
4
+ class DataImp
5
+ class Base
6
+ include DataImp::Options
7
+ extend DataImp::Finders
8
+ include DataImp::Import
9
+ extend DataImp::Import
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+
2
+ require_relative "base"
3
+ class DataImp
4
+ class File < Base
5
+ end
6
+ end
7
+
@@ -0,0 +1,41 @@
1
+
2
+ class DataImp
3
+ module Import
4
+ def parse(line)
5
+ case line
6
+ when /^(\w+)\.(\w+)$/
7
+ options.merge(line: line, importer: $1, parser: $2)
8
+ else
9
+ options.merge(line: line)
10
+ end
11
+ end
12
+
13
+ def importer opts
14
+ Importer.find(opts[:importer])
15
+ end
16
+
17
+ def parser opts
18
+ Parser.find(opts[:parser]).new(opts)
19
+ end
20
+
21
+ def import line
22
+ line.strip!
23
+ return if line =~ /^#/
24
+ opts = parse(line)
25
+ puts "import(#{line}) => #{opts.inspect}"
26
+ importer(opts).process parser(opts)
27
+ end
28
+
29
+ def import_list list
30
+ list.each_line do |line|
31
+ import line
32
+ end
33
+ end
34
+
35
+ def show_progress index
36
+ end
37
+ end
38
+
39
+ extend Import
40
+ include Import
41
+ end
@@ -4,15 +4,20 @@ require_relative "porter"
4
4
  require_relative "importer"
5
5
 
6
6
  module DataImp::ImportMethods
7
- def import(file=nil, **args, &block)
8
- file.strip!
9
- return if file =~ /^#/
10
- new(file, **args, &block).import
7
+ def import(*files, **options, &block)
8
+ files.each do |file|
9
+ file.strip!
10
+ unless file =~ /^#/
11
+ new(file, **options, &block).import
12
+ end
13
+ end
11
14
  end
12
15
 
13
- def import_list(list, **args, &block)
14
- list.each_line do |file|
15
- import file, **args, &block
16
+ def import_list(*lists, **options, &block)
17
+ lists.each do |list|
18
+ list.each_line do |file|
19
+ import file, **options, &block
20
+ end
16
21
  end
17
22
  end
18
23
  end
@@ -0,0 +1,2 @@
1
+ class DataImp::Importer::Sample < DataImp::Importer
2
+ end
@@ -0,0 +1,34 @@
1
+ class DataImp
2
+ module Options
3
+ def self.included mod
4
+ mod.extend ClassMethods
5
+ end
6
+
7
+ def initialize hash={}
8
+ self.options = hash
9
+ end
10
+
11
+ def options
12
+ @options ||= self.class.options.compact
13
+ end
14
+
15
+ def options= hash
16
+ @options = options.merge(hash)
17
+ end
18
+
19
+ module ClassMethods
20
+ def default_options
21
+ HashWithIndifferentAccess.new()
22
+ end
23
+
24
+ def options
25
+ @options ||= default_options.compact
26
+ end
27
+
28
+ def options= hash
29
+ @options = options.merge(hash)
30
+ end
31
+ end
32
+ end
33
+ include Options
34
+ end
@@ -1,4 +1,5 @@
1
1
  require 'csv'
2
+
2
3
  class DataImp::Parser::Csv < DataImp::Parser
3
4
  def options
4
5
  { headers: true }
@@ -6,17 +6,21 @@ class DataImp::Parser
6
6
  @filename = filename
7
7
  end
8
8
 
9
- def self.find_parser type
10
- return self if type.blank?
11
- begin
12
- const_get type.camelize
13
- rescue NameError => e
14
- if require_relative "parser/#{type.underscore}"
15
- retry
9
+ class << self
10
+ def find_parser type
11
+ return self if type.blank?
12
+ begin
13
+ const_get type.camelize
14
+ rescue NameError => e
15
+ if require_relative "parser/#{type.underscore}"
16
+ retry
17
+ end
16
18
  end
19
+ rescue LoadError => e
20
+ raise DataImp::NoParser.new(type)
17
21
  end
18
- rescue LoadError => e
19
- raise DataImp::NoParser.new(type)
22
+
23
+ alias_method :find, :find_parser
20
24
  end
21
25
 
22
26
  def parse chunk
@@ -3,17 +3,21 @@ require_relative 'no_importer'
3
3
  class DataImp::Porter
4
4
  attr_reader :hash, :index
5
5
 
6
- def self.find_importer type
7
- return self if type.blank?
8
- begin
9
- const_get type.classify
10
- rescue NameError => e
11
- if require_relative "porter/#{type.underscore}"
12
- retry
6
+ class << self
7
+ def find_importer type
8
+ return self if type.blank?
9
+ begin
10
+ const_get type.classify
11
+ rescue NameError => e
12
+ if require_relative "porter/#{type.underscore}"
13
+ retry
14
+ end
13
15
  end
16
+ rescue LoadError => e
17
+ raise DataImp::NoImporter.new(type)
14
18
  end
15
- rescue LoadError => e
16
- raise DataImp::NoImporter.new(type)
19
+
20
+ alias_method :find, :find_importer
17
21
  end
18
22
 
19
23
  def initialize(hash, index = nil)
@@ -1,3 +1,3 @@
1
1
  class DataImp
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
data/lib/data_imp.rb CHANGED
@@ -1,15 +1,20 @@
1
1
 
2
- require 'active_support/core_ext/string'
3
-
4
2
  class DataImp
5
3
  end
6
4
 
5
+ require 'active_support'
6
+ require 'active_support/all'
7
+
8
+ require_relative "data_imp/version"
9
+ require_relative "data_imp/options"
10
+
11
+ require_relative "data_imp/import"
12
+
7
13
  require_relative "data_imp/finders"
8
14
  require_relative "data_imp/dir"
9
15
  require_relative "data_imp/import_methods"
10
16
  require_relative "data_imp/class_methods"
11
17
 
12
- # Dir[File.dirname(__FILE__) + '/data_imp/*.rb'].each {|file| require file }
13
18
  class DataImp
14
19
  extend DataImp::Finders
15
20
  extend DataImp::Dir
@@ -18,19 +23,21 @@ class DataImp
18
23
  attr_accessor :file, :parser, :importer, :extname, :basename
19
24
 
20
25
  def initialize file = nil, parser: nil, importer: nil
21
- self.file = data_dir.join(file)
26
+ return unless file
27
+
28
+ @file = data_dir.join(file)
22
29
  extname = File.extname(file)
23
- self.basename ||= File.basename(file, extname)
24
- self.extname = extname = extname.downcase.sub('.','')
25
- self.importer = find_importer(importer || basename) # returns class
26
- self.parser = find_parser(parser || extname) # returns class
30
+ @basename ||= File.basename(file, extname)
31
+ @extname = extname.downcase.sub('.','')
32
+ @importer = find_importer(importer || @basename) # returns class
33
+ @parser = find_parser(parser || @extname) # returns class
27
34
  end
28
35
 
29
36
  def import
30
37
  puts "Importing #{basename} with #{importer}"
31
38
  importer.before_all_imports
32
39
  parser.new(file).process_file do |hash, index|
33
- porter = importer.new(hash,index)
40
+ porter = importer.new(hash, index)
34
41
  begin
35
42
  porter.before_import
36
43
  porter.import
@@ -49,6 +56,5 @@ class DataImp
49
56
  puts if index % 10_000 == 0
50
57
  print '.' if index % 100 == 0
51
58
  end
52
-
53
59
  end
54
60
 
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: data_imp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert W. Ferney
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2022-08-08 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: activesupport
@@ -28,46 +27,46 @@ dependencies:
28
27
  name: bundler
29
28
  requirement: !ruby/object:Gem::Requirement
30
29
  requirements:
31
- - - "~>"
30
+ - - ">="
32
31
  - !ruby/object:Gem::Version
33
- version: 2.3.7
32
+ version: '0'
34
33
  type: :development
35
34
  prerelease: false
36
35
  version_requirements: !ruby/object:Gem::Requirement
37
36
  requirements:
38
- - - "~>"
37
+ - - ">="
39
38
  - !ruby/object:Gem::Version
40
- version: 2.3.7
39
+ version: '0'
41
40
  - !ruby/object:Gem::Dependency
42
41
  name: rake
43
42
  requirement: !ruby/object:Gem::Requirement
44
43
  requirements:
45
- - - "~>"
44
+ - - ">="
46
45
  - !ruby/object:Gem::Version
47
- version: '10.0'
46
+ version: '0'
48
47
  type: :development
49
48
  prerelease: false
50
49
  version_requirements: !ruby/object:Gem::Requirement
51
50
  requirements:
52
- - - "~>"
51
+ - - ">="
53
52
  - !ruby/object:Gem::Version
54
- version: '10.0'
53
+ version: '0'
55
54
  - !ruby/object:Gem::Dependency
56
55
  name: rspec
57
56
  requirement: !ruby/object:Gem::Requirement
58
57
  requirements:
59
- - - "~>"
58
+ - - ">="
60
59
  - !ruby/object:Gem::Version
61
- version: '3.0'
60
+ version: '0'
62
61
  type: :development
63
62
  prerelease: false
64
63
  version_requirements: !ruby/object:Gem::Requirement
65
64
  requirements:
66
- - - "~>"
65
+ - - ">="
67
66
  - !ruby/object:Gem::Version
68
- version: '3.0'
67
+ version: '0'
69
68
  - !ruby/object:Gem::Dependency
70
- name: roo
69
+ name: pry
71
70
  requirement: !ruby/object:Gem::Requirement
72
71
  requirements:
73
72
  - - ">="
@@ -81,7 +80,7 @@ dependencies:
81
80
  - !ruby/object:Gem::Version
82
81
  version: '0'
83
82
  - !ruby/object:Gem::Dependency
84
- name: roo-xls
83
+ name: pry-byebug
85
84
  requirement: !ruby/object:Gem::Requirement
86
85
  requirements:
87
86
  - - ">="
@@ -95,7 +94,7 @@ dependencies:
95
94
  - !ruby/object:Gem::Version
96
95
  version: '0'
97
96
  - !ruby/object:Gem::Dependency
98
- name: tiny_tds
97
+ name: activesupport
99
98
  requirement: !ruby/object:Gem::Requirement
100
99
  requirements:
101
100
  - - ">="
@@ -108,59 +107,37 @@ dependencies:
108
107
  - - ">="
109
108
  - !ruby/object:Gem::Version
110
109
  version: '0'
111
- description:
112
110
  email:
113
111
  - rob@ferney.org
114
112
  executables: []
115
113
  extensions: []
116
114
  extra_rdoc_files: []
117
115
  files:
118
- - ".gitignore"
119
- - ".rspec"
120
- - ".travis.yml"
121
- - CODE_OF_CONDUCT.md
122
- - Gemfile
123
- - LICENSE.txt
124
- - README.md
125
- - Rakefile
126
- - bin/console
127
- - bin/setup
128
- - data/hero.json
129
- - data/hero.yaml
130
- - data/heros.csv
131
- - data/heros.json
132
- - data/heros.ods
133
- - data/heros.xls
134
- - data/heros.xlsx
135
- - data/heros.yaml
136
- - data_imp.gemspec
137
116
  - lib/data_imp.rb
117
+ - lib/data_imp/base.rb
138
118
  - lib/data_imp/class_methods.rb
139
119
  - lib/data_imp/dir.rb
120
+ - lib/data_imp/file.rb
140
121
  - lib/data_imp/finders.rb
122
+ - lib/data_imp/import.rb
141
123
  - lib/data_imp/import_methods.rb
142
124
  - lib/data_imp/importer.rb
125
+ - lib/data_imp/importer/sample.rb
143
126
  - lib/data_imp/no_importer.rb
144
127
  - lib/data_imp/no_parser.rb
128
+ - lib/data_imp/options.rb
145
129
  - lib/data_imp/parser.rb
146
130
  - lib/data_imp/parser/csv.rb
147
131
  - lib/data_imp/parser/json.rb
148
- - lib/data_imp/parser/ods.rb
149
- - lib/data_imp/parser/spreadsheet.rb
150
132
  - lib/data_imp/parser/stream.rb
151
- - lib/data_imp/parser/xls.rb
152
- - lib/data_imp/parser/xlsx.rb
153
133
  - lib/data_imp/parser/yaml.rb
154
134
  - lib/data_imp/porter.rb
155
135
  - lib/data_imp/porter/sample.rb
156
- - lib/data_imp/tds.rb
157
- - lib/data_imp/tds/table.rb
158
136
  - lib/data_imp/version.rb
159
137
  homepage: https://github.com/capnregex/data_imp
160
138
  licenses:
161
139
  - MIT
162
140
  metadata: {}
163
- post_install_message:
164
141
  rdoc_options: []
165
142
  require_paths:
166
143
  - lib
@@ -175,8 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
175
152
  - !ruby/object:Gem::Version
176
153
  version: '0'
177
154
  requirements: []
178
- rubygems_version: 3.3.7
179
- signing_key:
155
+ rubygems_version: 4.0.10
180
156
  specification_version: 4
181
157
  summary: Scaffolding to make importing data easy
182
158
  test_files: []
data/.gitignore DELETED
@@ -1,14 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
-
11
- # rspec failure tracking
12
- .rspec_status
13
- *~
14
- .*.swp
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --format documentation
2
- --color
data/.travis.yml DELETED
@@ -1,5 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.3.3
5
- before_install: gem install bundler -v 1.15.4
data/CODE_OF_CONDUCT.md DELETED
@@ -1,74 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- In the interest of fostering an open and welcoming environment, we as
6
- contributors and maintainers pledge to making participation in our project and
7
- our community a harassment-free experience for everyone, regardless of age, body
8
- size, disability, ethnicity, gender identity and expression, level of experience,
9
- nationality, personal appearance, race, religion, or sexual identity and
10
- orientation.
11
-
12
- ## Our Standards
13
-
14
- Examples of behavior that contributes to creating a positive environment
15
- include:
16
-
17
- * Using welcoming and inclusive language
18
- * Being respectful of differing viewpoints and experiences
19
- * Gracefully accepting constructive criticism
20
- * Focusing on what is best for the community
21
- * Showing empathy towards other community members
22
-
23
- Examples of unacceptable behavior by participants include:
24
-
25
- * The use of sexualized language or imagery and unwelcome sexual attention or
26
- advances
27
- * Trolling, insulting/derogatory comments, and personal or political attacks
28
- * Public or private harassment
29
- * Publishing others' private information, such as a physical or electronic
30
- address, without explicit permission
31
- * Other conduct which could reasonably be considered inappropriate in a
32
- professional setting
33
-
34
- ## Our Responsibilities
35
-
36
- Project maintainers are responsible for clarifying the standards of acceptable
37
- behavior and are expected to take appropriate and fair corrective action in
38
- response to any instances of unacceptable behavior.
39
-
40
- Project maintainers have the right and responsibility to remove, edit, or
41
- reject comments, commits, code, wiki edits, issues, and other contributions
42
- that are not aligned to this Code of Conduct, or to ban temporarily or
43
- permanently any contributor for other behaviors that they deem inappropriate,
44
- threatening, offensive, or harmful.
45
-
46
- ## Scope
47
-
48
- This Code of Conduct applies both within project spaces and in public spaces
49
- when an individual is representing the project or its community. Examples of
50
- representing a project or community include using an official project e-mail
51
- address, posting via an official social media account, or acting as an appointed
52
- representative at an online or offline event. Representation of a project may be
53
- further defined and clarified by project maintainers.
54
-
55
- ## Enforcement
56
-
57
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at robert.w.ferney@uscis.dhs.gov. All
59
- complaints will be reviewed and investigated and will result in a response that
60
- is deemed necessary and appropriate to the circumstances. The project team is
61
- obligated to maintain confidentiality with regard to the reporter of an incident.
62
- Further details of specific enforcement policies may be posted separately.
63
-
64
- Project maintainers who do not follow or enforce the Code of Conduct in good
65
- faith may face temporary or permanent repercussions as determined by other
66
- members of the project's leadership.
67
-
68
- ## Attribution
69
-
70
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
- available at [http://contributor-covenant.org/version/1/4][version]
72
-
73
- [homepage]: http://contributor-covenant.org
74
- [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile DELETED
@@ -1,6 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
-
5
- # Specify your gem's dependencies in data_imp.gemspec
6
- gemspec
data/LICENSE.txt DELETED
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2017 Robert W. Ferney
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
data/README.md DELETED
@@ -1,90 +0,0 @@
1
- # Data Imp Porter
2
-
3
- ## Installation
4
-
5
- Add this line to your application's Gemfile:
6
-
7
- ```ruby
8
- gem 'data_imp'
9
- ```
10
-
11
- And then execute:
12
-
13
- $ bundle
14
-
15
- Or install it yourself as:
16
-
17
- $ gem install data_imp
18
-
19
- ## Usage
20
-
21
- The use of this gem requires that you define an 'importer' for your files.
22
-
23
- the fields from your data will be available to the importer as if they were local variables.
24
- ```ruby
25
- class SampleImporter < DataImp::Porter
26
- def import
27
- User.create_with(
28
- name: name,
29
- ).find_or_create_by(
30
- email: email
31
- )
32
- end
33
- end
34
- ```
35
-
36
- If you had your users in a csv file like
37
-
38
- ```csv
39
- name,email
40
- George,george@example.com
41
- Fred,fred@example.net
42
- ```
43
-
44
- You could then use
45
- ```ruby
46
- DataImp.import 'user.csv'
47
- ```
48
-
49
- If you had your users in a yaml file like
50
-
51
- ```yaml
52
- ---
53
- - name: George
54
- email: george@example.com
55
- - name: Fred
56
- email: fred@example.net
57
- ```
58
-
59
- You could then use
60
- ```ruby
61
- DataImp.import 'user.yaml'
62
- ```
63
-
64
- The same importer would be used for either example.
65
-
66
- The importer is looked up by the base name, or provided by the `importer:` parameter. . 'user' in this case.
67
-
68
- Parsing of the file is done by a Parser class and is looked up by the file extension, or the `parser:` parameter.
69
-
70
- Pre defined parsers are located in the lib/data_imp/parsers/ folder
71
-
72
- If you need to write your own, define it as 'class ExtParser < DataImp::Parser' to create or override the 'ext' extension parser.
73
-
74
- ## Development
75
-
76
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
77
-
78
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
79
-
80
- ## Contributing
81
-
82
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/data-porter. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
83
-
84
- ## License
85
-
86
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
87
-
88
- ## Code of Conduct
89
-
90
- Everyone interacting in the Data::Porter project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/data-porter/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile DELETED
@@ -1,6 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task :default => :spec
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "data/porter"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
data/data/hero.json DELETED
@@ -1 +0,0 @@
1
- {"name":"George","rank":"Sargent","serial_number":9991212}
data/data/hero.yaml DELETED
@@ -1,4 +0,0 @@
1
- ---
2
- name: George
3
- rank: Sargent
4
- serial_number: 9991212
data/data/heros.csv DELETED
@@ -1,2 +0,0 @@
1
- name,rank,serial_number
2
- George,Sargent,9991212
data/data/heros.json DELETED
@@ -1 +0,0 @@
1
- [{"name":"George","rank":"Sargent","serial_number":9991212}]
data/data/heros.ods DELETED
Binary file
data/data/heros.xls DELETED
Binary file
data/data/heros.xlsx DELETED
Binary file
data/data/heros.yaml DELETED
@@ -1,4 +0,0 @@
1
- ---
2
- - name: George
3
- rank: Sargent
4
- serial_number: 9991212
data/data_imp.gemspec DELETED
@@ -1,31 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path("../lib", __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "data_imp/version"
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "data_imp"
8
- spec.version = DataImp::VERSION
9
- spec.authors = ["Robert W. Ferney"]
10
- spec.email = ["rob@ferney.org"]
11
-
12
- spec.summary = %q{Scaffolding to make importing data easy}
13
- spec.homepage = "https://github.com/capnregex/data_imp"
14
- spec.license = "MIT"
15
-
16
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
- f.match(%r{^(test|spec|features)/})
18
- end
19
- spec.bindir = "exe"
20
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
- spec.require_paths = ["lib"]
22
-
23
- spec.add_runtime_dependency 'activesupport'
24
-
25
- spec.add_development_dependency "bundler", "~> 2.3.7"
26
- spec.add_development_dependency "rake", "~> 10.0"
27
- spec.add_development_dependency "rspec", "~> 3.0"
28
- spec.add_development_dependency "roo" #, "~> 3.0"
29
- spec.add_development_dependency "roo-xls" #, "~> 3.0"
30
- spec.add_development_dependency "tiny_tds"
31
- end
@@ -1,7 +0,0 @@
1
-
2
- require_relative 'spreadsheet'
3
- class DataImp::Parser::Ods < DataImp::Parser::Spreadsheet
4
- def options
5
- { extension: "ods"}
6
- end
7
- end
@@ -1,20 +0,0 @@
1
- require 'roo'
2
- class DataImp::Parser::Spreadsheet < DataImp::Parser
3
- def options
4
- { }
5
- end
6
-
7
- def process_file &block
8
- spreadsheet = Roo::Spreadsheet.open(filename, options)
9
- header = spreadsheet.row(1)
10
- (2..spreadsheet.last_row).each do |index|
11
- row = spreadsheet.row(index)
12
- hash = [header, row].transpose.to_h
13
- yield hash, index
14
- end
15
- end
16
-
17
- def process input, &block
18
- raise "unable to process spreadsheet as a stream"
19
- end
20
- end
@@ -1,7 +0,0 @@
1
- require_relative 'spreadsheet'
2
- require 'roo-xls'
3
- class DataImp::Parser::Xls < DataImp::Parser::Spreadsheet
4
- def options
5
- { extension: "xls"}
6
- end
7
- end
@@ -1,6 +0,0 @@
1
- require_relative 'spreadsheet'
2
- class DataImp::Parser::Xlsx < DataImp::Parser::Spreadsheet
3
- def options
4
- { extension: :xlsx }
5
- end
6
- end
@@ -1,24 +0,0 @@
1
- class DataImp::Tds::Table
2
- attr_reader :client, :table, :schema
3
- def initialize client, table, schema:
4
- @client = client
5
- @table = table
6
- @schema = schema
7
- end
8
-
9
- def sql
10
- if schema
11
- "select * from [#{schema}].[#{table}]"
12
- else
13
- "select * from [#{table}]"
14
- end
15
- end
16
-
17
- def result
18
- @result ||= client.execute(sql)
19
- end
20
-
21
- def each &block
22
- result.each &block
23
- end
24
- end
data/lib/data_imp/tds.rb DELETED
@@ -1,53 +0,0 @@
1
- require 'tiny_tds'
2
- require_relative "finders"
3
- class DataImp::Tds
4
- extend DataImp::Finders
5
-
6
- def initialize options={}
7
- @options = options
8
- end
9
-
10
- def options
11
- @options ||= {}
12
- end
13
-
14
- def client
15
- @client ||= TinyTds::Client.new options
16
- end
17
-
18
- def import table
19
- table.strip!
20
- return if table =~ /^#/
21
- parts = table.split('.')
22
- table = parts.pop
23
- schema = parts.shift
24
- importer = find_importer(table)
25
- tbl = Table.new(client, table, schema: schema)
26
- puts "Importing #{table} with #{importer}"
27
- importer.before_all_imports
28
- tbl.each do |hash, index|
29
- porter = importer.new(hash,index)
30
- begin
31
- porter.before_import
32
- porter.import
33
- porter.after_import
34
- show_progress index
35
- rescue StandardError => e
36
- warn "#{table}:#{index}:#{e.class.name}"
37
- porter.on_error e
38
- end
39
- end
40
- importer.after_all_imports
41
- puts
42
- end
43
-
44
- def import_list list, *args, &block
45
- list.each_line do |table|
46
- import table, *args, &block
47
- end
48
- end
49
-
50
- def show_progress index
51
- end
52
- end
53
- require_relative "tds/table"