pluck_all 2.2.1 → 2.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +116 -0
- data/.gitignore +10 -10
- data/.rubocop.yml +1227 -1227
- data/CHANGELOG.md +12 -0
- data/CODE_OF_CONDUCT.md +48 -48
- data/LICENSE.txt +21 -21
- data/README.md +187 -167
- data/Rakefile +22 -22
- data/bin/console +14 -14
- data/bin/setup +8 -8
- data/gemfiles/active_record_32.gemfile +16 -13
- data/gemfiles/active_record_42.gemfile +18 -13
- data/gemfiles/active_record_50.gemfile +18 -13
- data/gemfiles/active_record_51.gemfile +18 -13
- data/gemfiles/active_record_52.gemfile +18 -13
- data/gemfiles/active_record_60.gemfile +18 -13
- data/gemfiles/active_record_61.gemfile +18 -13
- data/gemfiles/mongoid_54.gemfile +11 -11
- data/gemfiles/mongoid_64.gemfile +11 -11
- data/gemfiles/{mongoid_70.gemfile → mongoid_73.gemfile} +11 -11
- data/lib/pluck_all/hooks.rb +21 -21
- data/lib/pluck_all/models/active_record_extension.rb +138 -131
- data/lib/pluck_all/models/mongoid_extension.rb +88 -70
- data/lib/pluck_all/models/patches/deserialize.rb +13 -13
- data/lib/pluck_all/version.rb +4 -4
- data/lib/pluck_all.rb +3 -3
- data/pluck_all.gemspec +43 -43
- metadata +7 -7
- data/.travis.yml +0 -73
@@ -1,70 +1,88 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
module Mongoid
|
3
|
-
module Document::ClassMethods
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
def
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
def
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Mongoid
|
3
|
+
module Document::ClassMethods
|
4
|
+
if defined?(Mongoid::Errors::CriteriaArgumentRequired)
|
5
|
+
def pluck_array(*fields)
|
6
|
+
where.pluck_array(*fields)
|
7
|
+
end
|
8
|
+
|
9
|
+
def pluck_all(*fields)
|
10
|
+
where.pluck_all(*fields)
|
11
|
+
end
|
12
|
+
else
|
13
|
+
def pluck_array(*fields)
|
14
|
+
where(nil).pluck_array(*fields)
|
15
|
+
end
|
16
|
+
|
17
|
+
def pluck_all(*fields)
|
18
|
+
where(nil).pluck_all(*fields)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
module Findable
|
24
|
+
if singleton_class < Forwardable
|
25
|
+
def_delegators :with_default_scope, :pluck_all, :pluck_array
|
26
|
+
else
|
27
|
+
delegate :pluck_all, :pluck_array, to: :with_default_scope
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
module Contextual
|
32
|
+
if singleton_class < Forwardable
|
33
|
+
def_delegators :context, :pluck_all, :pluck_array
|
34
|
+
else
|
35
|
+
delegate :pluck_all, :pluck_array, to: :context
|
36
|
+
end
|
37
|
+
|
38
|
+
class None
|
39
|
+
def pluck_array(*)
|
40
|
+
[]
|
41
|
+
end
|
42
|
+
|
43
|
+
def pluck_all(*)
|
44
|
+
[]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class Mongo
|
49
|
+
def pluck_array(*fields)
|
50
|
+
normalized_select = get_normalized_select(fields)
|
51
|
+
get_query_data(normalized_select).reduce([]) do |plucked, doc|
|
52
|
+
values = normalized_select.keys.map(&plucked_value_mapper(:array, doc))
|
53
|
+
plucked << (values.size == 1 ? values.first : values)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def pluck_all(*fields)
|
58
|
+
normalized_select = get_normalized_select(fields)
|
59
|
+
get_query_data(normalized_select).reduce([]) do |plucked, doc|
|
60
|
+
values = normalized_select.keys.map(&plucked_value_mapper(:all, doc))
|
61
|
+
plucked << values.to_h
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def plucked_value_mapper(type, doc)
|
68
|
+
proc do |n|
|
69
|
+
values = [n, n =~ /\./ ? doc[n.partition('.')[0]] : doc[n]]
|
70
|
+
case type
|
71
|
+
when :array then values[1]
|
72
|
+
when :all then values
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def get_query_data(normalized_select)
|
78
|
+
return (@view ? @view.projection(normalized_select) : query.dup.select(normalized_select))
|
79
|
+
end
|
80
|
+
|
81
|
+
def get_normalized_select(fields)
|
82
|
+
fields.each_with_object({}) do |f, hash|
|
83
|
+
hash[klass.database_field_name(f)] = 1
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -1,13 +1,13 @@
|
|
1
|
-
module ActiveRecord
|
2
|
-
[
|
3
|
-
*([Type::Value, Type::Integer, Type::Serialized] if defined?(Type::Value)),
|
4
|
-
*([Enum::EnumType] if defined?(Enum::EnumType)),
|
5
|
-
].each do |s|
|
6
|
-
s.class_eval do
|
7
|
-
if !method_defined?(:deserialize) && method_defined?(:type_cast_from_database)
|
8
|
-
# deserialize was changed to type_cast_from_database in Rails 5
|
9
|
-
alias_method :deserialize, :type_cast_from_database
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
1
|
+
module ActiveRecord
|
2
|
+
[
|
3
|
+
*([Type::Value, Type::Integer, Type::Serialized] if defined?(Type::Value)),
|
4
|
+
*([Enum::EnumType] if defined?(Enum::EnumType)),
|
5
|
+
].each do |s|
|
6
|
+
s.class_eval do
|
7
|
+
if !method_defined?(:deserialize) && method_defined?(:type_cast_from_database)
|
8
|
+
# deserialize was changed to type_cast_from_database in Rails 5
|
9
|
+
alias_method :deserialize, :type_cast_from_database
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/pluck_all/version.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
module PluckAll
|
3
|
-
VERSION = '2.
|
4
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module PluckAll
|
3
|
+
VERSION = '2.3.3'
|
4
|
+
end
|
data/lib/pluck_all.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require 'pluck_all/version'
|
3
|
-
require 'pluck_all/hooks'
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'pluck_all/version'
|
3
|
+
require 'pluck_all/hooks'
|
data/pluck_all.gemspec
CHANGED
@@ -1,43 +1,43 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'pluck_all/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = 'pluck_all'
|
8
|
-
spec.version = PluckAll::VERSION
|
9
|
-
spec.authors = ['khiav reoy']
|
10
|
-
spec.email = ['mrtmrt15xn@yahoo.com.tw']
|
11
|
-
|
12
|
-
spec.summary = 'Pluck multiple columns/attributes and return array of hashes. Support Rails 3, 4, 5.'
|
13
|
-
spec.description = 'Pluck multiple columns/attributes and return array of hashes. Support Rails 3, 4, 5. If you have a Rails 3 project, and want to pluck not only one column, feel free to use this gem and no need to worry about upgrading to Rails 4, 5 in the future will break this.'
|
14
|
-
spec.homepage = 'https://github.com/khiav223577/pluck_all'
|
15
|
-
spec.license = 'MIT'
|
16
|
-
|
17
|
-
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
-
# delete this section to allow pushing this gem to any host.
|
19
|
-
# if spec.respond_to?(:metadata)
|
20
|
-
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
-
# else
|
22
|
-
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
-
# end
|
24
|
-
|
25
|
-
spec.files = `git ls-files -z`.split("\x0").reject{|f| f.match(%r{^(test|spec|features)/}) }
|
26
|
-
spec.bindir = 'exe'
|
27
|
-
spec.executables = spec.files.grep(%r{^exe/}){|f| File.basename(f) }
|
28
|
-
spec.require_paths = ['lib']
|
29
|
-
spec.metadata = {
|
30
|
-
'homepage_uri' => 'https://github.com/khiav223577/pluck_all',
|
31
|
-
'changelog_uri' => 'https://github.com/khiav223577/pluck_all/blob/master/CHANGELOG.md',
|
32
|
-
'source_code_uri' => 'https://github.com/khiav223577/pluck_all',
|
33
|
-
'documentation_uri' => 'https://www.rubydoc.info/gems/pluck_all',
|
34
|
-
'bug_tracker_uri' => 'https://github.com/khiav223577/pluck_all/issues',
|
35
|
-
}
|
36
|
-
|
37
|
-
spec.add_dependency 'activesupport', '>= 3.0.0'
|
38
|
-
spec.add_dependency 'rails_compatibility', '>= 0.0.
|
39
|
-
|
40
|
-
spec.add_development_dependency 'bundler', '>= 1.17', '< 3.x'
|
41
|
-
spec.add_development_dependency 'rake', '~> 12.0'
|
42
|
-
spec.add_development_dependency 'minitest', '~> 5.0'
|
43
|
-
end
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'pluck_all/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'pluck_all'
|
8
|
+
spec.version = PluckAll::VERSION
|
9
|
+
spec.authors = ['khiav reoy']
|
10
|
+
spec.email = ['mrtmrt15xn@yahoo.com.tw']
|
11
|
+
|
12
|
+
spec.summary = 'Pluck multiple columns/attributes and return array of hashes. Support Rails 3, 4, 5.'
|
13
|
+
spec.description = 'Pluck multiple columns/attributes and return array of hashes. Support Rails 3, 4, 5. If you have a Rails 3 project, and want to pluck not only one column, feel free to use this gem and no need to worry about upgrading to Rails 4, 5 in the future will break this.'
|
14
|
+
spec.homepage = 'https://github.com/khiav223577/pluck_all'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
# if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
+
# else
|
22
|
+
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
# end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject{|f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = 'exe'
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}){|f| File.basename(f) }
|
28
|
+
spec.require_paths = ['lib']
|
29
|
+
spec.metadata = {
|
30
|
+
'homepage_uri' => 'https://github.com/khiav223577/pluck_all',
|
31
|
+
'changelog_uri' => 'https://github.com/khiav223577/pluck_all/blob/master/CHANGELOG.md',
|
32
|
+
'source_code_uri' => 'https://github.com/khiav223577/pluck_all',
|
33
|
+
'documentation_uri' => 'https://www.rubydoc.info/gems/pluck_all',
|
34
|
+
'bug_tracker_uri' => 'https://github.com/khiav223577/pluck_all/issues',
|
35
|
+
}
|
36
|
+
|
37
|
+
spec.add_dependency 'activesupport', '>= 3.0.0'
|
38
|
+
spec.add_dependency 'rails_compatibility', '>= 0.0.7'
|
39
|
+
|
40
|
+
spec.add_development_dependency 'bundler', '>= 1.17', '< 3.x'
|
41
|
+
spec.add_development_dependency 'rake', '~> 12.0'
|
42
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
43
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pluck_all
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- khiav reoy
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.0.
|
33
|
+
version: 0.0.7
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.0.
|
40
|
+
version: 0.0.7
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -96,9 +96,9 @@ executables: []
|
|
96
96
|
extensions: []
|
97
97
|
extra_rdoc_files: []
|
98
98
|
files:
|
99
|
+
- ".github/workflows/ruby.yml"
|
99
100
|
- ".gitignore"
|
100
101
|
- ".rubocop.yml"
|
101
|
-
- ".travis.yml"
|
102
102
|
- CHANGELOG.md
|
103
103
|
- CODE_OF_CONDUCT.md
|
104
104
|
- LICENSE.txt
|
@@ -115,7 +115,7 @@ files:
|
|
115
115
|
- gemfiles/active_record_61.gemfile
|
116
116
|
- gemfiles/mongoid_54.gemfile
|
117
117
|
- gemfiles/mongoid_64.gemfile
|
118
|
-
- gemfiles/
|
118
|
+
- gemfiles/mongoid_73.gemfile
|
119
119
|
- lib/pluck_all.rb
|
120
120
|
- lib/pluck_all/hooks.rb
|
121
121
|
- lib/pluck_all/models/active_record_extension.rb
|
@@ -147,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
147
147
|
- !ruby/object:Gem::Version
|
148
148
|
version: '0'
|
149
149
|
requirements: []
|
150
|
-
rubygems_version: 3.
|
150
|
+
rubygems_version: 3.2.14
|
151
151
|
signing_key:
|
152
152
|
specification_version: 4
|
153
153
|
summary: Pluck multiple columns/attributes and return array of hashes. Support Rails
|
data/.travis.yml
DELETED
@@ -1,73 +0,0 @@
|
|
1
|
-
sudo: false
|
2
|
-
language: ruby
|
3
|
-
rvm:
|
4
|
-
- 2.2
|
5
|
-
- 2.6
|
6
|
-
- 2.7
|
7
|
-
services:
|
8
|
-
- mongodb
|
9
|
-
env:
|
10
|
-
global:
|
11
|
-
- CC_TEST_REPORTER_ID=db72eba1ff8fb1329dae5fb9b9dcd234243899d7a464ceb374e14a05ead27b7c
|
12
|
-
matrix:
|
13
|
-
- ORM_TYPE=ACTIVE_RECORD
|
14
|
-
- ORM_TYPE=MONGOID
|
15
|
-
gemfile:
|
16
|
-
- gemfiles/active_record_32.gemfile
|
17
|
-
- gemfiles/active_record_42.gemfile
|
18
|
-
- gemfiles/active_record_50.gemfile
|
19
|
-
- gemfiles/active_record_51.gemfile
|
20
|
-
- gemfiles/active_record_52.gemfile
|
21
|
-
- gemfiles/active_record_60.gemfile
|
22
|
-
- gemfiles/active_record_61.gemfile
|
23
|
-
- gemfiles/mongoid_54.gemfile
|
24
|
-
- gemfiles/mongoid_64.gemfile
|
25
|
-
- gemfiles/mongoid_70.gemfile
|
26
|
-
matrix:
|
27
|
-
exclude:
|
28
|
-
- gemfile: gemfiles/active_record_32.gemfile
|
29
|
-
rvm: 2.6
|
30
|
-
- gemfile: gemfiles/active_record_32.gemfile
|
31
|
-
rvm: 2.7
|
32
|
-
- gemfile: gemfiles/active_record_32.gemfile
|
33
|
-
env: ORM_TYPE=MONGOID
|
34
|
-
- gemfile: gemfiles/active_record_42.gemfile
|
35
|
-
rvm: 2.7
|
36
|
-
- gemfile: gemfiles/active_record_42.gemfile
|
37
|
-
env: ORM_TYPE=MONGOID
|
38
|
-
- gemfile: gemfiles/active_record_50.gemfile
|
39
|
-
env: ORM_TYPE=MONGOID
|
40
|
-
- gemfile: gemfiles/active_record_51.gemfile
|
41
|
-
env: ORM_TYPE=MONGOID
|
42
|
-
- gemfile: gemfiles/active_record_52.gemfile
|
43
|
-
env: ORM_TYPE=MONGOID
|
44
|
-
- gemfile: gemfiles/active_record_60.gemfile
|
45
|
-
rvm: 2.2
|
46
|
-
- gemfile: gemfiles/active_record_60.gemfile
|
47
|
-
env: ORM_TYPE=MONGOID
|
48
|
-
- gemfile: gemfiles/active_record_61.gemfile
|
49
|
-
rvm: 2.2
|
50
|
-
- gemfile: gemfiles/active_record_61.gemfile
|
51
|
-
env: ORM_TYPE=MONGOID
|
52
|
-
- gemfile: gemfiles/mongoid_54.gemfile
|
53
|
-
rvm: 2.7
|
54
|
-
- gemfile: gemfiles/mongoid_54.gemfile
|
55
|
-
env: ORM_TYPE=ACTIVE_RECORD
|
56
|
-
- gemfile: gemfiles/mongoid_64.gemfile
|
57
|
-
env: ORM_TYPE=ACTIVE_RECORD
|
58
|
-
- gemfile: gemfiles/mongoid_70.gemfile
|
59
|
-
env: ORM_TYPE=ACTIVE_RECORD
|
60
|
-
before_install:
|
61
|
-
- if `ruby -e 'exit(RUBY_VERSION.to_f < 2.7)'`; then
|
62
|
-
gem i rubygems-update -v '< 3' && update_rubygems;
|
63
|
-
gem install bundler -v '< 2';
|
64
|
-
fi
|
65
|
-
- gem --version
|
66
|
-
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
67
|
-
- chmod +x ./cc-test-reporter
|
68
|
-
- ./cc-test-reporter before-build
|
69
|
-
script:
|
70
|
-
- if [ "$ORM_TYPE" = "ACTIVE_RECORD" ]; then bundle exec rake test_active_record; fi
|
71
|
-
- if [ "$ORM_TYPE" = "MONGOID" ]; then bundle exec rake test_mongoid; fi
|
72
|
-
after_script:
|
73
|
-
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|