quickery 0.1.1 → 0.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.
- checksums.yaml +4 -4
- data/.gitignore +0 -0
- data/.rspec +0 -0
- data/.travis.yml +0 -0
- data/Appraisals +0 -0
- data/Gemfile +1 -0
- data/Guardfile +0 -0
- data/LICENSE.txt +0 -0
- data/README.md +19 -8
- data/Rakefile +0 -0
- data/config.ru +0 -0
- data/developer_guide.md +9 -0
- data/gemfiles/.bundle/config +0 -0
- data/gemfiles/rails_4.gemfile +1 -0
- data/gemfiles/rails_5.gemfile +1 -0
- data/lib/quickery.rb +0 -0
- data/lib/quickery/active_record_extensions/dsl.rb +0 -1
- data/lib/quickery/association_builder.rb +0 -0
- data/lib/quickery/callbacks_builder.rb +0 -0
- data/lib/quickery/quickery_builder.rb +0 -0
- data/lib/quickery/version.rb +1 -1
- data/quickery.gemspec +0 -0
- metadata +2 -3
- data/gemfiles/rails_3.gemfile +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f23d071c0950a5aea01e1fbaac6b70b8024afc869309116947c0b9bf093e5869
|
4
|
+
data.tar.gz: ded1a4a4900160e8e614ad09ffcf824b6f7fde68fdc9c2b4d61d1fe2bc650ec1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0fa75bd9539cfd2095beb17099685c83ef0c617723c829bdbbc6041c791292f1f5d8cd98561aca87e69655c2c1850d4f18e4c4615ef67108c662c6c047ffe0d9
|
7
|
+
data.tar.gz: 8f3be6901dd857c976b1d08e54245f7b9d249dc7738f59e4ddbf411e24bca40e36a43304ebc730af74f7f472ef307982ea165fe6f47dbc657e15a47741785a23
|
data/.gitignore
CHANGED
File without changes
|
data/.rspec
CHANGED
File without changes
|
data/.travis.yml
CHANGED
File without changes
|
data/Appraisals
CHANGED
File without changes
|
data/Gemfile
CHANGED
data/Guardfile
CHANGED
File without changes
|
data/LICENSE.txt
CHANGED
File without changes
|
data/README.md
CHANGED
@@ -3,8 +3,6 @@
|
|
3
3
|
[](https://travis-ci.org/jrpolidario/quickery)
|
4
4
|
[](https://badge.fury.io/rb/quickery)
|
5
5
|
|
6
|
-
## About
|
7
|
-
|
8
6
|
* Implements Law of Demeter by mapping associated record attributes as own attributes (one-way read-only)
|
9
7
|
* Consequently, speeds up SQL queries by removing joins queries between intermediary models, at the cost of slower writes.
|
10
8
|
* This is an anti-normalization pattern in favour of actual data-redundancy and faster queries. Use this only as necessary.
|
@@ -33,8 +31,9 @@
|
|
33
31
|
# app/models/employee.rb
|
34
32
|
class Employee < ApplicationRecord
|
35
33
|
# say we have the following attributes:
|
36
|
-
# branch_id:
|
34
|
+
# branch_id:bigint
|
37
35
|
# branch_company_name:string
|
36
|
+
|
38
37
|
belongs_to :branch
|
39
38
|
|
40
39
|
quickery do
|
@@ -58,7 +57,8 @@ end
|
|
58
57
|
# app/models/branch.rb
|
59
58
|
class Branch < ApplicationRecord
|
60
59
|
# say we have the following attributes:
|
61
|
-
# company_id:
|
60
|
+
# company_id:bigint
|
61
|
+
|
62
62
|
belongs_to :company
|
63
63
|
end
|
64
64
|
|
@@ -92,7 +92,7 @@ company.update!(name: 'Mang Inasal')
|
|
92
92
|
puts employee.branch_company_name
|
93
93
|
# => 'Jollibee'
|
94
94
|
|
95
|
-
# You need to reload the object, if you expect that it's been changed:
|
95
|
+
# You may or may not need to reload the object, depending on if you expect that it's been changed:
|
96
96
|
employee.reload
|
97
97
|
|
98
98
|
puts employee.branch_company_name
|
@@ -108,6 +108,15 @@ puts employee.branch_company_name
|
|
108
108
|
# => 'McDonalds'
|
109
109
|
```
|
110
110
|
|
111
|
+
If you already have "old" records before you've integrated quickery or if you have new quickery-defined attributes, you can update these stale records by using `recreate_quickery_cache!`. See example below:
|
112
|
+
|
113
|
+
```ruby
|
114
|
+
# rails console
|
115
|
+
Employee.find_each do |employee|
|
116
|
+
employee.recreate_quickery_cache!
|
117
|
+
end
|
118
|
+
```
|
119
|
+
|
111
120
|
## Usage Example 2
|
112
121
|
|
113
122
|
* let `Branch` and `Company` model be the same as the Usage Example 1 above
|
@@ -116,7 +125,7 @@ puts employee.branch_company_name
|
|
116
125
|
# app/models/employee.rb
|
117
126
|
class Employee < ApplicationRecord
|
118
127
|
belongs_to :branch
|
119
|
-
belongs_to :
|
128
|
+
belongs_to :company, foreign_key: :branch_company_id
|
120
129
|
|
121
130
|
quickery do
|
122
131
|
branch.company.id == :branch_company_id
|
@@ -143,7 +152,7 @@ puts Employee.where(company: company)
|
|
143
152
|
# => [#<Employee id: 1>]
|
144
153
|
|
145
154
|
# as you may notice, the query above is a lot simpler and faster instead of doing it normally like below (if not using Quickery)
|
146
|
-
# you may however still
|
155
|
+
# you may however still use belongs_to `:through` to achieve the simplified query like above, but it's still a lot slower because of JOINS
|
147
156
|
puts Employee.joins(branch: :company).where(companies: { id: company.id })
|
148
157
|
# => [#<Employee id: 1>]
|
149
158
|
```
|
@@ -179,7 +188,7 @@ puts Employee.joins(branch: :company).where(companies: { id: company.id })
|
|
179
188
|
* useful if you already have records, and you want these old records to be updated immediately
|
180
189
|
* i.e. you can do so something like the following:
|
181
190
|
```ruby
|
182
|
-
Employee.
|
191
|
+
Employee.find_each do |employee|
|
183
192
|
employee.recreate_quickery_cache!
|
184
193
|
end
|
185
194
|
```
|
@@ -209,6 +218,8 @@ puts Employee.joins(branch: :company).where(companies: { id: company.id })
|
|
209
218
|
* see [developer_guide.md](developer_guide.md)
|
210
219
|
|
211
220
|
## Changelog
|
221
|
+
* 0.1.2
|
222
|
+
* fixed require error for remnant debugging code: 'byebug'
|
212
223
|
* 0.1.1
|
213
224
|
* Gemspec fixes and travis build fixes.
|
214
225
|
* 0.1.0
|
data/Rakefile
CHANGED
File without changes
|
data/config.ru
CHANGED
File without changes
|
data/developer_guide.md
CHANGED
@@ -15,6 +15,15 @@ gem push quickery-X.X.X.gem
|
|
15
15
|
* [combustion](https://github.com/pat/combustion)
|
16
16
|
* [appraisal](https://github.com/thoughtbot/appraisal)
|
17
17
|
|
18
|
+
### Setup
|
19
|
+
|
20
|
+
```bash
|
21
|
+
# setup development gems
|
22
|
+
bundle install
|
23
|
+
# setup Apprisal for testing different Rails versions below
|
24
|
+
bundle exec appraisal install
|
25
|
+
```
|
26
|
+
|
18
27
|
```bash
|
19
28
|
# to auto-test specs whenever a spec file has been modified:
|
20
29
|
bundle exec guard
|
data/gemfiles/.bundle/config
CHANGED
File without changes
|
data/gemfiles/rails_4.gemfile
CHANGED
data/gemfiles/rails_5.gemfile
CHANGED
data/lib/quickery.rb
CHANGED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/lib/quickery/version.rb
CHANGED
data/quickery.gemspec
CHANGED
File without changes
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quickery
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jules Roman Polidario
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-09-
|
11
|
+
date: 2018-09-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -231,7 +231,6 @@ files:
|
|
231
231
|
- config.ru
|
232
232
|
- developer_guide.md
|
233
233
|
- gemfiles/.bundle/config
|
234
|
-
- gemfiles/rails_3.gemfile
|
235
234
|
- gemfiles/rails_4.gemfile
|
236
235
|
- gemfiles/rails_5.gemfile
|
237
236
|
- lib/quickery.rb
|