array_to_activerecord 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +3 -0
- data/.travis.yml +40 -0
- data/Appraisals +24 -0
- data/Gemfile +6 -0
- data/LICENSE +21 -0
- data/README.md +71 -0
- data/Rakefile +6 -0
- data/array_to_activerecord.gemspec +29 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/gemfiles/.bundle/config +2 -0
- data/gemfiles/rails40.gemfile +7 -0
- data/gemfiles/rails40.gemfile.lock +67 -0
- data/gemfiles/rails41.gemfile +7 -0
- data/gemfiles/rails41.gemfile.lock +66 -0
- data/gemfiles/rails42.gemfile +8 -0
- data/gemfiles/rails42.gemfile.lock +65 -0
- data/gemfiles/rails50.gemfile +8 -0
- data/gemfiles/rails50.gemfile.lock +63 -0
- data/gemfiles/rails51.gemfile +8 -0
- data/gemfiles/rails51.gemfile.lock +63 -0
- data/gemfiles/rails52.gemfile +8 -0
- data/gemfiles/rails52.gemfile.lock +63 -0
- data/gemfiles/rails60.rc1.gemfile +8 -0
- data/gemfiles/rails60.rc1.gemfile.lock +63 -0
- data/lib/array_to_activerecord.rb +73 -0
- metadata +155 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 92c07789ef46178587f78a2fcb993ae01c9c546f6f6e887a67d995c5d11d63cd
|
4
|
+
data.tar.gz: 3a1d40a16396e10706329e008fea4ad76bcd0a491931e8144089a5778c322289
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 92371f90973eb36cdfde153bdd5a223f6a3e574e1679882a32423454061df860467de210a45b6bc649cedf3cc19291347d6bc2809e3a8b369d075bef86c4d7eb
|
7
|
+
data.tar.gz: 8b010ceca1613c22c48fac5b22ea6761606aabf7893d92f058e58e52f537058aacb7aaaaf35ffd507067fe61c21387f7bd6e7dc0dcad84548f1e82b8e87a16de
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
sudo: false
|
2
|
+
language: ruby
|
3
|
+
|
4
|
+
matrix:
|
5
|
+
include:
|
6
|
+
# ActiveRecord 4.2
|
7
|
+
- rvm: 2.3
|
8
|
+
gemfile: gemfiles/rails42.gemfile
|
9
|
+
- rvm: 2.4
|
10
|
+
gemfile: gemfiles/rails42.gemfile
|
11
|
+
|
12
|
+
# ActiveRecord 5.0
|
13
|
+
- rvm: 2.3
|
14
|
+
gemfile: gemfiles/rails50.gemfile
|
15
|
+
- rvm: 2.4
|
16
|
+
gemfile: gemfiles/rails50.gemfile
|
17
|
+
- rvm: 2.5.3
|
18
|
+
gemfile: gemfiles/rails50.gemfile
|
19
|
+
|
20
|
+
# ActiveRecord 5.1
|
21
|
+
- rvm: 2.3
|
22
|
+
gemfile: gemfiles/rails51.gemfile
|
23
|
+
- rvm: 2.4
|
24
|
+
gemfile: gemfiles/rails51.gemfile
|
25
|
+
- rvm: 2.5.3
|
26
|
+
gemfile: gemfiles/rails51.gemfile
|
27
|
+
|
28
|
+
# ActiveRecord 5.2
|
29
|
+
- rvm: 2.4
|
30
|
+
gemfile: gemfiles/rails52.gemfile
|
31
|
+
- rvm: 2.5.3
|
32
|
+
gemfile: gemfiles/rails52.gemfile
|
33
|
+
- rvm: 2.6
|
34
|
+
gemfile: gemfiles/rails52.gemfile
|
35
|
+
|
36
|
+
# ActiveRecord 6.0.rc1
|
37
|
+
- rvm: 2.5.3
|
38
|
+
gemfile: gemfiles/rails60.rc1.gemfile
|
39
|
+
- rvm: 2.6
|
40
|
+
gemfile: gemfiles/rails60.rc1.gemfile
|
data/Appraisals
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
appraise 'rails42' do
|
2
|
+
gem 'activerecord', '~> 4.2.0'
|
3
|
+
gem "sqlite3", '~> 1.3.6'
|
4
|
+
end
|
5
|
+
|
6
|
+
appraise 'rails50' do
|
7
|
+
gem 'activerecord', '~> 5.0.0'
|
8
|
+
gem "sqlite3", '~> 1.3.6'
|
9
|
+
end
|
10
|
+
|
11
|
+
appraise 'rails51' do
|
12
|
+
gem 'activerecord', '~> 5.1.0'
|
13
|
+
gem "sqlite3", '~> 1.3.6'
|
14
|
+
end
|
15
|
+
|
16
|
+
appraise 'rails52' do
|
17
|
+
gem 'activerecord', '~> 5.2.0'
|
18
|
+
gem "sqlite3", '~> 1.3.6'
|
19
|
+
end
|
20
|
+
|
21
|
+
appraise 'rails60.rc1' do
|
22
|
+
gem 'activerecord', '~> 6.0.0.rc1'
|
23
|
+
gem "sqlite3", '~> 1.4'
|
24
|
+
end
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2019 potato2003
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/potato2003/array_to_activerecord.svg?branch=master)](https://travis-ci.org/potato2003/array_to_activerecord)
|
2
|
+
|
3
|
+
# ArrayToActiverecord
|
4
|
+
|
5
|
+
Convert Array to ActiveRecord::Relation without database access
|
6
|
+
|
7
|
+
## Support Version
|
8
|
+
|
9
|
+
ActiveRecord v4.2 ~ v6.0.0.rc1
|
10
|
+
|
11
|
+
Currently, Testing matrix of Ruby/ActiveRecord versions on Travis CI.
|
12
|
+
|
13
|
+
| ActiveRecord \ Ruby | 2.3 | 2.4 | 2.5 | 2.6 |
|
14
|
+
| ------------------- | --- | --- | --- | --- |
|
15
|
+
| 4.2 | ✓ | ✓ | - | - |
|
16
|
+
| 5.0 | ✓ | ✓ | ✓ | - |
|
17
|
+
| 5.1 | ✓ | ✓ | ✓ | - |
|
18
|
+
| 5.2 | - | ✓ | ✓ | ✓ |
|
19
|
+
| 6.0.rc1 | - | - | ✓ | ✓ |
|
20
|
+
|
21
|
+
## Installation
|
22
|
+
|
23
|
+
Add this line to your application's Gemfile:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
gem 'array_to_activerecord'
|
27
|
+
```
|
28
|
+
|
29
|
+
And then execute:
|
30
|
+
|
31
|
+
$ bundle
|
32
|
+
|
33
|
+
Or install it yourself as:
|
34
|
+
|
35
|
+
$ gem install array_to_activerecord
|
36
|
+
|
37
|
+
## Usage
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
array = [ Customer.find(1), Customer.find(2), Customer.find(3) ]
|
41
|
+
# Customer Load (0.1ms) SELECT `customers`.* FROM `customers` WHERE `customers`.`id` = 1 LIMIT 1
|
42
|
+
# Customer Load (0.1ms) SELECT `customers`.* FROM `customers` WHERE `customers`.`id` = 2 LIMIT 1
|
43
|
+
# Customer Load (0.1ms) SELECT `customers`.* FROM `customers` WHERE `customers`.`id` = 3 LIMIT 1
|
44
|
+
|
45
|
+
# Convert without database access
|
46
|
+
records = ArrayToActiveRecord.convert(array, model_class: Customer)
|
47
|
+
```
|
48
|
+
|
49
|
+
## Testing
|
50
|
+
|
51
|
+
```
|
52
|
+
bundle exec rake
|
53
|
+
```
|
54
|
+
|
55
|
+
### Testing with multiple versions of ActiveRecord
|
56
|
+
|
57
|
+
First, you need to install the dependencies for each appraisal
|
58
|
+
|
59
|
+
```
|
60
|
+
bundle exec appraisal install
|
61
|
+
```
|
62
|
+
|
63
|
+
Next, run tests across all ActiveRecord versions
|
64
|
+
|
65
|
+
```
|
66
|
+
bundle exec appraisal rake
|
67
|
+
```
|
68
|
+
|
69
|
+
## Contributing
|
70
|
+
|
71
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/potato2003/array_to_activerecord.
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "array_to_activerecord"
|
7
|
+
spec.version = "1.0.2"
|
8
|
+
spec.authors = ["potato2003"]
|
9
|
+
spec.email = ["potato2003@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "Convert Array to ActiveRecord::Relation without database access"
|
12
|
+
spec.description = "Convert Array to ActiveRecord::Relation without database access"
|
13
|
+
spec.homepage = "https://github.com/potato2003/array_to_activerecord"
|
14
|
+
spec.licenses = ['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_development_dependency "bundler"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
26
|
+
spec.add_development_dependency "activerecord"
|
27
|
+
spec.add_development_dependency "appraisal"
|
28
|
+
spec.add_development_dependency "sqlite3"
|
29
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "array_to_activerecord"
|
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
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ..
|
3
|
+
specs:
|
4
|
+
array_to_activerecord (1.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
activemodel (4.0.13)
|
10
|
+
activesupport (= 4.0.13)
|
11
|
+
builder (~> 3.1.0)
|
12
|
+
activerecord (4.0.13)
|
13
|
+
activemodel (= 4.0.13)
|
14
|
+
activerecord-deprecated_finders (~> 1.0.2)
|
15
|
+
activesupport (= 4.0.13)
|
16
|
+
arel (~> 4.0.0)
|
17
|
+
activerecord-deprecated_finders (1.0.4)
|
18
|
+
activesupport (4.0.13)
|
19
|
+
i18n (~> 0.6, >= 0.6.9)
|
20
|
+
minitest (~> 4.2)
|
21
|
+
multi_json (~> 1.3)
|
22
|
+
thread_safe (~> 0.1)
|
23
|
+
tzinfo (~> 0.3.37)
|
24
|
+
appraisal (2.2.0)
|
25
|
+
bundler
|
26
|
+
rake
|
27
|
+
thor (>= 0.14.0)
|
28
|
+
arel (4.0.2)
|
29
|
+
builder (3.1.4)
|
30
|
+
concurrent-ruby (1.1.5)
|
31
|
+
diff-lcs (1.3)
|
32
|
+
i18n (0.9.5)
|
33
|
+
concurrent-ruby (~> 1.0)
|
34
|
+
minitest (4.7.5)
|
35
|
+
multi_json (1.13.1)
|
36
|
+
rake (10.5.0)
|
37
|
+
rspec (3.8.0)
|
38
|
+
rspec-core (~> 3.8.0)
|
39
|
+
rspec-expectations (~> 3.8.0)
|
40
|
+
rspec-mocks (~> 3.8.0)
|
41
|
+
rspec-core (3.8.0)
|
42
|
+
rspec-support (~> 3.8.0)
|
43
|
+
rspec-expectations (3.8.3)
|
44
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
45
|
+
rspec-support (~> 3.8.0)
|
46
|
+
rspec-mocks (3.8.0)
|
47
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
48
|
+
rspec-support (~> 3.8.0)
|
49
|
+
rspec-support (3.8.0)
|
50
|
+
sqlite3 (1.3.13)
|
51
|
+
thor (0.20.3)
|
52
|
+
thread_safe (0.3.6)
|
53
|
+
tzinfo (0.3.55)
|
54
|
+
|
55
|
+
PLATFORMS
|
56
|
+
ruby
|
57
|
+
|
58
|
+
DEPENDENCIES
|
59
|
+
activerecord (~> 4.0.0)
|
60
|
+
appraisal
|
61
|
+
array_to_activerecord!
|
62
|
+
rake (~> 10.0)
|
63
|
+
rspec (~> 3.0)
|
64
|
+
sqlite3 (~> 1.3.6)
|
65
|
+
|
66
|
+
BUNDLED WITH
|
67
|
+
1.16.1
|
@@ -0,0 +1,66 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ..
|
3
|
+
specs:
|
4
|
+
array_to_activerecord (1.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
activemodel (4.1.16)
|
10
|
+
activesupport (= 4.1.16)
|
11
|
+
builder (~> 3.1)
|
12
|
+
activerecord (4.1.16)
|
13
|
+
activemodel (= 4.1.16)
|
14
|
+
activesupport (= 4.1.16)
|
15
|
+
arel (~> 5.0.0)
|
16
|
+
activesupport (4.1.16)
|
17
|
+
i18n (~> 0.6, >= 0.6.9)
|
18
|
+
json (~> 1.7, >= 1.7.7)
|
19
|
+
minitest (~> 5.1)
|
20
|
+
thread_safe (~> 0.1)
|
21
|
+
tzinfo (~> 1.1)
|
22
|
+
appraisal (2.2.0)
|
23
|
+
bundler
|
24
|
+
rake
|
25
|
+
thor (>= 0.14.0)
|
26
|
+
arel (5.0.1.20140414130214)
|
27
|
+
builder (3.2.3)
|
28
|
+
concurrent-ruby (1.1.5)
|
29
|
+
diff-lcs (1.3)
|
30
|
+
i18n (0.9.5)
|
31
|
+
concurrent-ruby (~> 1.0)
|
32
|
+
json (1.8.6)
|
33
|
+
minitest (5.11.3)
|
34
|
+
rake (10.5.0)
|
35
|
+
rspec (3.8.0)
|
36
|
+
rspec-core (~> 3.8.0)
|
37
|
+
rspec-expectations (~> 3.8.0)
|
38
|
+
rspec-mocks (~> 3.8.0)
|
39
|
+
rspec-core (3.8.0)
|
40
|
+
rspec-support (~> 3.8.0)
|
41
|
+
rspec-expectations (3.8.3)
|
42
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
43
|
+
rspec-support (~> 3.8.0)
|
44
|
+
rspec-mocks (3.8.0)
|
45
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
46
|
+
rspec-support (~> 3.8.0)
|
47
|
+
rspec-support (3.8.0)
|
48
|
+
sqlite3 (1.3.13)
|
49
|
+
thor (0.20.3)
|
50
|
+
thread_safe (0.3.6)
|
51
|
+
tzinfo (1.2.5)
|
52
|
+
thread_safe (~> 0.1)
|
53
|
+
|
54
|
+
PLATFORMS
|
55
|
+
ruby
|
56
|
+
|
57
|
+
DEPENDENCIES
|
58
|
+
activerecord (~> 4.1.0)
|
59
|
+
appraisal
|
60
|
+
array_to_activerecord!
|
61
|
+
rake (~> 10.0)
|
62
|
+
rspec (~> 3.0)
|
63
|
+
sqlite3 (~> 1.3.6)
|
64
|
+
|
65
|
+
BUNDLED WITH
|
66
|
+
1.16.1
|
@@ -0,0 +1,65 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ..
|
3
|
+
specs:
|
4
|
+
array_to_activerecord (1.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
activemodel (4.2.11.1)
|
10
|
+
activesupport (= 4.2.11.1)
|
11
|
+
builder (~> 3.1)
|
12
|
+
activerecord (4.2.11.1)
|
13
|
+
activemodel (= 4.2.11.1)
|
14
|
+
activesupport (= 4.2.11.1)
|
15
|
+
arel (~> 6.0)
|
16
|
+
activesupport (4.2.11.1)
|
17
|
+
i18n (~> 0.7)
|
18
|
+
minitest (~> 5.1)
|
19
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
20
|
+
tzinfo (~> 1.1)
|
21
|
+
appraisal (2.2.0)
|
22
|
+
bundler
|
23
|
+
rake
|
24
|
+
thor (>= 0.14.0)
|
25
|
+
arel (6.0.4)
|
26
|
+
builder (3.2.3)
|
27
|
+
concurrent-ruby (1.1.5)
|
28
|
+
diff-lcs (1.3)
|
29
|
+
i18n (0.9.5)
|
30
|
+
concurrent-ruby (~> 1.0)
|
31
|
+
minitest (5.11.3)
|
32
|
+
rake (10.5.0)
|
33
|
+
rspec (3.8.0)
|
34
|
+
rspec-core (~> 3.8.0)
|
35
|
+
rspec-expectations (~> 3.8.0)
|
36
|
+
rspec-mocks (~> 3.8.0)
|
37
|
+
rspec-core (3.8.0)
|
38
|
+
rspec-support (~> 3.8.0)
|
39
|
+
rspec-expectations (3.8.3)
|
40
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
41
|
+
rspec-support (~> 3.8.0)
|
42
|
+
rspec-mocks (3.8.0)
|
43
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
44
|
+
rspec-support (~> 3.8.0)
|
45
|
+
rspec-support (3.8.0)
|
46
|
+
sqlite3 (1.3.13)
|
47
|
+
thor (0.20.3)
|
48
|
+
thread_safe (0.3.6)
|
49
|
+
tzinfo (1.2.5)
|
50
|
+
thread_safe (~> 0.1)
|
51
|
+
|
52
|
+
PLATFORMS
|
53
|
+
ruby
|
54
|
+
|
55
|
+
DEPENDENCIES
|
56
|
+
activerecord (~> 4.2.0)
|
57
|
+
appraisal
|
58
|
+
array_to_activerecord!
|
59
|
+
bundler
|
60
|
+
rake (~> 10.0)
|
61
|
+
rspec (~> 3.0)
|
62
|
+
sqlite3 (~> 1.3.6)
|
63
|
+
|
64
|
+
BUNDLED WITH
|
65
|
+
1.16.1
|
@@ -0,0 +1,63 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ..
|
3
|
+
specs:
|
4
|
+
array_to_activerecord (1.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
activemodel (5.0.2)
|
10
|
+
activesupport (= 5.0.2)
|
11
|
+
activerecord (5.0.2)
|
12
|
+
activemodel (= 5.0.2)
|
13
|
+
activesupport (= 5.0.2)
|
14
|
+
arel (~> 7.0)
|
15
|
+
activesupport (5.0.2)
|
16
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
17
|
+
i18n (~> 0.7)
|
18
|
+
minitest (~> 5.1)
|
19
|
+
tzinfo (~> 1.1)
|
20
|
+
appraisal (2.2.0)
|
21
|
+
bundler
|
22
|
+
rake
|
23
|
+
thor (>= 0.14.0)
|
24
|
+
arel (7.1.4)
|
25
|
+
concurrent-ruby (1.1.5)
|
26
|
+
diff-lcs (1.3)
|
27
|
+
i18n (0.9.5)
|
28
|
+
concurrent-ruby (~> 1.0)
|
29
|
+
minitest (5.11.3)
|
30
|
+
rake (10.5.0)
|
31
|
+
rspec (3.8.0)
|
32
|
+
rspec-core (~> 3.8.0)
|
33
|
+
rspec-expectations (~> 3.8.0)
|
34
|
+
rspec-mocks (~> 3.8.0)
|
35
|
+
rspec-core (3.8.0)
|
36
|
+
rspec-support (~> 3.8.0)
|
37
|
+
rspec-expectations (3.8.3)
|
38
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
39
|
+
rspec-support (~> 3.8.0)
|
40
|
+
rspec-mocks (3.8.0)
|
41
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
42
|
+
rspec-support (~> 3.8.0)
|
43
|
+
rspec-support (3.8.0)
|
44
|
+
sqlite3 (1.3.13)
|
45
|
+
thor (0.20.3)
|
46
|
+
thread_safe (0.3.6)
|
47
|
+
tzinfo (1.2.5)
|
48
|
+
thread_safe (~> 0.1)
|
49
|
+
|
50
|
+
PLATFORMS
|
51
|
+
ruby
|
52
|
+
|
53
|
+
DEPENDENCIES
|
54
|
+
activerecord (~> 5.0.0)
|
55
|
+
appraisal
|
56
|
+
array_to_activerecord!
|
57
|
+
bundler
|
58
|
+
rake (~> 10.0)
|
59
|
+
rspec (~> 3.0)
|
60
|
+
sqlite3 (~> 1.3.6)
|
61
|
+
|
62
|
+
BUNDLED WITH
|
63
|
+
1.16.1
|
@@ -0,0 +1,63 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ..
|
3
|
+
specs:
|
4
|
+
array_to_activerecord (1.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
activemodel (5.1.6)
|
10
|
+
activesupport (= 5.1.6)
|
11
|
+
activerecord (5.1.6)
|
12
|
+
activemodel (= 5.1.6)
|
13
|
+
activesupport (= 5.1.6)
|
14
|
+
arel (~> 8.0)
|
15
|
+
activesupport (5.1.6)
|
16
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
17
|
+
i18n (>= 0.7, < 2)
|
18
|
+
minitest (~> 5.1)
|
19
|
+
tzinfo (~> 1.1)
|
20
|
+
appraisal (2.2.0)
|
21
|
+
bundler
|
22
|
+
rake
|
23
|
+
thor (>= 0.14.0)
|
24
|
+
arel (8.0.0)
|
25
|
+
concurrent-ruby (1.1.5)
|
26
|
+
diff-lcs (1.3)
|
27
|
+
i18n (1.6.0)
|
28
|
+
concurrent-ruby (~> 1.0)
|
29
|
+
minitest (5.11.3)
|
30
|
+
rake (10.5.0)
|
31
|
+
rspec (3.8.0)
|
32
|
+
rspec-core (~> 3.8.0)
|
33
|
+
rspec-expectations (~> 3.8.0)
|
34
|
+
rspec-mocks (~> 3.8.0)
|
35
|
+
rspec-core (3.8.0)
|
36
|
+
rspec-support (~> 3.8.0)
|
37
|
+
rspec-expectations (3.8.3)
|
38
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
39
|
+
rspec-support (~> 3.8.0)
|
40
|
+
rspec-mocks (3.8.0)
|
41
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
42
|
+
rspec-support (~> 3.8.0)
|
43
|
+
rspec-support (3.8.0)
|
44
|
+
sqlite3 (1.3.13)
|
45
|
+
thor (0.20.3)
|
46
|
+
thread_safe (0.3.6)
|
47
|
+
tzinfo (1.2.5)
|
48
|
+
thread_safe (~> 0.1)
|
49
|
+
|
50
|
+
PLATFORMS
|
51
|
+
ruby
|
52
|
+
|
53
|
+
DEPENDENCIES
|
54
|
+
activerecord (~> 5.1.0)
|
55
|
+
appraisal
|
56
|
+
array_to_activerecord!
|
57
|
+
bundler
|
58
|
+
rake (~> 10.0)
|
59
|
+
rspec (~> 3.0)
|
60
|
+
sqlite3 (~> 1.3.6)
|
61
|
+
|
62
|
+
BUNDLED WITH
|
63
|
+
1.16.1
|
@@ -0,0 +1,63 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ..
|
3
|
+
specs:
|
4
|
+
array_to_activerecord (1.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
activemodel (5.2.3)
|
10
|
+
activesupport (= 5.2.3)
|
11
|
+
activerecord (5.2.3)
|
12
|
+
activemodel (= 5.2.3)
|
13
|
+
activesupport (= 5.2.3)
|
14
|
+
arel (>= 9.0)
|
15
|
+
activesupport (5.2.3)
|
16
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
17
|
+
i18n (>= 0.7, < 2)
|
18
|
+
minitest (~> 5.1)
|
19
|
+
tzinfo (~> 1.1)
|
20
|
+
appraisal (2.2.0)
|
21
|
+
bundler
|
22
|
+
rake
|
23
|
+
thor (>= 0.14.0)
|
24
|
+
arel (9.0.0)
|
25
|
+
concurrent-ruby (1.1.5)
|
26
|
+
diff-lcs (1.3)
|
27
|
+
i18n (1.6.0)
|
28
|
+
concurrent-ruby (~> 1.0)
|
29
|
+
minitest (5.11.3)
|
30
|
+
rake (10.5.0)
|
31
|
+
rspec (3.8.0)
|
32
|
+
rspec-core (~> 3.8.0)
|
33
|
+
rspec-expectations (~> 3.8.0)
|
34
|
+
rspec-mocks (~> 3.8.0)
|
35
|
+
rspec-core (3.8.0)
|
36
|
+
rspec-support (~> 3.8.0)
|
37
|
+
rspec-expectations (3.8.3)
|
38
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
39
|
+
rspec-support (~> 3.8.0)
|
40
|
+
rspec-mocks (3.8.0)
|
41
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
42
|
+
rspec-support (~> 3.8.0)
|
43
|
+
rspec-support (3.8.0)
|
44
|
+
sqlite3 (1.3.13)
|
45
|
+
thor (0.20.3)
|
46
|
+
thread_safe (0.3.6)
|
47
|
+
tzinfo (1.2.5)
|
48
|
+
thread_safe (~> 0.1)
|
49
|
+
|
50
|
+
PLATFORMS
|
51
|
+
ruby
|
52
|
+
|
53
|
+
DEPENDENCIES
|
54
|
+
activerecord (~> 5.2.0)
|
55
|
+
appraisal
|
56
|
+
array_to_activerecord!
|
57
|
+
bundler
|
58
|
+
rake (~> 10.0)
|
59
|
+
rspec (~> 3.0)
|
60
|
+
sqlite3 (~> 1.3.6)
|
61
|
+
|
62
|
+
BUNDLED WITH
|
63
|
+
1.16.1
|
@@ -0,0 +1,63 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ..
|
3
|
+
specs:
|
4
|
+
array_to_activerecord (1.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
activemodel (6.0.0.rc1)
|
10
|
+
activesupport (= 6.0.0.rc1)
|
11
|
+
activerecord (6.0.0.rc1)
|
12
|
+
activemodel (= 6.0.0.rc1)
|
13
|
+
activesupport (= 6.0.0.rc1)
|
14
|
+
activesupport (6.0.0.rc1)
|
15
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
16
|
+
i18n (>= 0.7, < 2)
|
17
|
+
minitest (~> 5.1)
|
18
|
+
tzinfo (~> 1.1)
|
19
|
+
zeitwerk (~> 2.1, >= 2.1.4)
|
20
|
+
appraisal (2.2.0)
|
21
|
+
bundler
|
22
|
+
rake
|
23
|
+
thor (>= 0.14.0)
|
24
|
+
concurrent-ruby (1.1.5)
|
25
|
+
diff-lcs (1.3)
|
26
|
+
i18n (1.6.0)
|
27
|
+
concurrent-ruby (~> 1.0)
|
28
|
+
minitest (5.11.3)
|
29
|
+
rake (10.5.0)
|
30
|
+
rspec (3.8.0)
|
31
|
+
rspec-core (~> 3.8.0)
|
32
|
+
rspec-expectations (~> 3.8.0)
|
33
|
+
rspec-mocks (~> 3.8.0)
|
34
|
+
rspec-core (3.8.0)
|
35
|
+
rspec-support (~> 3.8.0)
|
36
|
+
rspec-expectations (3.8.3)
|
37
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
38
|
+
rspec-support (~> 3.8.0)
|
39
|
+
rspec-mocks (3.8.0)
|
40
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
41
|
+
rspec-support (~> 3.8.0)
|
42
|
+
rspec-support (3.8.0)
|
43
|
+
sqlite3 (1.4.1)
|
44
|
+
thor (0.20.3)
|
45
|
+
thread_safe (0.3.6)
|
46
|
+
tzinfo (1.2.5)
|
47
|
+
thread_safe (~> 0.1)
|
48
|
+
zeitwerk (2.1.6)
|
49
|
+
|
50
|
+
PLATFORMS
|
51
|
+
ruby
|
52
|
+
|
53
|
+
DEPENDENCIES
|
54
|
+
activerecord (~> 6.0.0.rc1)
|
55
|
+
appraisal
|
56
|
+
array_to_activerecord!
|
57
|
+
bundler
|
58
|
+
rake (~> 10.0)
|
59
|
+
rspec (~> 3.0)
|
60
|
+
sqlite3 (~> 1.4)
|
61
|
+
|
62
|
+
BUNDLED WITH
|
63
|
+
1.16.1
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require "active_record"
|
2
|
+
|
3
|
+
module ArrayToActiveRecord
|
4
|
+
def self.convert(array, model_class: nil)
|
5
|
+
model_class = determine(array) if model_class.nil?
|
6
|
+
|
7
|
+
Converter.new(model_class).convert(array)
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def self.determine(array)
|
13
|
+
model = array[0] if array.is_a? Array
|
14
|
+
|
15
|
+
unless model.is_a? ActiveRecord::Base
|
16
|
+
raise(ArgumentError,
|
17
|
+
"Failed to determine model_class because array is empty, " \
|
18
|
+
"or array item is non ActiveRecord model. " \
|
19
|
+
"You can resolve by using model_class option"
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
model.class
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
module ArrayToActiveRecord
|
28
|
+
class Converter
|
29
|
+
def initialize(model_class)
|
30
|
+
@model_class = model_class
|
31
|
+
end
|
32
|
+
|
33
|
+
def convert(array)
|
34
|
+
@relation = new_relation
|
35
|
+
@relation = @relation.where(id: array.map(&:id)) # add query info used by `to_sql` method etc.
|
36
|
+
load_records(array)
|
37
|
+
|
38
|
+
@relation
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def new_relation
|
44
|
+
@model_class.all
|
45
|
+
end
|
46
|
+
|
47
|
+
def load_records(array)
|
48
|
+
v5_0 = Gem::Version.create("5.0")
|
49
|
+
v4_0 = Gem::Version.create("4.0")
|
50
|
+
|
51
|
+
if v5_0 < activerecord_version
|
52
|
+
@relation.send(:load_records, array)
|
53
|
+
elsif v4_0 < activerecord_version
|
54
|
+
@relation.instance_variable_set(:@records, array)
|
55
|
+
@relation.instance_variable_set(:@loaded, true)
|
56
|
+
else
|
57
|
+
raise "ActiveRecord version #{ActiveRecord.gem_version} is not supported"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def activerecord_version
|
62
|
+
return @activerecord_version if @activerecord_version
|
63
|
+
|
64
|
+
if ActiveRecord.respond_to? :gem_version # version 5.0 ~
|
65
|
+
@activerecord_version = ActiveRecord.gem_version
|
66
|
+
elsif ActiveRecord.respond_to? :version # version 4.0 ~
|
67
|
+
@activerecord_version = ActiveRecord.version
|
68
|
+
else
|
69
|
+
@activerecord_version = nil
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
metadata
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: array_to_activerecord
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- potato2003
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-06-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activerecord
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: appraisal
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: sqlite3
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Convert Array to ActiveRecord::Relation without database access
|
98
|
+
email:
|
99
|
+
- potato2003@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
|
+
- ".travis.yml"
|
107
|
+
- Appraisals
|
108
|
+
- Gemfile
|
109
|
+
- LICENSE
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- array_to_activerecord.gemspec
|
113
|
+
- bin/console
|
114
|
+
- bin/setup
|
115
|
+
- gemfiles/.bundle/config
|
116
|
+
- gemfiles/rails40.gemfile
|
117
|
+
- gemfiles/rails40.gemfile.lock
|
118
|
+
- gemfiles/rails41.gemfile
|
119
|
+
- gemfiles/rails41.gemfile.lock
|
120
|
+
- gemfiles/rails42.gemfile
|
121
|
+
- gemfiles/rails42.gemfile.lock
|
122
|
+
- gemfiles/rails50.gemfile
|
123
|
+
- gemfiles/rails50.gemfile.lock
|
124
|
+
- gemfiles/rails51.gemfile
|
125
|
+
- gemfiles/rails51.gemfile.lock
|
126
|
+
- gemfiles/rails52.gemfile
|
127
|
+
- gemfiles/rails52.gemfile.lock
|
128
|
+
- gemfiles/rails60.rc1.gemfile
|
129
|
+
- gemfiles/rails60.rc1.gemfile.lock
|
130
|
+
- lib/array_to_activerecord.rb
|
131
|
+
homepage: https://github.com/potato2003/array_to_activerecord
|
132
|
+
licenses:
|
133
|
+
- MIT
|
134
|
+
metadata: {}
|
135
|
+
post_install_message:
|
136
|
+
rdoc_options: []
|
137
|
+
require_paths:
|
138
|
+
- lib
|
139
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
requirements: []
|
150
|
+
rubyforge_project:
|
151
|
+
rubygems_version: 2.7.6
|
152
|
+
signing_key:
|
153
|
+
specification_version: 4
|
154
|
+
summary: Convert Array to ActiveRecord::Relation without database access
|
155
|
+
test_files: []
|