multipluck 0.0.5 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -4
- data/lib/multipluck/pluck.rb +14 -24
- data/lib/multipluck/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4963eb4da7b783327836db19c6604e921e5ca428
|
4
|
+
data.tar.gz: 3d7dc7796866cb84cae35672e59da4970e9b7e38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8c4bef54ddaf717d98c8f0f0c83dc6fb62a9bb791630c5bcf268ab5779b5eccb64954dbb8dc8a79a46f264623f61940b8162845ce847fc930831147f0d263a4
|
7
|
+
data.tar.gz: 84e68974fcbdc0abc511ef87cc7290793b0375bc6d85f6c452b5300b318be4a07c23450bf94f402f41c31700bf20b3d683a2df577f8ceb75c7647f26ad8330f9
|
data/.travis.yml
CHANGED
@@ -2,20 +2,16 @@ language: ruby
|
|
2
2
|
|
3
3
|
matrix:
|
4
4
|
allow_failures:
|
5
|
-
- rvm: jruby-18mode
|
6
5
|
- rvm: jruby-19mode
|
7
6
|
- rvm: rbx-2
|
8
7
|
|
9
8
|
rvm:
|
10
|
-
- 1.8.7
|
11
|
-
- 1.9.2
|
12
9
|
- 1.9.3
|
13
10
|
- 2.0.0
|
14
11
|
- 2.1.0
|
15
12
|
- 2.1.1
|
16
13
|
- 2.1.2
|
17
14
|
- 2.1.3
|
18
|
-
- jruby-18mode
|
19
15
|
- jruby-19mode
|
20
16
|
- rbx-2
|
21
17
|
|
data/lib/multipluck/pluck.rb
CHANGED
@@ -6,30 +6,20 @@ module Multipluck
|
|
6
6
|
# Preserve the original `pluck` functionality
|
7
7
|
alias_method :single_column_pluck, :pluck
|
8
8
|
|
9
|
-
def pluck(*
|
10
|
-
#
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
#
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
#
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
column_names.map!(&:to_s)
|
24
|
-
|
25
|
-
# Yields an `Array` of `Hash(es)`
|
26
|
-
rows = klass.connection.select_all(select(column_names).arel)
|
27
|
-
|
28
|
-
# Row is a `Hash` of: 'column_name' => value
|
29
|
-
rows.map! do |row|
|
30
|
-
attrs = klass.initialize_attributes(row)
|
31
|
-
column_names.map do |col_name|
|
32
|
-
klass.type_cast_attribute(col_name, attrs)
|
9
|
+
def pluck(*column_names)
|
10
|
+
# Yields an `Array` of `String` column-names (maintains legacy support,
|
11
|
+
# the previous interface expected an `Array` as the first argument)
|
12
|
+
column_names = Array(column_names.flatten).map(&:to_s)
|
13
|
+
|
14
|
+
# If there was only one `column_name` specified fall back to the default
|
15
|
+
# `pluck` implementation
|
16
|
+
return single_column_pluck(column_names.first) if column_names.size == 1
|
17
|
+
|
18
|
+
# Fetch and map rows (yields an `Array` of `Array(s)`)
|
19
|
+
klass.connection.select_all(select(column_names).arel).map! do |row|
|
20
|
+
attributes = klass.initialize_attributes(row)
|
21
|
+
column_names.map do |column_name|
|
22
|
+
klass.type_cast_attribute(column_name, attributes)
|
33
23
|
end
|
34
24
|
end
|
35
25
|
end
|
data/lib/multipluck/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: multipluck
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan W. Zaleski
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2015-01-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|