pluckex 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +15 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/{MIT-LICENSE → LICENSE.txt} +3 -1
- data/README.md +44 -0
- data/Rakefile +4 -20
- data/lib/pluckex/active_record/relation/calculations.rb +21 -0
- data/lib/pluckex/version.rb +1 -1
- data/lib/pluckex.rb +2 -2
- data/pluckex.gemspec +24 -0
- data/spec/pluckex_spec.rb +11 -0
- data/spec/spec_helper.rb +2 -0
- metadata +51 -15
- data/config/routes.rb +0 -2
- data/lib/active_record_extension.rb +0 -24
- data/lib/pluckex/engine.rb +0 -4
- data/lib/tasks/pluckex_tasks.rake +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8985a2797e08a17723fbfcff744ae983828ae45
|
4
|
+
data.tar.gz: 5dd2764db924e582f6d287f179437be308918991
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f49af65d8733c74806fe7a430c487754058ec6ce7c4a0813ce65942402bc3fe0d8ab9b2eb274eeb409d0be48a53345edd3bc2bc9612e73d475d275af392392a
|
7
|
+
data.tar.gz: 5a8bec23611bc9f73dfcfbc250461773563e99d8cf684dd17c5092d78e315a34d50b2125556bc63edbb818597898fa644a657963738cd2fa7e1fa6fb5bf2deb0
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/{MIT-LICENSE → LICENSE.txt}
RENAMED
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# Pluckex
|
2
|
+
|
3
|
+
Pluckex add pluck-extended methods.
|
4
|
+
|
5
|
+
[ActiveRecord::Caluculations#pluck](http://api.rubyonrails.org/classes/ActiveRecord/Calculations.html#method-i-pluck).
|
6
|
+
|
7
|
+
Like this.
|
8
|
+
|
9
|
+
### pluck_tied_by_id
|
10
|
+
|
11
|
+
```
|
12
|
+
# Person.pluck_tied_by_id(:name)
|
13
|
+
# # => {1=>'David', 2=>'Jeremy', 3=>'Jose'}
|
14
|
+
```
|
15
|
+
### pluck_with_keys
|
16
|
+
|
17
|
+
```
|
18
|
+
# Person.pluck_with_keys(:id, :name)
|
19
|
+
# # => [{:id=>1, :name=>'David'}, {:id=>2, :name=>'Jeremy'}, {:id=>3, :name=>'Jose'}]
|
20
|
+
```
|
21
|
+
|
22
|
+
## Installation
|
23
|
+
|
24
|
+
Add this line to your application's Gemfile:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
gem 'pluckex'
|
28
|
+
```
|
29
|
+
|
30
|
+
And then execute:
|
31
|
+
|
32
|
+
$ bundle
|
33
|
+
|
34
|
+
Or install it yourself as:
|
35
|
+
|
36
|
+
$ gem install pluckex
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
1. Fork it ( https://github.com/[my-github-username]/pluckex/fork )
|
41
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
42
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
43
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
44
|
+
5. Create a new Pull Request
|
data/Rakefile
CHANGED
@@ -1,23 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
rescue LoadError
|
4
|
-
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
-
end
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rspec/core/rake_task"
|
6
3
|
|
7
|
-
|
4
|
+
RSpec::Core::RakeTask.new(:spec)
|
8
5
|
|
9
|
-
|
10
|
-
rdoc.rdoc_dir = 'rdoc'
|
11
|
-
rdoc.title = 'Pluckex'
|
12
|
-
rdoc.options << '--line-numbers'
|
13
|
-
rdoc.rdoc_files.include('README.rdoc')
|
14
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
-
end
|
16
|
-
|
17
|
-
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
18
|
-
load 'rails/tasks/engine.rake'
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
Bundler::GemHelper.install_tasks
|
6
|
+
task :default => :spec
|
23
7
|
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module Calculations
|
3
|
+
# Person.pluck_tied_by_id(:name)
|
4
|
+
# # => {1=>'David', 2=>'Jeremy', 3=>'Jose'}
|
5
|
+
def pluck_tied_by_id(col_name)
|
6
|
+
col_names = [:id] << col_name
|
7
|
+
Hash[*self.pluck(*col_names).flatten]
|
8
|
+
end
|
9
|
+
|
10
|
+
# Person.pluck_with_keys(:id, :name)
|
11
|
+
# # => [{:id=>1, :name=>'David'}, {:id=>2, :name=>'Jeremy'}, {:id=>3, :name=>'Jose'}]
|
12
|
+
def pluck_with_keys(*col_names)
|
13
|
+
self.pluck(*col_names).map do |element|
|
14
|
+
hash = {}
|
15
|
+
col_names.map.with_index do |col, i|
|
16
|
+
hash.merge!(col => element[i])
|
17
|
+
end.uniq
|
18
|
+
end.flatten
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/pluckex/version.rb
CHANGED
data/lib/pluckex.rb
CHANGED
data/pluckex.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'pluckex/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "pluckex"
|
8
|
+
spec.version = Pluckex::VERSION
|
9
|
+
spec.authors = ["Daiki Taniguchi"]
|
10
|
+
spec.email = ["daiki.taniguchi@aktsk.jp"]
|
11
|
+
spec.summary = %q{Pluckex.}
|
12
|
+
spec.description = %q{Pluckex!}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,44 +1,77 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pluckex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Daiki Taniguchi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
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
|
15
43
|
requirement: !ruby/object:Gem::Requirement
|
16
44
|
requirements:
|
17
45
|
- - '>='
|
18
46
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
20
|
-
type: :
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
21
49
|
prerelease: false
|
22
50
|
version_requirements: !ruby/object:Gem::Requirement
|
23
51
|
requirements:
|
24
52
|
- - '>='
|
25
53
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
54
|
+
version: '0'
|
27
55
|
description: Pluckex!
|
28
56
|
email:
|
29
|
-
-
|
57
|
+
- daiki.taniguchi@aktsk.jp
|
30
58
|
executables: []
|
31
59
|
extensions: []
|
32
60
|
extra_rdoc_files: []
|
33
61
|
files:
|
34
|
-
-
|
62
|
+
- .gitignore
|
63
|
+
- .rspec
|
64
|
+
- .travis.yml
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
35
68
|
- Rakefile
|
36
|
-
- config/routes.rb
|
37
|
-
- lib/active_record_extension.rb
|
38
69
|
- lib/pluckex.rb
|
39
|
-
- lib/pluckex/
|
70
|
+
- lib/pluckex/active_record/relation/calculations.rb
|
40
71
|
- lib/pluckex/version.rb
|
41
|
-
-
|
72
|
+
- pluckex.gemspec
|
73
|
+
- spec/pluckex_spec.rb
|
74
|
+
- spec/spec_helper.rb
|
42
75
|
homepage: ''
|
43
76
|
licenses:
|
44
77
|
- MIT
|
@@ -62,5 +95,8 @@ rubyforge_project:
|
|
62
95
|
rubygems_version: 2.4.1
|
63
96
|
signing_key:
|
64
97
|
specification_version: 4
|
65
|
-
summary: Pluckex
|
66
|
-
test_files:
|
98
|
+
summary: Pluckex.
|
99
|
+
test_files:
|
100
|
+
- spec/pluckex_spec.rb
|
101
|
+
- spec/spec_helper.rb
|
102
|
+
has_rdoc:
|
data/config/routes.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
# Extensions for ActiveRecord.
|
2
|
-
module ActiveRecord
|
3
|
-
class Base
|
4
|
-
class << self
|
5
|
-
# Person.pluck_tied_by_id(:name)
|
6
|
-
# # => {1=>'David', 2=>'Jeremy', 3=>'Jose'}
|
7
|
-
def pluck_tied_by_id(col_name)
|
8
|
-
col_names = [:id] << col_name
|
9
|
-
Hash[*self.pluck(*col_names).flatten]
|
10
|
-
end
|
11
|
-
|
12
|
-
# Person.pluck_with_keys(:id, :name)
|
13
|
-
# # => [{:id=>1, :name=>'David'}, {:id=>2, :name=>'Jeremy'}, {:id=>3, :name=>'Jose'}]
|
14
|
-
def pluck_with_keys(*col_names)
|
15
|
-
self.pluck(*col_names).map do |element|
|
16
|
-
hash = {}
|
17
|
-
col_names.map.with_index do |col, i|
|
18
|
-
hash.merge!(col => element[i])
|
19
|
-
end.uniq
|
20
|
-
end.flatten
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
data/lib/pluckex/engine.rb
DELETED