active_record_data_loader 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +38 -0
  5. data/.travis.yml +11 -0
  6. data/Appraisals +17 -0
  7. data/CODE_OF_CONDUCT.md +74 -0
  8. data/Gemfile +8 -0
  9. data/Gemfile.lock +107 -0
  10. data/LICENSE.txt +21 -0
  11. data/README.md +49 -0
  12. data/Rakefile +10 -0
  13. data/active_record_data_loader.gemspec +47 -0
  14. data/bin/console +15 -0
  15. data/bin/setup +8 -0
  16. data/config/database.yml +10 -0
  17. data/config/database.yml.travis +7 -0
  18. data/gemfiles/.bundle/config +2 -0
  19. data/gemfiles/activerecord_5.gemfile +7 -0
  20. data/gemfiles/activerecord_6.gemfile +7 -0
  21. data/gemfiles/faker.gemfile +7 -0
  22. data/gemfiles/ffaker.gemfile +7 -0
  23. data/lib/active_record_data_loader.rb +64 -0
  24. data/lib/active_record_data_loader/active_record/belongs_to_configuration.rb +27 -0
  25. data/lib/active_record_data_loader/active_record/column_configuration.rb +43 -0
  26. data/lib/active_record_data_loader/active_record/enum_value_generator.rb +25 -0
  27. data/lib/active_record_data_loader/active_record/integer_value_generator.rb +21 -0
  28. data/lib/active_record_data_loader/active_record/model_data_generator.rb +72 -0
  29. data/lib/active_record_data_loader/active_record/polymorphic_belongs_to_configuration.rb +49 -0
  30. data/lib/active_record_data_loader/active_record/text_value_generator.rb +72 -0
  31. data/lib/active_record_data_loader/bulk_insert_strategy.rb +57 -0
  32. data/lib/active_record_data_loader/configuration.rb +17 -0
  33. data/lib/active_record_data_loader/copy_strategy.rb +58 -0
  34. data/lib/active_record_data_loader/data_faker.rb +85 -0
  35. data/lib/active_record_data_loader/dsl/definition.rb +25 -0
  36. data/lib/active_record_data_loader/dsl/model.rb +35 -0
  37. data/lib/active_record_data_loader/dsl/polymorphic_association.rb +25 -0
  38. data/lib/active_record_data_loader/loader.rb +66 -0
  39. data/lib/active_record_data_loader/version.rb +5 -0
  40. data/script/ci_build.sh +6 -0
  41. metadata +240 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: fbc38165d9ffa4debdc127641a9e79c4fd3eb382dd9271c7e0eed849992c8c72
4
+ data.tar.gz: d2703bbd36cdbcae163dbf19082704e39dc717499689d9754bc570d846895ada
5
+ SHA512:
6
+ metadata.gz: a999728b9926d7e87cb93fbf3329902becc4dd0b51139f38b473820010b93987ecb5e87be0be214111f28bd6c64685af6d2b09d61cc35cf4d3c41dd1fc88f026
7
+ data.tar.gz: 1b6bcbf2edd88700ce91083ce7da1958ef314f65f5c57932cd978915e36603788696eb3f1cc5894f36dd6870d6d945ca9e72068e2ac05444f5992df099c4760a
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /log/
10
+ /gemfiles/*.lock
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,38 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.3
3
+
4
+ Lint/UnusedMethodArgument:
5
+ AllowUnusedKeywordArguments: true
6
+
7
+ Metrics/AbcSize:
8
+ Max: 20
9
+ Exclude: ["spec/**/*"]
10
+
11
+ Metrics/BlockLength:
12
+ Exclude: ["spec/**/*", "*.gemspec"]
13
+
14
+ Metrics/LineLength:
15
+ Max: 110
16
+ Exclude: ["*.gemspec"]
17
+
18
+ Metrics/MethodLength:
19
+ Max: 15
20
+ Exclude: ["spec/**/*"]
21
+
22
+ Style/FrozenStringLiteralComment:
23
+ Exclude: ["gemfiles/*"]
24
+
25
+ Style/Documentation:
26
+ Enabled: false
27
+
28
+ Style/StringLiterals:
29
+ EnforcedStyle: double_quotes
30
+
31
+ Style/SymbolArray:
32
+ Exclude: ["spec/**/*", "*.gemspec", "Rakefile"]
33
+
34
+ Style/TrailingCommaInArrayLiteral:
35
+ EnforcedStyleForMultiline: consistent_comma
36
+
37
+ Style/TrailingCommaInHashLiteral:
38
+ EnforcedStyleForMultiline: consistent_comma
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.3
5
+ services:
6
+ - postgresql
7
+ before_install: gem install bundler -v 1.16.1
8
+ before_script:
9
+ - psql -c 'create database test;' -U postgres
10
+ - cp config/database.yml.travis config/database.yml
11
+ script: ./script/ci_build.sh
data/Appraisals ADDED
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ appraise "activerecord-5" do
4
+ gem "activerecord", "~> 5.0"
5
+ end
6
+
7
+ appraise "activerecord-6" do
8
+ gem "activerecord", "6.0.0.rc1"
9
+ end
10
+
11
+ appraise "faker" do
12
+ gem "faker", ">= 1.9.3"
13
+ end
14
+
15
+ appraise "ffaker" do
16
+ gem "ffaker"
17
+ end
@@ -0,0 +1,74 @@
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 abeiderman@gmail.com. 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 ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in active_record_data_loader.gemspec
8
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,107 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ active_record_data_loader (0.1.1)
5
+ activerecord (>= 4.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activemodel (5.2.3)
11
+ activesupport (= 5.2.3)
12
+ activerecord (5.2.3)
13
+ activemodel (= 5.2.3)
14
+ activesupport (= 5.2.3)
15
+ arel (>= 9.0)
16
+ activesupport (5.2.3)
17
+ concurrent-ruby (~> 1.0, >= 1.0.2)
18
+ i18n (>= 0.7, < 2)
19
+ minitest (~> 5.1)
20
+ tzinfo (~> 1.1)
21
+ appraisal (2.2.0)
22
+ bundler
23
+ rake
24
+ thor (>= 0.14.0)
25
+ arel (9.0.0)
26
+ ast (2.4.0)
27
+ coderay (1.1.2)
28
+ concurrent-ruby (1.1.5)
29
+ coveralls (0.8.23)
30
+ json (>= 1.8, < 3)
31
+ simplecov (~> 0.16.1)
32
+ term-ansicolor (~> 1.3)
33
+ thor (>= 0.19.4, < 2.0)
34
+ tins (~> 1.6)
35
+ diff-lcs (1.3)
36
+ docile (1.3.1)
37
+ i18n (1.6.0)
38
+ concurrent-ruby (~> 1.0)
39
+ jaro_winkler (1.5.2)
40
+ json (2.2.0)
41
+ method_source (0.9.2)
42
+ minitest (5.11.3)
43
+ parallel (1.17.0)
44
+ parser (2.6.3.0)
45
+ ast (~> 2.4.0)
46
+ pg (1.1.4)
47
+ pry (0.12.2)
48
+ coderay (~> 1.1.0)
49
+ method_source (~> 0.9.0)
50
+ rainbow (3.0.0)
51
+ rake (12.3.2)
52
+ rspec (3.8.0)
53
+ rspec-core (~> 3.8.0)
54
+ rspec-expectations (~> 3.8.0)
55
+ rspec-mocks (~> 3.8.0)
56
+ rspec-collection_matchers (1.1.3)
57
+ rspec-expectations (>= 2.99.0.beta1)
58
+ rspec-core (3.8.0)
59
+ rspec-support (~> 3.8.0)
60
+ rspec-expectations (3.8.3)
61
+ diff-lcs (>= 1.2.0, < 2.0)
62
+ rspec-support (~> 3.8.0)
63
+ rspec-mocks (3.8.0)
64
+ diff-lcs (>= 1.2.0, < 2.0)
65
+ rspec-support (~> 3.8.0)
66
+ rspec-support (3.8.0)
67
+ rubocop (0.68.1)
68
+ jaro_winkler (~> 1.5.1)
69
+ parallel (~> 1.10)
70
+ parser (>= 2.5, != 2.5.1.1)
71
+ rainbow (>= 2.2.2, < 4.0)
72
+ ruby-progressbar (~> 1.7)
73
+ unicode-display_width (>= 1.4.0, < 1.6)
74
+ ruby-progressbar (1.10.0)
75
+ simplecov (0.16.1)
76
+ docile (~> 1.1)
77
+ json (>= 1.8, < 3)
78
+ simplecov-html (~> 0.10.0)
79
+ simplecov-html (0.10.2)
80
+ sqlite3 (1.4.1)
81
+ term-ansicolor (1.7.1)
82
+ tins (~> 1.0)
83
+ thor (0.20.3)
84
+ thread_safe (0.3.6)
85
+ tins (1.20.3)
86
+ tzinfo (1.2.5)
87
+ thread_safe (~> 0.1)
88
+ unicode-display_width (1.5.0)
89
+
90
+ PLATFORMS
91
+ ruby
92
+
93
+ DEPENDENCIES
94
+ active_record_data_loader!
95
+ appraisal
96
+ bundler (>= 1.16)
97
+ coveralls
98
+ pg
99
+ pry
100
+ rake (~> 12.0)
101
+ rspec (~> 3.0)
102
+ rspec-collection_matchers
103
+ rubocop
104
+ sqlite3
105
+
106
+ BUNDLED WITH
107
+ 2.0.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Alejandro Beiderman
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 ADDED
@@ -0,0 +1,49 @@
1
+ # ActiveRecord Data Loader
2
+
3
+ [![Build Status](https://travis-ci.org/abeiderman/active_record_data_loader.svg?branch=master)](https://travis-ci.org/abeiderman/active_record_data_loader)
4
+ [![Coverage Status](https://coveralls.io/repos/github/abeiderman/active_record_data_loader/badge.svg?branch=master)](https://coveralls.io/github/abeiderman/active_record_data_loader?branch=master)
5
+ [![Maintainability](https://api.codeclimate.com/v1/badges/338904b3f7e8d19a3cb1/maintainability)](https://codeclimate.com/github/abeiderman/active_record_data_loader/maintainability)
6
+
7
+ Efficiently bulk load data for your ActiveRecord models with a simple DSL.
8
+
9
+ ## Why?
10
+
11
+ Load, performance, and stress tests often require setting up a realistic amount of data in your database. This gem is intended to help organize that data load and make it more maintainable than having a collection of SQL scripts.
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem "active_record_data_loader"
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install active_record_data_loader
28
+
29
+ ## Usage
30
+
31
+ TODO: Write usage instructions here
32
+
33
+ ## Development
34
+
35
+ 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.
36
+
37
+ 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).
38
+
39
+ ## Contributing
40
+
41
+ Bug reports and pull requests are welcome on GitHub at https://github.com/abeiderman/active_record_data_loader. 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.
42
+
43
+ ## License
44
+
45
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
46
+
47
+ ## Code of Conduct
48
+
49
+ Everyone interacting in the ActiveRecord Data Loader project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/abeiderman/active_record_data_loader/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+ require "rubocop/rake_task"
6
+
7
+ RSpec::Core::RakeTask.new(:spec)
8
+ RuboCop::RakeTask.new(:rubocop)
9
+
10
+ task default: [:spec, :rubocop]
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("lib", __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "active_record_data_loader/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "active_record_data_loader"
9
+ spec.version = ActiveRecordDataLoader::VERSION
10
+ spec.authors = ["Alejandro Beiderman"]
11
+ spec.email = ["abeiderman@gmail.com"]
12
+
13
+ spec.summary = "A utility to bulk load test data for performance testing."
14
+ spec.description = "A utility to bulk load test data for performance testing."
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["source_code_uri"] = "https://github.com/abeiderman/active_record_data_loader"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "bin"
30
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.required_ruby_version = ">= 2.3.0"
34
+
35
+ spec.add_dependency "activerecord", ">= 4.0"
36
+
37
+ spec.add_development_dependency "appraisal"
38
+ spec.add_development_dependency "bundler", ">= 1.16"
39
+ spec.add_development_dependency "coveralls"
40
+ spec.add_development_dependency "pg"
41
+ spec.add_development_dependency "pry"
42
+ spec.add_development_dependency "rake", "~> 12.0"
43
+ spec.add_development_dependency "rspec", "~> 3.0"
44
+ spec.add_development_dependency "rspec-collection_matchers"
45
+ spec.add_development_dependency "rubocop"
46
+ spec.add_development_dependency "sqlite3"
47
+ end
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "active_record_data_loader"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
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