deep_pluck_with_authorization 1.1.2

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.
@@ -0,0 +1,25 @@
1
+ sudo: false
2
+ env:
3
+ global:
4
+ - CC_TEST_REPORTER_ID=29e69e7da6b55678f27b7de2444b6161a6c98e3c4b22e0e017ebab87ada18fd5
5
+ language: ruby
6
+ rvm:
7
+ - 2.2
8
+ - 2.3
9
+ gemfile:
10
+ - gemfiles/3.2.gemfile
11
+ - gemfiles/4.2.gemfile
12
+ - gemfiles/5.0.gemfile
13
+ - gemfiles/5.1.gemfile
14
+ - gemfiles/5.2.gemfile
15
+ before_install:
16
+ - gem i rubygems-update -v '<3' && update_rubygems
17
+ - gem install bundler -v 1.17.3
18
+ - gem --version
19
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
20
+ - chmod +x ./cc-test-reporter
21
+ - ./cc-test-reporter before-build
22
+ script:
23
+ - bundle exec rake test
24
+ after_script:
25
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
@@ -0,0 +1,47 @@
1
+ ## Change Log
2
+
3
+ ### [v1.1.1](https://github.com/khiav223577/deep_pluck/compare/v1.1.0...v1.1.1) 2018/07/08
4
+ - [#26](https://github.com/khiav223577/deep_pluck/pull/26) Fix: `id` may disappear when plucking at model instance (@khiav223577)
5
+ - [#25](https://github.com/khiav223577/deep_pluck/pull/25) Refactor - move models definition to separate files (@khiav223577)
6
+ - [#24](https://github.com/khiav223577/deep_pluck/pull/24) test Rails 5.2 (@khiav223577)
7
+ - [#23](https://github.com/khiav223577/deep_pluck/pull/23) should test both 5.0.x and 5.1.x (@khiav223577)
8
+ - [#22](https://github.com/khiav223577/deep_pluck/pull/22) #deep_pluck at active model without plucking deeply will cause ArgumentError (@khiav223577)
9
+ - [#20](https://github.com/khiav223577/deep_pluck/pull/20) [ENHANCE] Eliminate Extra Select Loop in Hash Lookup (@berniechiu)
10
+
11
+ ### [v1.1.0](https://github.com/khiav223577/deep_pluck/compare/v1.0.3...v1.1.0) 2018/02/15
12
+ - [#19](https://github.com/khiav223577/deep_pluck/pull/19) Support deep_pluck at active model (@khiav223577)
13
+ - [#18](https://github.com/khiav223577/deep_pluck/pull/18) Add rubocop and Improve code quality (@khiav223577)
14
+
15
+ ### [v1.0.3](https://github.com/khiav223577/deep_pluck/compare/v1.0.0...v1.0.3) 2017/06/30
16
+ - [#15](https://github.com/khiav223577/deep_pluck/pull/15) test deep_pluck in rails 5.1.x (@khiav223577)
17
+ - [#14](https://github.com/khiav223577/deep_pluck/pull/14) Handle polymorphic associations correctly. (@Bogadon)
18
+
19
+ ### [v1.0.0](https://github.com/khiav223577/deep_pluck/compare/v0.1.4...v1.0.0) 2017/03/28
20
+ - [#12](https://github.com/khiav223577/deep_pluck/pull/12) reduce cyclomatic complexity in model.rb (@khiav223577)
21
+
22
+ ### [v0.1.4](https://github.com/khiav223577/deep_pluck/compare/v0.1.3...v0.1.4) 2017/03/27
23
+ - [#11](https://github.com/khiav223577/deep_pluck/pull/11) Fix conditional associations (@khiav223577)
24
+
25
+ ### [v0.1.3](https://github.com/khiav223577/deep_pluck/compare/v0.1.2...v0.1.3) 2017/03/20
26
+ - [#10](https://github.com/khiav223577/deep_pluck/pull/10) fix custom foreign_key, custom primary_key issues (@khiav223577)
27
+ - [#9](https://github.com/khiav223577/deep_pluck/pull/9) fix has_and_belongs_to_many (@khiav223577)
28
+
29
+ ### [v0.1.2](https://github.com/khiav223577/deep_pluck/compare/v0.1.1...v0.1.2) 2017/03/17
30
+ - [#8](https://github.com/khiav223577/deep_pluck/pull/8) fix some need columns is missing (@khiav223577)
31
+ - [#7](https://github.com/khiav223577/deep_pluck/pull/7) raise error message when association not found (@khiav223577)
32
+
33
+ ### [v0.1.1](https://github.com/khiav223577/deep_pluck/compare/v0.1.0...v0.1.1) 2017/03/16
34
+ - [#6](https://github.com/khiav223577/deep_pluck/pull/6) fix deep_pluck with #joins (@khiav223577)
35
+
36
+ ### [v0.1.0](https://github.com/khiav223577/deep_pluck/compare/v0.0.4...v0.1.0) 2017/03/15
37
+ - [#5](https://github.com/khiav223577/deep_pluck/pull/5) Support pluck many-to-many associations (@khiav223577)
38
+
39
+ ### [v0.0.4](https://github.com/khiav223577/deep_pluck/compare/v0.0.3...v0.0.4) 2017/03/14
40
+ - [#4](https://github.com/khiav223577/deep_pluck/pull/4) Fix use deep_pluck on NullRelation will raise exception and prevent unneeded query. (@khiav223577)
41
+
42
+ ### [v0.0.3](https://github.com/khiav223577/deep_pluck/compare/v0.0.2...v0.0.3) 2017/03/06
43
+ - [#3](https://github.com/khiav223577/deep_pluck/pull/3) support more than two level (@khiav223577)
44
+
45
+ ### v0.0.2 2017/03/06
46
+ - [#2](https://github.com/khiav223577/deep_pluck/pull/2) The result of has_one association should not be array (@khiav223577)
47
+ - [#1](https://github.com/khiav223577/deep_pluck/pull/1) deep pluck (@khiav223577)
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at mrtmrt15xn@yahoo.com.tw. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 khiav reoy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,171 @@
1
+ # DeepPluck
2
+
3
+ [![Gem Version](https://img.shields.io/gem/v/deep_pluck.svg?style=flat)](http://rubygems.org/gems/deep_pluck)
4
+ [![Build Status](https://travis-ci.org/khiav223577/deep_pluck.svg?branch=master)](https://travis-ci.org/khiav223577/deep_pluck)
5
+ [![RubyGems](http://img.shields.io/gem/dt/deep_pluck.svg?style=flat)](http://rubygems.org/gems/deep_pluck)
6
+ [![Code Climate](https://codeclimate.com/github/khiav223577/deep_pluck/badges/gpa.svg)](https://codeclimate.com/github/khiav223577/deep_pluck)
7
+ [![Test Coverage](https://codeclimate.com/github/khiav223577/deep_pluck/badges/coverage.svg)](https://codeclimate.com/github/khiav223577/deep_pluck/coverage)
8
+
9
+ Allow you to pluck deeply into nested associations without loading a bunch of records.
10
+
11
+ Support Rails 3.2, 4.2, 5.0, 5.1, 5.2.
12
+
13
+
14
+ ## Installation
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ ```ruby
19
+ gem 'deep_pluck'
20
+ ```
21
+
22
+ And then execute:
23
+
24
+ $ bundle
25
+
26
+ Or install it yourself as:
27
+
28
+ $ gem install deep_pluck
29
+
30
+ ## Usage
31
+
32
+ ### Similar to #pluck method
33
+
34
+ ```rb
35
+ User.deep_pluck(:id, :name)
36
+ # SELECT `users`.`id`, `users`.`name` FROM `users`
37
+ # =>
38
+ # [
39
+ # {'id' => 1, 'name' => 'David'},
40
+ # {'id' => 2, 'name' => 'Jeremy'},
41
+ # ]
42
+ ```
43
+
44
+ ### Pluck attributes from nested associations
45
+
46
+ ```rb
47
+ User.deep_pluck(:name, 'posts' => :title)
48
+ # SELECT `users`.`id`, `users`.`name` FROM `users`
49
+ # SELECT `posts`.`user_id`, `posts`.`title` FROM `posts` WHERE `posts`.`user_id` IN (1, 2)
50
+ # =>
51
+ # [
52
+ # {
53
+ # 'name' => 'David' ,
54
+ # 'posts' => [
55
+ # {'title' => 'post1'},
56
+ # {'title' => 'post2'},
57
+ # ],
58
+ # },
59
+ # {
60
+ # 'name' => 'Jeremy',
61
+ # 'posts' => [
62
+ # {'title' => 'post3'},
63
+ # ],
64
+ # },
65
+ # ]
66
+ ```
67
+
68
+ ### Pluck at models
69
+
70
+ ```rb
71
+ user = User.find_by(name: 'David')
72
+ user.deep_pluck(:name, :posts => :title)
73
+ # =>
74
+ # {
75
+ # 'name' => 'David' ,
76
+ # :posts => [
77
+ # {'title' => 'post1'},
78
+ # {'title' => 'post2'},
79
+ # ],
80
+ # }
81
+ ```
82
+
83
+ ### Compare with using `#as_json`
84
+
85
+ Assume the following relations:
86
+
87
+ > User has_many Posts.<br>
88
+ > Post has_many PostComments.<br>
89
+ > User has_one Contact.<br>
90
+
91
+ And the following #as_json example:
92
+ ```rb
93
+ User.where(:name => %w(Pearl Kathenrie)).includes([{:posts => :post_comments}, :contact]).as_json({
94
+ :root => false,
95
+ :only => [:name, :email],
96
+ :include => {
97
+ 'posts' => {
98
+ :only => :name,
99
+ :include => {
100
+ 'post_comments' => {
101
+ :only => :comment,
102
+ },
103
+ },
104
+ },
105
+ 'contact' => {
106
+ :only => :address,
107
+ },
108
+ },
109
+ })
110
+
111
+ ```
112
+ It works as expected, but is not very DRY, repeat writing `include`, `posts`, `post_comments` so many times.
113
+
114
+ Not to mention the huge performace improvement by using #deep_pluck.
115
+
116
+ You could refactor the example with #deep_pluck:
117
+ ```rb
118
+ User.where(:name => %w(Pearl Kathenrie)).deep_pluck(
119
+ :name,
120
+ :email,
121
+ 'posts' => [:name, 'post_comments' => :comment],
122
+ 'contact' => :address,
123
+ )
124
+ ```
125
+
126
+ ### Better Performance
127
+
128
+ #deep_pluck return raw hash data without loading a bunch of records, so that faster than #as_json, or #select.
129
+
130
+ The following is the benchmark test on 3 users, 6 posts, where `users` table have 14 columns and `posts` have 6 columns. As it shows, `deep_pluck` is 4x faster than `as_json`.
131
+
132
+
133
+ ```rb
134
+ # Repeat 500 times
135
+ # User.includes(:posts).as_json(:only => :email, :include => {:posts => {:only => :title}})
136
+ # User.deep_pluck(:email, {'posts' => :title})
137
+
138
+ user system total real
139
+ as_json 1.740000 1.230000 2.970000 ( 3.231465)
140
+ deep_pluck 0.660000 0.030000 0.690000 ( 0.880018)
141
+ ```
142
+
143
+ The following is the benchmark test on 10000 users, where `users` table have 46 columns. As it shows, `deep_pluck` is 40x faster than `as_json` and 4x faster than `map`.
144
+ ```rb
145
+ # Repeat 1 times
146
+ # User.select('account, email').map{|s| {'account' => s.account, 'email' => s.email}}
147
+ # User.select('account, email').as_json(:only => [:account, :email])
148
+ # User.deep_pluck(:account, :email)
149
+
150
+ user system total real
151
+ map 0.210000 0.000000 0.210000 ( 0.225421)
152
+ as_json 1.980000 0.060000 2.040000 ( 2.042205)
153
+ deep_pluck 0.040000 0.000000 0.040000 ( 0.051673)
154
+ ```
155
+
156
+
157
+ ## Development
158
+
159
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
160
+
161
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
162
+
163
+ ## Contributing
164
+
165
+ Bug reports and pull requests are welcome on GitHub at https://github.com/khiav223577/deep_pluck. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
166
+
167
+
168
+ ## License
169
+
170
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
171
+
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << 'test'
6
+ t.libs << 'lib'
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task default: :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'deep_pluck'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install --gemfile=gemfiles/4.2.gemfile
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,40 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'deep_pluck/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'deep_pluck_with_authorization'
8
+ spec.version = DeepPluck::VERSION
9
+ spec.authors = ['Poilon']
10
+ spec.email = ['poilon@gmail.com']
11
+
12
+ spec.summary = 'Use deep_pluck as a shortcut to select one or more attributes and' \
13
+ ' include associated models without loading a bunch of records. Added a filter for graphql_rails_api gem.'
14
+ spec.description = 'Use deep_pluck as a shortcut to select one or more attributes and' \
15
+ ' include associated models without loading a bunch of records. And DRY up your code w' \
16
+ 'hen using #as_json. Added a filter for graphql_rails_api gem'
17
+ spec.homepage = 'https://github.com/poilon/deep_pluck'
18
+ spec.license = 'MIT'
19
+
20
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
21
+ # delete this section to allow pushing this gem to any host.
22
+ # if spec.respond_to?(:metadata)
23
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
24
+ # else
25
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
26
+ # end
27
+
28
+ spec.files = `git ls-files -z`.split("\x0").reject{|f| f.match(%r{^(test|spec|features)/}) }
29
+ spec.bindir = 'exe'
30
+ spec.executables = spec.files.grep(%r{^exe/}){|f| File.basename(f) }
31
+ spec.require_paths = ['lib']
32
+
33
+ spec.add_development_dependency 'bundler', '>= 1.17', '< 3.x'
34
+ spec.add_development_dependency 'rake', '~> 12.0'
35
+ spec.add_development_dependency 'sqlite3', '~> 1.3'
36
+ spec.add_development_dependency 'minitest', '~> 5.0'
37
+
38
+ spec.add_dependency 'activerecord', '>= 3'
39
+ spec.add_dependency 'pluck_all', '>= 1.2.3'
40
+ end
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pluck_all.gemspec
4
+
5
+ gem 'activerecord', '~> 3.2.0'
6
+ gem 'pluck_all', '~> 1.2.2'
7
+
8
+ group :test do
9
+ gem 'simplecov'
10
+ end
11
+
12
+ gemspec path: '../'
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pluck_all.gemspec
4
+
5
+ gem 'activerecord', '~> 4.2.0'
6
+ gem 'pluck_all', '~> 1.2.2'
7
+
8
+ group :test do
9
+ gem 'simplecov'
10
+ end
11
+
12
+ gemspec path: '../'
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pluck_all.gemspec
4
+
5
+ gem 'activerecord', '~> 5.0.0'
6
+ gem 'pluck_all', '~> 1.2.2'
7
+
8
+ group :test do
9
+ gem 'simplecov'
10
+ end
11
+
12
+ gemspec path: '../'
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pluck_all.gemspec
4
+
5
+ gem 'activerecord', '~> 5.1.0'
6
+ gem 'pluck_all', '~> 1.2.2'
7
+
8
+ group :test do
9
+ gem 'simplecov'
10
+ end
11
+
12
+ gemspec path: '../'