active_record_in_cache 0.1.0 → 1.0.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f1856979c4ee921d727ddd9c891005c7e93c674baf5064cb5241bfcc47d63d47
4
- data.tar.gz: 6337a0417c2094b1d2bfb24d880a1f331d74474d75c1bd14378d3494d1af8217
3
+ metadata.gz: 28ebd1d181edc8f09c7e1235bf95de5332cb95ac1e61af23a9e76d97f2d92408
4
+ data.tar.gz: edbfe182ba09b12e88ea470e78dbb076381191e1e7bd86ed09b2f23e295cb136
5
5
  SHA512:
6
- metadata.gz: 6c6cb6efe65e2e44dd04ce1b4d5e50833bbf1ed24bfe72932cb0c0e6e4988d511bed5e3d337634a3a2f98c234127ab095fb4a04136b69f4ea7666ea85ea97ac8
7
- data.tar.gz: ca58055d8ab596744f061a0ec8b3ed36ad5b1d49a11cbe867f868f3fdf2f7082ad5913db29b153b1bd2de4c86dbc03baffd8aad2c7a3954b9c1690eab466b50b
6
+ metadata.gz: 70866938a12b79bca026b802e15c22d5016f5bfe33b99de372215b875bd8f2d2a862a411739145f06cdfcedc7d836be8b0ea9ff539400923078996e8a283214a
7
+ data.tar.gz: dc8d90b2af4ed7f928a2e3370395d03564a4991522c49d75b1afc340198626ad9ca658338e0764b0a34cbe8cc2c3666f7d41f1c4882cf5e98301cea0ef177e50
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Gem Version](https://badge.fury.io/rb/active_record_in_cache.svg)](https://badge.fury.io/rb/active_record_in_cache)
2
+
1
3
  # ActiveRecordInCache
2
4
 
3
5
  `ActiveRecordInCache` provides a method to execute SQL while automatically caching.
@@ -33,9 +35,14 @@ end
33
35
  You can call the `in_cache` method at the end of the chain.
34
36
 
35
37
  ```ruby
36
- def index
37
- @articles = Article.published.in_cache
38
- end
38
+ Article.all.in_cache
39
+ # SELECT MAX("articles"."updated_at") FROM "articles"
40
+ # SELECT "articles".* FROM "articles"
41
+ #=> #<ActiveRecord::Relation ...>
42
+
43
+ Article.all.in_cache
44
+ # SELECT MAX("articles"."updated_at") FROM "articles"
45
+ #=> #<ActiveRecord::Relation ...>
39
46
  ```
40
47
 
41
48
  Automatically check `maximum(:updated_at)` and use the cache if it exists.
@@ -36,8 +36,9 @@ module ActiveRecordInCache
36
36
  #
37
37
  # Article.all.in_cache(expires_in: 5.minutes)
38
38
  #
39
- def in_cache(column = :updated_at, options = {})
40
- name = "#{all.to_sql}_#{all.maximum(column)}"
39
+ def in_cache(column = :updated_at, options = {}, &block)
40
+ value = block_given? ? all.instance_exec(&block) : all.maximum(column)
41
+ name = "#{all.to_sql}_#{value}"
41
42
  Rails.cache.fetch(name, options) { all.to_a }
42
43
  end
43
44
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveRecordInCache
2
- VERSION = "0.1.0"
2
+ VERSION = "1.0.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record_in_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - sinsoku
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-06-25 00:00:00.000000000 Z
11
+ date: 2019-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails