multipluck 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d4f255600fa5cb8f4336cc17650b0c0682f3f4fd
4
+ data.tar.gz: e5edfd4e8d679b64a8b00868ce72518b9befdc8e
5
+ SHA512:
6
+ metadata.gz: 70e1b4e04ffb1363313d9e8e8f216a52e421a32f23f5a195e80776e379425cef397a0c5f76cef8a14df9c2468f3e7ebc79839e31aa329fb2452ce4a666103a95
7
+ data.tar.gz: 3bcbd55e0b332cdbf28c54f5225aa50557780ba667e891e8ddcbabc435a0057c8af85daca3df53492042fd4e6219aee3c72d6254113aa389e31e1118e78268bb
@@ -0,0 +1,11 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ test/dummy/db/*.sqlite3
5
+ test/dummy/log/*.log
6
+ test/dummy/tmp/
7
+ test/dummy/.sass-cache
8
+ .idea
9
+ Gemfile.lock
10
+ .ruby-gemset
11
+ .ruby-version
@@ -0,0 +1,23 @@
1
+ language: ruby
2
+
3
+ matrix:
4
+ allow_failures:
5
+ - rvm: jruby-18mode
6
+ - rvm: jruby-19mode
7
+ - rvm: rbx-2
8
+
9
+ rvm:
10
+ - 1.8.7
11
+ - 1.9.2
12
+ - 1.9.3
13
+ - 2.0.0
14
+ - 2.1.0
15
+ - 2.1.1
16
+ - 2.1.2
17
+ - 2.1.3
18
+ - jruby-18mode
19
+ - jruby-19mode
20
+ - rbx-2
21
+
22
+ script:
23
+ - (cd test/dummy && RAILS_ENV=test bundle exec rake --trace db:migrate test)
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ platform :ruby do
7
+ gem 'sqlite3', '~> 1.3'
8
+ end
9
+
10
+ platform :jruby do
11
+ gem 'activerecord-jdbcsqlite3-adapter', '~> 1.3'
12
+ gem 'jdbc-sqlite3', '~> 3.8'
13
+ end
14
+ end
data/README.md CHANGED
@@ -1,27 +1,26 @@
1
- ## Multipluck [![Build Status](https://secure.travis-ci.org/hanzq/multipluck.png)](http://travis-ci.org/hanzq/multipluck)
1
+ ## Multipluck
2
2
 
3
- Multipluck is a Ruby gem for Rails that enhances the .pluck function to select multiple columns.
3
+ [![Build Status](https://travis-ci.org/jzaleski/multipluck.svg)](https://travis-ci.org/jzaleski/multipluck)
4
+ [![Dependency Status](https://gemnasium.com/jzaleski/multipluck.png)](https://gemnasium.com/jzaleski/multipluck)
4
5
 
5
- Currently limited to Rails 3.2.3+, but I plan to change that.
6
+ A Ruby gem for Rails that enhances the `pluck` function to select multiple columns
6
7
 
7
- ### Usage
8
+ ## Usage
8
9
 
9
10
  ```ruby
10
- # Fetch all user ids and names
11
+ # Fetch all user ids and names using var-args
12
+ User.pluck(:id, :name)
13
+ # => [[1, "Bob"], [2, "Simone"], ...]
11
14
 
15
+ # Fetch all user ids and names using an `Array` (legacy)
12
16
  User.pluck([:id, :name])
13
- # => [ [1, "Bob"], [2, "Simone"], ... ]
17
+ # => [[1, "Bob"], [2, "Simone"], ...]
14
18
  ```
15
19
 
16
- ### Installation
20
+ ## Contributing
17
21
 
18
- 1. Add the gem to your Gemfile
19
-
20
- ```ruby
21
- gem 'multipluck'
22
- ```
23
-
24
- 2. Pluck forth!
25
-
26
-
27
- This project rocks and uses MIT-LICENSE. Yes it does.
22
+ 1. Fork it ( http://github.com/jzaleski/multipluck/fork )
23
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
24
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
25
+ 4. Push to the branch (`git push origin my-new-feature`)
26
+ 5. Create new Pull Request
data/Rakefile CHANGED
@@ -1,9 +1,11 @@
1
1
  #!/usr/bin/env rake
2
+
2
3
  begin
3
4
  require 'bundler/setup'
4
5
  rescue LoadError
5
6
  puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
7
  end
8
+
7
9
  begin
8
10
  require 'rdoc/task'
9
11
  rescue LoadError
@@ -14,25 +16,26 @@ end
14
16
 
15
17
  RDoc::Task.new(:rdoc) do |rdoc|
16
18
  rdoc.rdoc_dir = 'rdoc'
17
- rdoc.title = 'Multipluck'
19
+ rdoc.title = 'Multipluck'
18
20
  rdoc.options << '--line-numbers'
19
21
  rdoc.rdoc_files.include('README.md')
20
22
  rdoc.rdoc_files.include('lib/**/*.rb')
21
23
  end
22
24
 
23
-
24
-
25
-
26
25
  Bundler::GemHelper.install_tasks
27
26
 
28
27
  require 'rake/testtask'
29
28
 
30
29
  Rake::TestTask.new(:test) do |t|
31
- t.libs << 'lib'
32
- t.libs << 'test'
30
+ t.libs += %w[lib test]
33
31
  t.pattern = 'test/**/*_test.rb'
34
32
  t.verbose = false
35
33
  end
36
34
 
35
+ def run_rake_task_in_dummy(task)
36
+ abort unless system("cd test/dummy && bundle exec rake #{task}")
37
+ end
38
+
39
+ Dir.glob(File.expand_path('../lib/tasks/*.rake', __FILE__)).each { |f| load f }
37
40
 
38
41
  task :default => :test
@@ -1,21 +1,31 @@
1
-
2
1
  module Multipluck
3
2
  module Pluck
4
3
  extend ActiveSupport::Concern
5
4
 
6
5
  included do
7
- # Preserve the original pluck functionality
6
+ # Preserve the original `pluck` functionality
8
7
  alias_method :single_column_pluck, :pluck
9
8
 
10
- def pluck(column_name_or_array)
11
- return single_column_pluck(column_name_or_array) unless column_name_or_array.instance_of?(Array)
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
12
16
 
13
- column_names = column_name_or_array.map(&:to_s)
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?
14
21
 
15
- # Array of rows
22
+ # Since `column_names` can be symbols `stringify` them here
23
+ column_names.map!(&:to_s)
24
+
25
+ # Yields an `Array` of `Hash(es)`
16
26
  rows = klass.connection.select_all(select(column_names).arel)
17
27
 
18
- # Row is a hash of of 'column_name' => value
28
+ # Row is a `Hash` of: 'column_name' => value
19
29
  rows.map! do |row|
20
30
  attrs = klass.initialize_attributes(row)
21
31
  column_names.map do |col_name|
@@ -23,7 +33,6 @@ module Multipluck
23
33
  end
24
34
  end
25
35
  end
26
-
27
36
  end
28
37
  end
29
38
  end
@@ -1,3 +1,3 @@
1
1
  module Multipluck
2
- VERSION = "0.0.4"
2
+ VERSION = '0.0.5'
3
3
  end
@@ -0,0 +1,22 @@
1
+ namespace :db do
2
+ %w[create drop migrate rollback version].each do |task_name|
3
+ desc "Run db:#{task_name} in the dummy application"
4
+ task task_name.to_sym do
5
+ run_rake_task_in_dummy("db:#{task_name}")
6
+ end
7
+ end
8
+
9
+ namespace :schema do
10
+ desc 'Run db:schema:load in the dummy application'
11
+ task :load do
12
+ run_rake_task_in_dummy('db:schema:load')
13
+ end
14
+ end
15
+
16
+ namespace :test do
17
+ desc 'Run db:test:prepare in the dummy-app'
18
+ task :prepare do
19
+ run_rake_task_in_dummy('db:test:prepare')
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,19 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'multipluck/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = 'multipluck'
8
+ gem.version = Multipluck::VERSION
9
+ gem.authors = ['Jonathan W. Zaleski', 'David Wright']
10
+ gem.email = ['JonathanZaleski@gmail.com']
11
+ gem.homepage = 'https://github.com/jzaleski/multipluck'
12
+ gem.summary = 'A Ruby gem for Rails that enhances the `pluck` function to select multiple columns'
13
+
14
+ gem.files = `git ls-files`.split($/)
15
+ gem.executables = gem.files.grep(%r{^bin/}) { |file| File.basename(file) }
16
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
+
18
+ gem.add_dependency 'rails', '>= 3.2.0', '< 4.0'
19
+ end
@@ -10,6 +10,4 @@
10
10
  // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
11
  // GO AFTER THE REQUIRES BELOW.
12
12
  //
13
- //= require jquery
14
- //= require jquery_ujs
15
13
  //= require_tree .
File without changes
File without changes
@@ -1,25 +1,16 @@
1
- # SQLite version 3.x
2
- # gem install sqlite3
3
- #
4
- # Ensure the SQLite 3 gem is defined in your Gemfile
5
- # gem 'sqlite3'
6
- development:
1
+ shared: &shared
7
2
  adapter: sqlite3
8
- database: db/development.sqlite3
9
3
  pool: 5
10
4
  timeout: 5000
11
5
 
12
- # Warning: The database defined as "test" will be erased and
13
- # re-generated from your development database when you run "rake".
14
- # Do not set this db to the same as development or production.
6
+ development:
7
+ <<: *shared
8
+ database: db/development.sqlite3
9
+
15
10
  test:
16
- adapter: sqlite3
11
+ <<: *shared
17
12
  database: db/test.sqlite3
18
- pool: 5
19
- timeout: 5000
20
13
 
21
14
  production:
22
- adapter: sqlite3
15
+ <<: *shared
23
16
  database: db/production.sqlite3
24
- pool: 5
25
- timeout: 5000
@@ -1,6 +1,6 @@
1
1
  # Be sure to restart your server when you modify this file.
2
2
 
3
- Dummy::Application.config.session_store :cookie_store, key: '_dummy_session'
3
+ Dummy::Application.config.session_store :cookie_store, :key => '_dummy_session'
4
4
 
5
5
  # Use the database for sessions instead of the cookie-based default,
6
6
  # which shouldn't be used to store highly confidential information
@@ -5,7 +5,7 @@
5
5
 
6
6
  # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7
7
  ActiveSupport.on_load(:action_controller) do
8
- wrap_parameters format: [:json]
8
+ wrap_parameters :format => [:json]
9
9
  end
10
10
 
11
11
  # Disable root element in JSON by default.
File without changes
File without changes
@@ -1,33 +1,41 @@
1
- require_relative 'test_helper'
1
+ require 'test_helper'
2
2
 
3
3
  class MultipluckTest < ActiveSupport::TestCase
4
-
5
- test "make sure normal pluck functionality still works" do
6
- Widget.create!(an_int: 5)
4
+ test 'make sure original pluck functionality still works' do
5
+ Widget.create!(:an_int => 5)
7
6
  assert_equal [5], Widget.pluck(:an_int)
8
7
  end
9
8
 
10
- test "normal pluck, multiple rows" do
11
- Widget.create!(an_int: 5)
12
- Widget.create!(an_int: 12)
9
+ test 'normal pluck, multiple rows' do
10
+ Widget.create!(:an_int => 5)
11
+ Widget.create!(:an_int => 12)
13
12
  assert_equal [5, 12], Widget.pluck(:an_int)
14
13
  end
15
14
 
16
- test "same parameter twice" do
17
- Widget.create!(an_int: 5)
18
- assert_equal [[5, 5]], Widget.pluck([:an_int, :an_int])
15
+ test 'multiple parameters in an Array' do
16
+ Widget.create!(:a_string => 'cow', :an_int => 5)
17
+ assert_equal [[5, 'cow']], Widget.pluck([:an_int, :a_string])
18
+ end
19
+
20
+ test 'multiple parameters as Varargs' do
21
+ Widget.create!(:a_string => 'cow', :an_int => 5)
22
+ assert_equal [[5, 'cow']], Widget.pluck(:an_int, :a_string)
19
23
  end
20
24
 
21
- test "multiple parameters" do
22
- Widget.create!(a_string: "cow", an_int: 5)
23
- assert_equal [[5, "cow"]], Widget.pluck([:an_int, :a_string])
24
- assert_equal [["cow", 5]], Widget.pluck([:a_string, :an_int])
25
+ test 'same parameter twice' do
26
+ Widget.create!(:an_int => 5)
27
+ assert_equal [[5, 5]], Widget.pluck(:an_int, :an_int)
25
28
  end
26
29
 
27
- test "multiple parameters / multiple rows" do
28
- Widget.create!(a_string: "cow", an_int: 5)
29
- Widget.create!(a_string: "dog", an_int: 12)
30
- assert_equal [[5,"cow"], [12, "dog"]], Widget.pluck([:an_int, :a_string])
30
+ test 'multiple parameters' do
31
+ Widget.create!(:a_string => 'cow', :an_int => 5)
32
+ assert_equal [[5, 'cow']], Widget.pluck(:an_int, :a_string)
33
+ assert_equal [['cow', 5]], Widget.pluck(:a_string, :an_int)
31
34
  end
32
35
 
36
+ test 'multiple parameters / multiple rows' do
37
+ Widget.create!(:a_string => 'cow', :an_int => 5)
38
+ Widget.create!(:a_string => 'dog', :an_int => 12)
39
+ assert_equal [[5, 'cow'], [12, 'dog']], Widget.pluck(:an_int, :a_string)
40
+ end
33
41
  end
metadata CHANGED
@@ -1,58 +1,65 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multipluck
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
5
- prerelease:
4
+ version: 0.0.5
6
5
  platform: ruby
7
6
  authors:
7
+ - Jonathan W. Zaleski
8
8
  - David Wright
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-24 00:00:00.000000000Z
12
+ date: 2014-12-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &70163287847220 !ruby/object:Gem::Requirement
17
- none: false
16
+ requirement: !ruby/object:Gem::Requirement
18
17
  requirements:
19
- - - ! '>='
18
+ - - '>='
20
19
  - !ruby/object:Gem::Version
21
20
  version: 3.2.0
21
+ - - <
22
+ - !ruby/object:Gem::Version
23
+ version: '4.0'
22
24
  type: :runtime
23
25
  prerelease: false
24
- version_requirements: *70163287847220
25
- - !ruby/object:Gem::Dependency
26
- name: sqlite3
27
- requirement: &70163287846800 !ruby/object:Gem::Requirement
28
- none: false
26
+ version_requirements: !ruby/object:Gem::Requirement
29
27
  requirements:
30
- - - ! '>='
28
+ - - '>='
31
29
  - !ruby/object:Gem::Version
32
- version: '0'
33
- type: :development
34
- prerelease: false
35
- version_requirements: *70163287846800
30
+ version: 3.2.0
31
+ - - <
32
+ - !ruby/object:Gem::Version
33
+ version: '4.0'
36
34
  description:
37
35
  email:
38
- - davidwright@gmail.com
36
+ - JonathanZaleski@gmail.com
39
37
  executables: []
40
38
  extensions: []
41
39
  extra_rdoc_files: []
42
40
  files:
43
- - lib/multipluck/pluck.rb
44
- - lib/multipluck/version.rb
45
- - lib/multipluck.rb
46
- - lib/tasks/multipluck_tasks.rake
41
+ - .gitignore
42
+ - .travis.yml
43
+ - Gemfile
47
44
  - MIT-LICENSE
48
- - Rakefile
49
45
  - README.md
46
+ - Rakefile
47
+ - lib/multipluck.rb
48
+ - lib/multipluck/pluck.rb
49
+ - lib/multipluck/version.rb
50
+ - lib/tasks/db.rake
51
+ - multipluck.gemspec
52
+ - test/dummy/README.rdoc
53
+ - test/dummy/Rakefile
50
54
  - test/dummy/app/assets/javascripts/application.js
51
55
  - test/dummy/app/assets/stylesheets/application.css
52
56
  - test/dummy/app/controllers/application_controller.rb
53
57
  - test/dummy/app/helpers/application_helper.rb
58
+ - test/dummy/app/mailers/.gitkeep
59
+ - test/dummy/app/models/.gitkeep
54
60
  - test/dummy/app/models/widget.rb
55
61
  - test/dummy/app/views/layouts/application.html.erb
62
+ - test/dummy/config.ru
56
63
  - test/dummy/config/application.rb
57
64
  - test/dummy/config/boot.rb
58
65
  - test/dummy/config/database.yml
@@ -68,54 +75,54 @@ files:
68
75
  - test/dummy/config/initializers/wrap_parameters.rb
69
76
  - test/dummy/config/locales/en.yml
70
77
  - test/dummy/config/routes.rb
71
- - test/dummy/config.ru
72
- - test/dummy/db/development.sqlite3
73
78
  - test/dummy/db/migrate/20120422025545_create_widgets.rb
74
79
  - test/dummy/db/schema.rb
75
- - test/dummy/db/test.sqlite3
76
- - test/dummy/log/development.log
77
- - test/dummy/log/test.log
80
+ - test/dummy/lib/assets/.gitkeep
81
+ - test/dummy/log/.gitkeep
78
82
  - test/dummy/public/404.html
79
83
  - test/dummy/public/422.html
80
84
  - test/dummy/public/500.html
81
85
  - test/dummy/public/favicon.ico
82
- - test/dummy/Rakefile
83
- - test/dummy/README.rdoc
84
86
  - test/dummy/script/rails
85
87
  - test/dummy/test/fixtures/widgets.yml
86
88
  - test/multipluck_test.rb
87
89
  - test/test_helper.rb
88
- homepage: https://github.com/hanzq/multipluck
90
+ homepage: https://github.com/jzaleski/multipluck
89
91
  licenses: []
92
+ metadata: {}
90
93
  post_install_message:
91
94
  rdoc_options: []
92
95
  require_paths:
93
96
  - lib
94
97
  required_ruby_version: !ruby/object:Gem::Requirement
95
- none: false
96
98
  requirements:
97
- - - ! '>='
99
+ - - '>='
98
100
  - !ruby/object:Gem::Version
99
101
  version: '0'
100
102
  required_rubygems_version: !ruby/object:Gem::Requirement
101
- none: false
102
103
  requirements:
103
- - - ! '>='
104
+ - - '>='
104
105
  - !ruby/object:Gem::Version
105
106
  version: '0'
106
107
  requirements: []
107
108
  rubyforge_project:
108
- rubygems_version: 1.8.10
109
+ rubygems_version: 2.2.2
109
110
  signing_key:
110
- specification_version: 3
111
- summary: Use the ActiveRecord pluck to pluck multiple columns instead of just one
111
+ specification_version: 4
112
+ summary: A Ruby gem for Rails that enhances the `pluck` function to select multiple
113
+ columns
112
114
  test_files:
115
+ - test/dummy/README.rdoc
116
+ - test/dummy/Rakefile
113
117
  - test/dummy/app/assets/javascripts/application.js
114
118
  - test/dummy/app/assets/stylesheets/application.css
115
119
  - test/dummy/app/controllers/application_controller.rb
116
120
  - test/dummy/app/helpers/application_helper.rb
121
+ - test/dummy/app/mailers/.gitkeep
122
+ - test/dummy/app/models/.gitkeep
117
123
  - test/dummy/app/models/widget.rb
118
124
  - test/dummy/app/views/layouts/application.html.erb
125
+ - test/dummy/config.ru
119
126
  - test/dummy/config/application.rb
120
127
  - test/dummy/config/boot.rb
121
128
  - test/dummy/config/database.yml
@@ -131,19 +138,14 @@ test_files:
131
138
  - test/dummy/config/initializers/wrap_parameters.rb
132
139
  - test/dummy/config/locales/en.yml
133
140
  - test/dummy/config/routes.rb
134
- - test/dummy/config.ru
135
- - test/dummy/db/development.sqlite3
136
141
  - test/dummy/db/migrate/20120422025545_create_widgets.rb
137
142
  - test/dummy/db/schema.rb
138
- - test/dummy/db/test.sqlite3
139
- - test/dummy/log/development.log
140
- - test/dummy/log/test.log
143
+ - test/dummy/lib/assets/.gitkeep
144
+ - test/dummy/log/.gitkeep
141
145
  - test/dummy/public/404.html
142
146
  - test/dummy/public/422.html
143
147
  - test/dummy/public/500.html
144
148
  - test/dummy/public/favicon.ico
145
- - test/dummy/Rakefile
146
- - test/dummy/README.rdoc
147
149
  - test/dummy/script/rails
148
150
  - test/dummy/test/fixtures/widgets.yml
149
151
  - test/multipluck_test.rb