deep_pluck 1.0.1 → 1.0.2

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: 62f11d2a98f0fcc87a92b67870d4f93eea1e08e6
4
- data.tar.gz: 349f58e92dbb61357cfe304fbc04fe99a53fb852
3
+ metadata.gz: 02452d4bac10e6638a4df989d324371064b4dd03
4
+ data.tar.gz: f82443f03983bbb1c58c9e4a17a4057e483946bb
5
5
  SHA512:
6
- metadata.gz: 1c3cfa0781e1e6d2677b05d36999e1f1d82294c82fb92cf4ec80107bd565c1bcaba07393f868567d7e1a34788770c42e7150e5cccda0bbe73377315ff99e9459
7
- data.tar.gz: d6fec64a70b30f830f236c902703ea74853ff60d3ad0034ddda73ae005b0b04135d1360520ae90249b747416d79f23aa9bd38c5f72e2aaaec6174abedf15c9ef
6
+ metadata.gz: 89e9ef90f3a61e47dfb868075282b61376249db2cd685e81176cb2ae810f953bf34c1b0d737e9fd1ab21191bd5f67e84457993cfc002ab20177b3cfca5b29493
7
+ data.tar.gz: 8f2b8a6c7f7d1dcc714c2937654d8758c7732ae13b9ea7d4a102909d111e5be45774ae0fd7662b8e98a2808e8a4500a273db104ac90edc62397f1a3b51891685
data/README.md CHANGED
@@ -10,6 +10,8 @@ Allow you to pluck deeply into nested associations without loading a bunch of re
10
10
 
11
11
  And DRY up your code when using #as_json.
12
12
 
13
+ Works in Rails 3+.
14
+
13
15
 
14
16
  ## Installation
15
17
 
@@ -76,6 +78,8 @@ User.where(:name => %w(Pearl Kathenrie)).includes([{:posts => :post_comments}, :
76
78
  })
77
79
 
78
80
  ```
81
+ It works as expected, but is not very DRY, repeat writing `include`, `posts`, `post_comments` so many times.
82
+
79
83
  You could refactor it with #deep_pluck like:
80
84
  ```rb
81
85
  User.where(:name => %w(Pearl Kathenrie)).deep_pluck(
@@ -92,7 +96,31 @@ User.where(:name => %w(Pearl Kathenrie)).deep_pluck(
92
96
 
93
97
  In that faster than #as_json, or #select.
94
98
 
95
- Will add some benchmarks soon :)
99
+ 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`.
100
+
101
+
102
+ ```rb
103
+ # Repeat 500 times
104
+ # User.includes(:posts).as_json(:only => :email, :include => {:posts => {:only => :title}})
105
+ # User.deep_pluck(:email, {'posts' => :title})
106
+
107
+ user system total real
108
+ as_json 1.740000 1.230000 2.970000 ( 3.231465)
109
+ deep_pluck 0.660000 0.030000 0.690000 ( 0.880018)
110
+ ```
111
+
112
+ 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`.
113
+ ```rb
114
+ # Repeat 1 times
115
+ # User.select('account, email').map{|s| {'account' => s.account, 'email' => s.email}}
116
+ # User.select('account, email').as_json(:only => [:account, :email])
117
+ # User.deep_pluck(:account, :email)
118
+
119
+ user system total real
120
+ map 0.210000 0.000000 0.210000 ( 0.225421)
121
+ as_json 1.980000 0.060000 2.040000 ( 2.042205)
122
+ deep_pluck 0.040000 0.000000 0.040000 ( 0.051673)
123
+ ```
96
124
 
97
125
 
98
126
  ## Development
@@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
32
32
  spec.add_development_dependency "sqlite3", "~> 1.3"
33
33
  spec.add_development_dependency "minitest", "~> 5.0"
34
34
 
35
- spec.add_dependency "activerecord", "> 3.x"
36
- spec.add_dependency "pluck_all", "~> 1.2.2"
35
+ spec.add_dependency "activerecord", ">= 3"
36
+ spec.add_dependency "pluck_all", ">= 1.2.3"
37
37
 
38
38
  end
@@ -1,3 +1,3 @@
1
1
  module DeepPluck
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deep_pluck
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - khiav reoy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-28 00:00:00.000000000 Z
11
+ date: 2017-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -70,30 +70,30 @@ dependencies:
70
70
  name: activerecord
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: 3.x
75
+ version: '3'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">"
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: 3.x
82
+ version: '3'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: pluck_all
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - "~>"
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: 1.2.2
89
+ version: 1.2.3
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - "~>"
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
- version: 1.2.2
96
+ version: 1.2.3
97
97
  description: 'Use deep_pluck as a shortcut to select one or more attributes and include
98
98
  associated models without loading a bunch of records. And DRY up your code when
99
99
  using #as_json.'