active_cached_resource 0.1.4 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/lib/active_cached_resource/caching.rb +5 -5
- data/lib/active_cached_resource/model.rb +15 -0
- data/lib/active_cached_resource/version.rb +1 -1
- data/lib/activeresource/lib/active_resource/collection.rb +20 -2
- metadata +18 -4
- /data/lib/generators/active_cached_resource/{install_generator.rb → active_record_generator.rb} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7398b81424e7d34365729859220d5d05265452e4c7d8024f123b5a18f0490f0
|
4
|
+
data.tar.gz: 0c8b48b2cecec7992a5170b3467839cf7c4e9d13f141d552a9206f9eccc5527d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea69cc9271151a45decccb33a3e52275d05bd0dc0d4244472305e6b050479fb51431f42c13705f19a380bf0cfe1dba1e1242ff6480b4b23992fb850c25df32dd
|
7
|
+
data.tar.gz: '0807a7648e90ffd1e4a0c5650d52c15f67438a9a84366cf9a2563cd775ecd92a68f9fe0d816a8dac80f09f277623928b717a9f25f33fe1c484cb8617da367bc6'
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
## [0.1.6] - 2024-01-15
|
2
|
+
- Renamed `ActiveResource::Collection#refresh` to `#reload` to match Rails ORM naming convention.
|
3
|
+
- Added a `ActiveResource::Collection.none` class method similar to Rails `ActiveRecord::QueryMethods.none`
|
4
|
+
- Enhanced `ActiveResource::Collection#where` so that it returns `ActiveResource::Collection.none` if `resource_class` is missing.
|
5
|
+
- This is useful for when `where` clauses are chained on an empty `ActiveResource::Collection`
|
6
|
+
|
7
|
+
## [0.1.5] - 2024-01-09
|
8
|
+
- Added callbacks to cache:
|
9
|
+
- Create/POST, refresh cache after successful POST request
|
10
|
+
- Update/PUT, refresh cache after successful PUT request
|
11
|
+
- Destroy/DELETE, invalidate cache after successful DELETE request
|
12
|
+
- Fixed issue with generator for SQLCache strategy tables
|
13
|
+
|
1
14
|
## [0.1.4] - 2024-12-20
|
2
15
|
- CI Improvements
|
3
16
|
- Added annotations
|
@@ -140,13 +140,13 @@ module ActiveCachedResource
|
|
140
140
|
should_reload ? find_via_reload(*args) : find_via_cache(*args)
|
141
141
|
end
|
142
142
|
|
143
|
-
# Clears
|
144
|
-
#
|
145
|
-
# This method clears all cached entries that match the cache key prefix.
|
143
|
+
# Clears the cache for the specified pattern.
|
146
144
|
#
|
145
|
+
# @param pattern [String, nil] The pattern to match cache keys against.
|
146
|
+
# If nil, all cache keys with this models prefix will be cleared.
|
147
147
|
# @return [void]
|
148
|
-
def clear_cache
|
149
|
-
cached_resource.cache.clear("#{cache_key_prefix}
|
148
|
+
def clear_cache(pattern = nil)
|
149
|
+
cached_resource.cache.clear("#{cache_key_prefix}/#{pattern}")
|
150
150
|
end
|
151
151
|
|
152
152
|
private
|
@@ -8,6 +8,11 @@ module ActiveCachedResource
|
|
8
8
|
extend ActiveSupport::Concern
|
9
9
|
|
10
10
|
included do
|
11
|
+
before_save :invalidate_cache
|
12
|
+
|
13
|
+
after_save :save_to_cache
|
14
|
+
after_destroy :invalidate_cache
|
15
|
+
|
11
16
|
class << self
|
12
17
|
attr_accessor :cached_resource
|
13
18
|
|
@@ -47,5 +52,15 @@ module ActiveCachedResource
|
|
47
52
|
end
|
48
53
|
end
|
49
54
|
# :nodoc:
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def invalidate_cache
|
59
|
+
self.class.clear_cache(id.to_s)
|
60
|
+
end
|
61
|
+
|
62
|
+
def save_to_cache
|
63
|
+
self.class.send(:cache_write, self, id)
|
64
|
+
end
|
50
65
|
end
|
51
66
|
end
|
@@ -21,6 +21,23 @@ module ActiveResource # :nodoc:
|
|
21
21
|
attr_writer :prefix_options
|
22
22
|
attr_reader :from
|
23
23
|
|
24
|
+
# Returns a frozen empty collection.
|
25
|
+
#
|
26
|
+
# @return [ActiveResource::Collection] an empty collection
|
27
|
+
def self.none
|
28
|
+
new([]).tap do |collection|
|
29
|
+
collection.instance_variable_set(:@requested, true)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Creates a new ActiveResource::Collection instance.
|
34
|
+
#
|
35
|
+
# ==== Arguments
|
36
|
+
#
|
37
|
+
# +elements+ (Array<Object>) - An optional array of resources to be set as the collection elements.
|
38
|
+
# Defaults to an empty array.
|
39
|
+
# +from+ (String, Symbol) - The path to the collection resource or the symbol for the collection resource.
|
40
|
+
|
24
41
|
# ActiveResource::Collection is a wrapper to handle parsing index responses that
|
25
42
|
# do not directly map to Rails conventions.
|
26
43
|
#
|
@@ -98,12 +115,12 @@ module ActiveResource # :nodoc:
|
|
98
115
|
@prefix_options || {}
|
99
116
|
end
|
100
117
|
|
101
|
-
#
|
118
|
+
# Reload the collection by re-fetching the resources from the API.
|
102
119
|
#
|
103
120
|
# ==== Returns
|
104
121
|
#
|
105
122
|
# [Array<Object>] The collection of resources retrieved from the API.
|
106
|
-
def
|
123
|
+
def reload
|
107
124
|
@requested = false
|
108
125
|
request_resources!
|
109
126
|
end
|
@@ -182,6 +199,7 @@ module ActiveResource # :nodoc:
|
|
182
199
|
# # => PostCollection:xxx (filtered collection)
|
183
200
|
def where(clauses = {})
|
184
201
|
raise ArgumentError, "expected a clauses Hash, got #{clauses.inspect}" unless clauses.is_a? Hash
|
202
|
+
return self.class.none if resource_class.nil?
|
185
203
|
new_clauses = query_params.merge(clauses)
|
186
204
|
resource_class.where(new_clauses)
|
187
205
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_cached_resource
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jean Luis Urena
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date:
|
10
|
+
date: 2025-01-15 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: activemodel-serializers-xml
|
@@ -71,6 +71,20 @@ dependencies:
|
|
71
71
|
- - ">="
|
72
72
|
- !ruby/object:Gem::Version
|
73
73
|
version: 1.7.5
|
74
|
+
- !ruby/object:Gem::Dependency
|
75
|
+
name: ostruct
|
76
|
+
requirement: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - "~>"
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 0.6.1
|
81
|
+
type: :runtime
|
82
|
+
prerelease: false
|
83
|
+
version_requirements: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - "~>"
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: 0.6.1
|
74
88
|
email:
|
75
89
|
- eljean@live.com
|
76
90
|
executables: []
|
@@ -117,7 +131,7 @@ files:
|
|
117
131
|
- lib/activeresource/lib/active_resource/threadsafe_attributes.rb
|
118
132
|
- lib/activeresource/lib/active_resource/validations.rb
|
119
133
|
- lib/activeresource/lib/activeresource.rb
|
120
|
-
- lib/generators/active_cached_resource/
|
134
|
+
- lib/generators/active_cached_resource/active_record_generator.rb
|
121
135
|
- lib/generators/active_cached_resource/templates/migration.erb
|
122
136
|
homepage: https://github.com/jlurena/active_cached_resource
|
123
137
|
licenses: []
|
@@ -141,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
141
155
|
- !ruby/object:Gem::Version
|
142
156
|
version: '0'
|
143
157
|
requirements: []
|
144
|
-
rubygems_version: 3.6.
|
158
|
+
rubygems_version: 3.6.2
|
145
159
|
specification_version: 4
|
146
160
|
summary: ActiveResource, but with a caching layer.
|
147
161
|
test_files: []
|
/data/lib/generators/active_cached_resource/{install_generator.rb → active_record_generator.rb}
RENAMED
File without changes
|