active_model_cachers 2.1.5 → 2.1.6

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
  SHA256:
3
- metadata.gz: 3a8f59a55915fa875ecfda9692094c2054e434349b847e2abfd11b030e0dfee8
4
- data.tar.gz: b1e594fb44ab1248cc10b54daca3149d1abb0f35cef902a6982e51a14251ac61
3
+ metadata.gz: e31817e291e8fdf57beee4f76dad4a9a4f710c3f8865758ea9d92eff18bfddd1
4
+ data.tar.gz: 2f39c9465528dcf3fbd4908cdb0c82d46306bc2a6fadebf3f6ff9d67c9a97c32
5
5
  SHA512:
6
- metadata.gz: 67c437185d13326f655820d9950f81bf9109470b2aab4e128554525af7710c0048d3fda5d1341fcd128a55fcf153ec30d99e77223d68a9f385a2e68c58c98636
7
- data.tar.gz: 6c66961a17577c16afabbb80bc8a6920ca256355d096d35cd518d054a284ac36d4b6679ca038d82b52bab19338c9df21057dccaa341d5f5f2804af52c76af8a5
6
+ metadata.gz: 737e904b7bd2bddc6d39e0800d9810522091688174df520d78d61cc51e4d687b7eb0381e05765581ff4dbe70fed23a23bbe493ea5dd85449af6e80940ed48ca0
7
+ data.tar.gz: 5551567cc44161b125f9a026438f1395fc11491d965fab0cc14a8d6feab8f112fb8305c974140b495791cf22a424743bcc54ef4ca1db8d8f6b440bfb6d9b5f91
data/.gitignore CHANGED
@@ -1,9 +1,9 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml CHANGED
@@ -13,8 +13,8 @@ gemfile:
13
13
  - gemfiles/5.1.gemfile
14
14
  - gemfiles/5.2.gemfile
15
15
  before_install:
16
- - gem install bundler
17
- - gem update --system
16
+ - gem i rubygems-update -v '<3' && update_rubygems
17
+ - gem install bundler -v 1.17.3
18
18
  - gem --version
19
19
  - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
20
20
  - chmod +x ./cc-test-reporter
data/CHANGELOG.md CHANGED
@@ -1,57 +1,62 @@
1
- ## Change Log
2
-
3
- ### [v2.1.4](https://github.com/khiav223577/active_model_cachers/compare/v2.1.3...v2.1.4) 2018/06/14
4
- - [#41](https://github.com/khiav223577/active_model_cachers/pull/41) Fix: binding problem (@khiav223577)
5
- - [#40](https://github.com/khiav223577/active_model_cachers/pull/40) [Refactor] Solve warnings (@khiav223577)
6
-
7
- ### [v2.1.3](https://github.com/khiav223577/active_model_cachers/compare/v2.1.2...v2.1.3) 2018/06/07
8
- - [#38](https://github.com/khiav223577/active_model_cachers/pull/38) Fix: Eager-loaded models will not register `after_commit` callback (@khiav223577)
9
-
10
- ### [v2.1.2](https://github.com/khiav223577/active_model_cachers/compare/v2.1.1...v2.1.2) 2018/06/01
11
- - [#37](https://github.com/khiav223577/active_model_cachers/pull/37) Fix: ModelName cant be referred to in development (@khiav223577)
12
-
13
- ### [v2.1.1](https://github.com/khiav223577/active_model_cachers/compare/v2.1.0...v2.1.1) 2018/05/25
14
- - [#35](https://github.com/khiav223577/active_model_cachers/pull/35) Preventing registering same callbacks in some cases (@khiav223577)
15
- - [#34](https://github.com/khiav223577/active_model_cachers/pull/34) Enhance - automatically clean cache when `#touch` (@ff2248)
16
- - [#33](https://github.com/khiav223577/active_model_cachers/pull/33) [Enhance] Code Climate Gem Deprecation (@berniechiu)
17
-
18
- ### [v2.1.0](https://github.com/khiav223577/active_model_cachers/compare/v2.0.3...v2.1.0) 2018/05/18
19
- - [#32](https://github.com/khiav223577/active_model_cachers/pull/32) Add test cases to test "store all data in hash" (@khiav223577)
20
- - [#31](https://github.com/khiav223577/active_model_cachers/pull/31) Change the syntax of getting self from cache (@khiav223577)
21
- - [#29](https://github.com/khiav223577/active_model_cachers/pull/29) test assigning association (@khiav223577)
22
-
23
- ### [v2.0.3](https://github.com/khiav223577/active_model_cachers/compare/v2.0.2...v2.0.3) 2018/05/14
24
- - [#28](https://github.com/khiav223577/active_model_cachers/pull/28) No need to dump all association caches (@khiav223577)
25
-
26
- ### [v2.0.2](https://github.com/khiav223577/active_model_cachers/compare/v2.0.1...v2.0.2) 2018/05/14
27
- - [#27](https://github.com/khiav223577/active_model_cachers/pull/27) [Fix] will send query even if has one association is cached (@khiav223577)
28
-
29
- ### [v2.0.1](https://github.com/khiav223577/active_model_cachers/compare/v2.0.0...v2.0.1) 2018/05/13
30
- - [#26](https://github.com/khiav223577/active_model_cachers/pull/26) Prevent infinite loop if someone override default associations' method (@khiav223577)
31
-
32
- ### v2.0.0 2018/05/13
33
- - [#25](https://github.com/khiav223577/active_model_cachers/pull/25) Support cache self by other column (@khiav223577)
34
- - [#24](https://github.com/khiav223577/active_model_cachers/pull/24) Support cleaning the cache manually (@khiav223577)
35
- - [#23](https://github.com/khiav223577/active_model_cachers/pull/23) use loaded model if possible to prevent extra queries (@khiav223577)
36
- - [#22](https://github.com/khiav223577/active_model_cachers/pull/22) Support caching result from outer service (@khiav223577)
37
- - [#21](https://github.com/khiav223577/active_model_cachers/pull/21) Support writing query in instance scope (@khiav223577)
38
- - [#20](https://github.com/khiav223577/active_model_cachers/pull/20) instance cacher (@khiav223577)
39
- - [#19](https://github.com/khiav223577/active_model_cachers/pull/19) Pass model to `delete` method to prevent an extra query (@khiav223577)
40
- - [#18](https://github.com/khiav223577/active_model_cachers/pull/18) [Test] show all sql queries if query count doesn't equal to expected count. (@khiav223577)
41
- - [#17](https://github.com/khiav223577/active_model_cachers/pull/17) Support cache at has_many association II - add test cases (@khiav223577)
42
- - [#16](https://github.com/khiav223577/active_model_cachers/pull/16) Support cache at has_many association I (@khiav223577)
43
- - [#15](https://github.com/khiav223577/active_model_cachers/pull/15) Adjust file structures (@khiav223577)
44
- - [#14](https://github.com/khiav223577/active_model_cachers/pull/14) Support cache at belongs_to association (@khiav223577)
45
- - [#13](https://github.com/khiav223577/active_model_cachers/pull/13) Fix that cache not cleaned if foreign_key is not `id` and calling `mode.delete` (@khiav223577)
46
- - [#12](https://github.com/khiav223577/active_model_cachers/pull/12) [Refactor] move the active_record extension to proper directory (@khiav223577)
47
- - [#11](https://github.com/khiav223577/active_model_cachers/pull/11) Fix id problem by specify foreign_key manually (@khiav223577)
48
- - [#10](https://github.com/khiav223577/active_model_cachers/pull/10) cache on falsy result (@khiav223577)
49
- - [#9](https://github.com/khiav223577/active_model_cachers/pull/9) Fix that all models cache with same id will be cleaned if any of one is cleaned (@khiav223577)
50
- - [#8](https://github.com/khiav223577/active_model_cachers/pull/8) allow developer to specify whether the cache should expire (@khiav223577)
51
- - [#7](https://github.com/khiav223577/active_model_cachers/pull/7) custom query which allow you to specify how to expire the cache by `expire_by` option (@khiav223577)
52
- - [#6](https://github.com/khiav223577/active_model_cachers/pull/6) test cache self (@khiav223577)
53
- - [#5](https://github.com/khiav223577/active_model_cachers/pull/5) Deal with delete, dependent: :delete that do not fire after_commit callback (@khiav223577)
54
- - [#4](https://github.com/khiav223577/active_model_cachers/pull/4) split test cases to several files and refactor the code (@khiav223577)
55
- - [#3](https://github.com/khiav223577/active_model_cachers/pull/3) Safer cache mechanism: Prevent cache from being left over if someone forgets to write `cache_self` (@khiav223577)
56
- - [#2](https://github.com/khiav223577/active_model_cachers/pull/2) Adjust usage (@khiav223577)
57
- - [#1](https://github.com/khiav223577/active_model_cachers/pull/1) use after_commit hook to expire cached associations (@khiav223577)
1
+ ## Change Log
2
+
3
+ ### [v2.1.5](https://github.com/khiav223577/active_model_cachers/compare/v2.1.4...v2.1.5) 2018/08/03
4
+ - [#44](https://github.com/khiav223577/active_model_cachers/pull/44) should fire an extra query if the attribute used to clean cache is not selected (@khiav223577)
5
+ - [#45](https://github.com/khiav223577/active_model_cachers/pull/45) lazily add global callbacks to ActiveRecord::Base (@khiav223577)
6
+ - [#43](https://github.com/khiav223577/active_model_cachers/pull/43) Improve the structure of README. (@cybersol795)
7
+
8
+ ### [v2.1.4](https://github.com/khiav223577/active_model_cachers/compare/v2.1.3...v2.1.4) 2018/06/14
9
+ - [#41](https://github.com/khiav223577/active_model_cachers/pull/41) Fix: binding problem (@khiav223577)
10
+ - [#40](https://github.com/khiav223577/active_model_cachers/pull/40) [Refactor] Solve warnings (@khiav223577)
11
+
12
+ ### [v2.1.3](https://github.com/khiav223577/active_model_cachers/compare/v2.1.2...v2.1.3) 2018/06/07
13
+ - [#38](https://github.com/khiav223577/active_model_cachers/pull/38) Fix: Eager-loaded models will not register `after_commit` callback (@khiav223577)
14
+
15
+ ### [v2.1.2](https://github.com/khiav223577/active_model_cachers/compare/v2.1.1...v2.1.2) 2018/06/01
16
+ - [#37](https://github.com/khiav223577/active_model_cachers/pull/37) Fix: ModelName cant be referred to in development (@khiav223577)
17
+
18
+ ### [v2.1.1](https://github.com/khiav223577/active_model_cachers/compare/v2.1.0...v2.1.1) 2018/05/25
19
+ - [#35](https://github.com/khiav223577/active_model_cachers/pull/35) Preventing registering same callbacks in some cases (@khiav223577)
20
+ - [#34](https://github.com/khiav223577/active_model_cachers/pull/34) Enhance - automatically clean cache when `#touch` (@ff2248)
21
+ - [#33](https://github.com/khiav223577/active_model_cachers/pull/33) [Enhance] Code Climate Gem Deprecation (@berniechiu)
22
+
23
+ ### [v2.1.0](https://github.com/khiav223577/active_model_cachers/compare/v2.0.3...v2.1.0) 2018/05/18
24
+ - [#32](https://github.com/khiav223577/active_model_cachers/pull/32) Add test cases to test "store all data in hash" (@khiav223577)
25
+ - [#31](https://github.com/khiav223577/active_model_cachers/pull/31) Change the syntax of getting self from cache (@khiav223577)
26
+ - [#29](https://github.com/khiav223577/active_model_cachers/pull/29) test assigning association (@khiav223577)
27
+
28
+ ### [v2.0.3](https://github.com/khiav223577/active_model_cachers/compare/v2.0.2...v2.0.3) 2018/05/14
29
+ - [#28](https://github.com/khiav223577/active_model_cachers/pull/28) No need to dump all association caches (@khiav223577)
30
+
31
+ ### [v2.0.2](https://github.com/khiav223577/active_model_cachers/compare/v2.0.1...v2.0.2) 2018/05/14
32
+ - [#27](https://github.com/khiav223577/active_model_cachers/pull/27) [Fix] will send query even if has one association is cached (@khiav223577)
33
+
34
+ ### [v2.0.1](https://github.com/khiav223577/active_model_cachers/compare/v2.0.0...v2.0.1) 2018/05/13
35
+ - [#26](https://github.com/khiav223577/active_model_cachers/pull/26) Prevent infinite loop if someone override default associations' method (@khiav223577)
36
+
37
+ ### v2.0.0 2018/05/13
38
+ - [#25](https://github.com/khiav223577/active_model_cachers/pull/25) Support cache self by other column (@khiav223577)
39
+ - [#24](https://github.com/khiav223577/active_model_cachers/pull/24) Support cleaning the cache manually (@khiav223577)
40
+ - [#23](https://github.com/khiav223577/active_model_cachers/pull/23) use loaded model if possible to prevent extra queries (@khiav223577)
41
+ - [#22](https://github.com/khiav223577/active_model_cachers/pull/22) Support caching result from outer service (@khiav223577)
42
+ - [#21](https://github.com/khiav223577/active_model_cachers/pull/21) Support writing query in instance scope (@khiav223577)
43
+ - [#20](https://github.com/khiav223577/active_model_cachers/pull/20) instance cacher (@khiav223577)
44
+ - [#19](https://github.com/khiav223577/active_model_cachers/pull/19) Pass model to `delete` method to prevent an extra query (@khiav223577)
45
+ - [#18](https://github.com/khiav223577/active_model_cachers/pull/18) [Test] show all sql queries if query count doesn't equal to expected count. (@khiav223577)
46
+ - [#17](https://github.com/khiav223577/active_model_cachers/pull/17) Support cache at has_many association II - add test cases (@khiav223577)
47
+ - [#16](https://github.com/khiav223577/active_model_cachers/pull/16) Support cache at has_many association I (@khiav223577)
48
+ - [#15](https://github.com/khiav223577/active_model_cachers/pull/15) Adjust file structures (@khiav223577)
49
+ - [#14](https://github.com/khiav223577/active_model_cachers/pull/14) Support cache at belongs_to association (@khiav223577)
50
+ - [#13](https://github.com/khiav223577/active_model_cachers/pull/13) Fix that cache not cleaned if foreign_key is not `id` and calling `mode.delete` (@khiav223577)
51
+ - [#12](https://github.com/khiav223577/active_model_cachers/pull/12) [Refactor] move the active_record extension to proper directory (@khiav223577)
52
+ - [#11](https://github.com/khiav223577/active_model_cachers/pull/11) Fix id problem by specify foreign_key manually (@khiav223577)
53
+ - [#10](https://github.com/khiav223577/active_model_cachers/pull/10) cache on falsy result (@khiav223577)
54
+ - [#9](https://github.com/khiav223577/active_model_cachers/pull/9) Fix that all models cache with same id will be cleaned if any of one is cleaned (@khiav223577)
55
+ - [#8](https://github.com/khiav223577/active_model_cachers/pull/8) allow developer to specify whether the cache should expire (@khiav223577)
56
+ - [#7](https://github.com/khiav223577/active_model_cachers/pull/7) custom query which allow you to specify how to expire the cache by `expire_by` option (@khiav223577)
57
+ - [#6](https://github.com/khiav223577/active_model_cachers/pull/6) test cache self (@khiav223577)
58
+ - [#5](https://github.com/khiav223577/active_model_cachers/pull/5) Deal with delete, dependent: :delete that do not fire after_commit callback (@khiav223577)
59
+ - [#4](https://github.com/khiav223577/active_model_cachers/pull/4) split test cases to several files and refactor the code (@khiav223577)
60
+ - [#3](https://github.com/khiav223577/active_model_cachers/pull/3) Safer cache mechanism: Prevent cache from being left over if someone forgets to write `cache_self` (@khiav223577)
61
+ - [#2](https://github.com/khiav223577/active_model_cachers/pull/2) Adjust usage (@khiav223577)
62
+ - [#1](https://github.com/khiav223577/active_model_cachers/pull/1) use after_commit hook to expire cached associations (@khiav223577)
data/CODE_OF_CONDUCT.md CHANGED
@@ -1,49 +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
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
49
  [version]: http://contributor-covenant.org/version/1/3/0/
data/LICENSE.txt CHANGED
@@ -1,21 +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.
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.
data/README.md CHANGED
@@ -15,7 +15,7 @@ ActiveModelCachers:
15
15
  - Supports ActiveRecord 3, 4 and 5
16
16
  - Has high test coverage
17
17
 
18
- ### Table of contents
18
+ ## Table of contents
19
19
 
20
20
  1. [Compare with identity_cache](#compare-with-identity_cache)
21
21
  2. [Installation](#installation)
@@ -31,9 +31,9 @@ ActiveModelCachers:
31
31
 
32
32
  ## Compare with [identity_cache](https://github.com/Shopify/identity_cache)
33
33
 
34
- `active_model_cachers` allows you to specify what to cache and when to expire those caches, so that you can cache raw sql query results, time-consuming methods, responses of requests, and so on. It also supports AR associations/attibutes (has_many, has_one, belongs_to) and secondary indexes.
34
+ `active_model_cachers` allows you to specify what to cache and when to expire those caches, so that you can cache raw sql query results, time-consuming methods, responses of requests, and so on. It also supports AR associations/attributes (has_many, has_one, belongs_to) and secondary indexes.
35
35
 
36
- `identity_cache` focuses on AR, and doesn't have the flexibility to specify the query.`identity_cache` has more features for caching AR associations/attibutes. Some of these feature are: Caching attibutes by multiple keys, embedding associations to load data in one fetch, non-unique secondary indexes, and caching polymorphic associations.
36
+ `identity_cache` focuses on AR, and doesn't have the flexibility to specify the query.`identity_cache` has more features for caching AR associations/attributes. Some of these feature are: Caching attributes by multiple keys, embedding associations to load data in one fetch, non-unique secondary indexes, and caching polymorphic associations.
37
37
 
38
38
  Another important difference is that `active_model_cachers` encapsulates methods to `cacher`, while `identity_cache` adds a number of `fetch_*` method to `AR` directly, therefore it's more possible to have method name collision when using `identity_cache`.
39
39
 
@@ -76,7 +76,7 @@ Parameters:
76
76
 
77
77
  ### Access the cached attributes
78
78
 
79
- "To avoid method name collision, all methods will be defined on the `Cacher` instead of `ActiveModel`. You can get the `cacher` from the class or from the instance (e.g. `User.cacher` or `user.cacher`), then access cached attributes via the method defined by `cache_at` (e.g. `user.cacher.the_attribute_name`)."
79
+ To avoid method name collision, all methods will be defined on the `Cacher` instead of `ActiveModel`. You can get the `cacher` from the class or from the instance (e.g. `User.cacher` or `user.cacher`), then access cached attributes via the method defined by `cache_at` (e.g. `user.cacher.the_attribute_name`).
80
80
 
81
81
  ### Basic Example
82
82
  ```rb
@@ -121,15 +121,28 @@ end
121
121
  You could use the cacher from the instance scope, e.g. `user.cacher`, instead of `User.cacher`. The difference is that the `binding` of query lambda is changed. In this example, you can write the query as `posts.exists?` which is in instance scope. The binding of the lambda is `user`, not `User`, so that it accesses `posts` method of `user`.
122
122
 
123
123
  ```rb
124
+ # Access cacher from instance
124
125
  class User < ActiveRecord::Base
125
126
  has_many :posts
126
127
  cache_at :has_post?, ->{ posts.exists? }, expire_by: :posts
127
128
  end
128
129
 
129
- do_something if current_user.cacher.has_post?
130
+ user = User.take
131
+ do_something if user.cacher.has_post?
130
132
  ```
131
133
 
132
- In this example, the cache should be cleaned when the `posts` of the user is changed. If you set `expire_by` to the association: `:posts`, it will do all the work for you (It actually sets [`expire_by`](#expire_by) to `Post#user_id` and [`foreign_key`](#foreign_key), which is needed for backtracing the user id from post, to `:user_id`).
134
+ ```rb
135
+ # Access cacher from class (It's useful when you don't want to do an extra query)
136
+ class User < ActiveRecord::Base
137
+ has_many :posts
138
+ cache_at :has_post?, ->(id){ Post.where(user_id: id).exists? }, expire_by: :posts
139
+ end
140
+
141
+ user_id = 1
142
+ do_something if User.cacher_at(user_id).has_post?
143
+ ```
144
+
145
+ In this example, the cache should be cleaned when the `posts` of the user is changed. If you set `expire_by` to the association: `:posts`, it will do all the work for you (It actually sets [`expire_by`](#expire_by) to `Post#user_id` and [`foreign_key`](#foreign_key), which is needed for backtracing the user id from post, to `:user_id`).
133
146
 
134
147
 
135
148
  ### Example 4: Pass an argument to the query lambda
@@ -313,11 +326,11 @@ Monitor on the specific model. Clean the cached objects if targets are changed.
313
326
  - If symbol, e.g. `:posts`: Monitoring on the association. It will monitor all attributes of `Post` and set the `foreign_key'.
314
327
 
315
328
  - The default value depends on the `name`. If `name`:
316
-
329
+
317
330
  - Is an association, monitoring the association klass
318
-
331
+
319
332
  - Is an attribute, monitoring current klass and the attribute name
320
-
333
+
321
334
  - In other cases, monitoring nothing
322
335
 
323
336
  ### :on
@@ -356,7 +369,7 @@ Monitor on the specific model. Clean the cached objects if targets are changed.
356
369
 
357
370
  - [ ] caching polymorphic associations
358
371
  - [ ] non-unique secondary indexes
359
- - [ ] caching attibutes by multiple keys
372
+ - [ ] caching attributes by multiple keys
360
373
  - [ ] testing counter cache
361
374
  - [ ] testing has_many through
362
375
  - [ ] testing has_and_belongs_to_many
data/Rakefile CHANGED
@@ -1,10 +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
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
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
27
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
28
  spec.require_paths = ["lib"]
29
29
 
30
- spec.add_development_dependency "bundler", "~> 1.11"
30
+ spec.add_development_dependency 'bundler', '>= 1.17', '< 3.x'
31
31
  spec.add_development_dependency "rake", "~> 12.0"
32
32
  spec.add_development_dependency "sqlite3", "~> 1.3"
33
33
  spec.add_development_dependency "minitest", "~> 5.0"
data/bin/console CHANGED
@@ -1,14 +1,14 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "active_model_cachers"
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
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "active_model_cachers"
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