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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d4f255600fa5cb8f4336cc17650b0c0682f3f4fd
4
- data.tar.gz: e5edfd4e8d679b64a8b00868ce72518b9befdc8e
3
+ metadata.gz: 4963eb4da7b783327836db19c6604e921e5ca428
4
+ data.tar.gz: 3d7dc7796866cb84cae35672e59da4970e9b7e38
5
5
  SHA512:
6
- metadata.gz: 70e1b4e04ffb1363313d9e8e8f216a52e421a32f23f5a195e80776e379425cef397a0c5f76cef8a14df9c2468f3e7ebc79839e31aa329fb2452ce4a666103a95
7
- data.tar.gz: 3bcbd55e0b332cdbf28c54f5225aa50557780ba667e891e8ddcbabc435a0057c8af85daca3df53492042fd4e6219aee3c72d6254113aa389e31e1118e78268bb
6
+ metadata.gz: e8c4bef54ddaf717d98c8f0f0c83dc6fb62a9bb791630c5bcf268ab5779b5eccb64954dbb8dc8a79a46f264623f61940b8162845ce847fc930831147f0d263a4
7
+ data.tar.gz: 84e68974fcbdc0abc511ef87cc7290793b0375bc6d85f6c452b5300b318be4a07c23450bf94f402f41c31700bf20b3d683a2df577f8ceb75c7647f26ad8330f9
@@ -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
 
@@ -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(*args)
10
- # Extract `opts` (defaults could be merged here in the future)
11
- opts = args.last.is_a?(Hash) ? args.pop : {}
12
-
13
- # Maintains legacy support, the previous interface expected an `Array`
14
- # as the first argument
15
- column_names = args.flatten
16
-
17
- # If no `opts` is empty and there was only one `column_name` specified
18
- # fall back to the default `pluck` implementation
19
- return single_column_pluck(column_names.first) \
20
- if column_names.size == 1 && opts.empty?
21
-
22
- # Since `column_names` can be symbols `stringify` them here
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
@@ -1,3 +1,3 @@
1
1
  module Multipluck
2
- VERSION = '0.0.5'
2
+ VERSION = '1.0.1'
3
3
  end
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: 0.0.5
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: 2014-12-17 00:00:00.000000000 Z
12
+ date: 2015-01-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails