active_remote-cached 0.2.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +55 -0
- data/Gemfile +2 -0
- data/Rakefile +6 -4
- data/active_remote-cached.gemspec +23 -17
- data/lib/active_remote/cached/argument_keys.rb +49 -46
- data/lib/active_remote/cached/cache.rb +50 -49
- data/lib/active_remote/cached/railtie.rb +5 -5
- data/lib/active_remote/cached/version.rb +3 -1
- data/lib/active_remote/cached.rb +149 -84
- data/lib/active_remote-cached.rb +3 -1
- data/spec/active_remote/cached/argument_keys_spec.rb +12 -10
- data/spec/active_remote/cached/cache_spec.rb +13 -16
- data/spec/active_remote/cached_delete_methods_spec.rb +19 -12
- data/spec/active_remote/cached_exist_methods_spec.rb +40 -33
- data/spec/active_remote/cached_find_methods_spec.rb +64 -51
- data/spec/active_remote/cached_search_methods_spec.rb +153 -102
- data/spec/spec_helper.rb +5 -10
- metadata +41 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6ac1efd0991c3ee528e08b55099bf6f05a6c1eb243f290e4197be290b725dca
|
4
|
+
data.tar.gz: 34229f667ea990196cf2593fe31207532ddbc60fdd72904c8ff618a5e9b3c5c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e38d49aedda27d13809af64e7f939bd2578dc8f45a3f0f657f0dabf4bae5e3f376078ae6b16bf8765a3e8e7d198f93fb7105e292e7555a1e86927d879c4992ad
|
7
|
+
data.tar.gz: 1c4f37e645e020daf1e4523e6788aa397a1d23a7bda1f59e4335bc17d1501eaaf5343ce7d94a72134d1f56a581099021456f391051dd3f841a432cb627c0d20b
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 3.1
|
3
|
+
Exclude:
|
4
|
+
- 'gemfiles/**/*'
|
5
|
+
|
6
|
+
Layout/AccessModifierIndentation:
|
7
|
+
Enabled: false
|
8
|
+
Layout/CommentIndentation:
|
9
|
+
Enabled: false
|
10
|
+
Layout/IndentationConsistency:
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
Style/AccessModifierDeclarations:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Naming/MethodParameterName:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Metrics/BlockLength:
|
20
|
+
Exclude:
|
21
|
+
- 'spec/**/*'
|
22
|
+
|
23
|
+
Naming/FileName:
|
24
|
+
Exclude:
|
25
|
+
- 'lib/active_remote-cached.rb'
|
26
|
+
|
27
|
+
|
28
|
+
Metrics/ModuleLength:
|
29
|
+
Exclude:
|
30
|
+
- 'lib/active_remote/cached.rb' # this module is big
|
31
|
+
|
32
|
+
Style/Documentation:
|
33
|
+
Enabled: false
|
34
|
+
|
35
|
+
Metrics/MethodLength:
|
36
|
+
Enabled: false
|
37
|
+
|
38
|
+
Naming/VariableNumber:
|
39
|
+
Enabled: false
|
40
|
+
|
41
|
+
Style/HashSyntax:
|
42
|
+
Description: >-
|
43
|
+
Prefer Ruby 1.8 hash syntax { :a => 1, :b => 2 }
|
44
|
+
over 1.9 syntax { a: 1, b: 2 }.
|
45
|
+
StyleGuide: 'https://git.moneydesktop.com/dev/ruby-style-guide#hash-literals'
|
46
|
+
EnforcedStyle: hash_rockets
|
47
|
+
Exclude:
|
48
|
+
- 'Gemfile'
|
49
|
+
|
50
|
+
# Use lambdas instead of stabbys
|
51
|
+
Style/Lambda:
|
52
|
+
EnforcedStyle: lambda
|
53
|
+
|
54
|
+
Style/MissingRespondToMissing:
|
55
|
+
Enabled: false
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
2
4
|
require 'rake/testtask'
|
3
5
|
|
4
6
|
Rake::TestTask.new do |t|
|
5
|
-
t.libs.push
|
6
|
-
t.libs.push
|
7
|
-
t.pattern =
|
7
|
+
t.libs.push 'lib'
|
8
|
+
t.libs.push 'spec'
|
9
|
+
t.pattern = 'spec/**/*_spec.rb'
|
8
10
|
t.verbose = true
|
9
11
|
end
|
10
12
|
|
@@ -1,27 +1,33 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'English'
|
4
|
+
|
5
|
+
lib = File.expand_path('lib', __dir__)
|
3
6
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
7
|
require 'active_remote/cached/version'
|
5
8
|
|
6
9
|
Gem::Specification.new do |gem|
|
7
|
-
gem.name =
|
10
|
+
gem.name = 'active_remote-cached'
|
8
11
|
gem.version = ActiveRemote::Cached::VERSION
|
9
|
-
gem.authors = [
|
10
|
-
gem.email = [
|
11
|
-
gem.description =
|
12
|
-
gem.summary =
|
13
|
-
gem.homepage =
|
12
|
+
gem.authors = ['Brandon Dewitt', 'MXDevExperience']
|
13
|
+
gem.email = ['brandonsdewitt@gmail.com', 'devexperience@mx.com']
|
14
|
+
gem.description = ' Provides "cached" finders and a DSL to enumerate which finders should have cached versions '
|
15
|
+
gem.summary = ' Provides a configuration for caching mechanisms and finders on ActiveRemote models'
|
16
|
+
gem.homepage = ''
|
14
17
|
|
15
|
-
gem.
|
16
|
-
gem.
|
18
|
+
gem.required_ruby_version = '>= 2.6'
|
19
|
+
gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
20
|
+
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
17
21
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
-
gem.require_paths = [
|
22
|
+
gem.require_paths = ['lib']
|
19
23
|
|
20
|
-
gem.add_dependency
|
21
|
-
gem.add_dependency
|
24
|
+
gem.add_dependency 'active_remote', '>= 6.1'
|
25
|
+
gem.add_dependency 'activesupport'
|
22
26
|
|
23
|
-
gem.add_development_dependency
|
24
|
-
gem.add_development_dependency
|
25
|
-
gem.add_development_dependency
|
26
|
-
gem.add_development_dependency
|
27
|
+
gem.add_development_dependency 'bundler'
|
28
|
+
gem.add_development_dependency 'mocha'
|
29
|
+
gem.add_development_dependency 'pry'
|
30
|
+
gem.add_development_dependency 'rake'
|
31
|
+
gem.add_development_dependency 'rspec', '>= 3.0'
|
32
|
+
gem.add_development_dependency 'rubocop'
|
27
33
|
end
|
@@ -1,57 +1,60 @@
|
|
1
|
-
module ActiveRemote
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
@
|
1
|
+
module ActiveRemote
|
2
|
+
module Cached
|
3
|
+
class ArgumentKeys
|
4
|
+
attr_reader :arguments, :argument_string, :options
|
5
|
+
|
6
|
+
REMOVE_CHARACTERS = /[[:space:]+=><{}\[\];:\-,]/
|
7
|
+
REPLACE_MAP = [
|
8
|
+
[' ', 'SP'],
|
9
|
+
['+', 'PL'],
|
10
|
+
['=', 'EQ'],
|
11
|
+
['>', 'GT'],
|
12
|
+
['<', 'LT'],
|
13
|
+
['{', 'LB'],
|
14
|
+
['}', 'RB'],
|
15
|
+
['[', 'LB2'],
|
16
|
+
[']', 'RB2'],
|
17
|
+
[';', 'SC'],
|
18
|
+
[':', 'CO'],
|
19
|
+
['-', 'DA'],
|
20
|
+
[',', 'COM']
|
21
|
+
].freeze
|
22
|
+
|
23
|
+
def initialize(*arguments, options)
|
24
|
+
@options = options
|
25
|
+
@arguments = arguments.flatten.compact
|
26
|
+
@argument_string = ''
|
27
|
+
|
28
|
+
@arguments.each do |argument|
|
29
|
+
@argument_string << argument.to_s
|
30
|
+
end
|
29
31
|
end
|
30
|
-
end
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
33
|
+
def cache_key
|
34
|
+
return @argument_string.gsub(REMOVE_CHARACTERS, '') if remove_characters?
|
35
|
+
|
36
|
+
if replace_characters?
|
37
|
+
REPLACE_MAP.each do |character, replacement|
|
38
|
+
@argument_string.gsub!(character, replacement)
|
39
|
+
end
|
37
40
|
end
|
38
|
-
end
|
39
41
|
|
40
|
-
|
41
|
-
|
42
|
+
@argument_string
|
43
|
+
end
|
42
44
|
|
43
|
-
|
44
|
-
|
45
|
-
|
45
|
+
def to_s
|
46
|
+
cache_key
|
47
|
+
end
|
46
48
|
|
47
|
-
|
49
|
+
private
|
48
50
|
|
49
|
-
|
50
|
-
|
51
|
-
|
51
|
+
def remove_characters?
|
52
|
+
options.fetch(:active_remote_cached_remove_characters, false)
|
53
|
+
end
|
52
54
|
|
53
|
-
|
54
|
-
|
55
|
+
def replace_characters?
|
56
|
+
options.fetch(:active_remote_cached_replace_characters, false)
|
57
|
+
end
|
55
58
|
end
|
56
59
|
end
|
57
60
|
end
|
@@ -1,72 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'delegate'
|
2
4
|
|
3
|
-
module ActiveRemote
|
4
|
-
|
5
|
-
|
5
|
+
module ActiveRemote
|
6
|
+
module Cached
|
7
|
+
class Cache < ::SimpleDelegator
|
8
|
+
attr_reader :cache_provider
|
6
9
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
+
def initialize(new_cache_provider)
|
11
|
+
@cache_provider = new_cache_provider
|
12
|
+
@nested_cache_provider = ::ActiveSupport::Cache::NullStore.new
|
10
13
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
validate_provider_method_present(:delete)
|
15
|
+
validate_provider_method_present(:exist?)
|
16
|
+
validate_provider_method_present(:fetch)
|
17
|
+
validate_provider_method_present(:read)
|
18
|
+
validate_provider_method_present(:write)
|
16
19
|
|
17
|
-
|
18
|
-
|
20
|
+
super(@cache_provider)
|
21
|
+
end
|
19
22
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
23
|
+
def delete(*args)
|
24
|
+
nested_cache_provider.delete(*args)
|
25
|
+
super
|
26
|
+
end
|
24
27
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
+
def enable_nested_caching!
|
29
|
+
@nested_cache_provider = ::ActiveSupport::Cache::MemoryStore.new
|
30
|
+
end
|
28
31
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
+
def exist?(*args)
|
33
|
+
nested_cache_provider.exist?(*args) || super
|
34
|
+
end
|
35
|
+
|
36
|
+
def fetch(name, options = {})
|
37
|
+
fetch_value = nested_cache_provider.fetch(name, options) { super }
|
32
38
|
|
33
|
-
|
34
|
-
fetch_value = nested_cache_provider.fetch(name, options) { super }
|
39
|
+
delete(name) unless valid_fetched_value?(fetch_value, options)
|
35
40
|
|
36
|
-
|
37
|
-
delete(name)
|
41
|
+
fetch_value
|
38
42
|
end
|
39
43
|
|
40
|
-
|
41
|
-
|
44
|
+
def read(*args)
|
45
|
+
nested_cache_provider.read(*args) || super
|
46
|
+
end
|
42
47
|
|
43
|
-
|
44
|
-
|
45
|
-
|
48
|
+
def write(*args)
|
49
|
+
nested_cache_provider.write(*args)
|
50
|
+
super
|
51
|
+
end
|
46
52
|
|
47
|
-
|
48
|
-
nested_cache_provider.write(*args)
|
49
|
-
super
|
50
|
-
end
|
53
|
+
private
|
51
54
|
|
52
|
-
|
55
|
+
attr_reader :nested_cache_provider
|
53
56
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
+
def valid_fetched_value?(value, options = {})
|
58
|
+
return false if value.nil? && !options.fetch(:allow_nil, false)
|
59
|
+
return false if !options.fetch(:allow_empty, false) && value.respond_to?(:empty?) && value.empty?
|
57
60
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
61
|
+
true
|
62
|
+
end
|
63
|
+
|
64
|
+
def validate_provider_method_present(method_name)
|
65
|
+
return if cache_provider.respond_to?(method_name)
|
63
66
|
|
64
|
-
|
65
|
-
unless self.cache_provider.respond_to?(method_name)
|
66
|
-
raise <<-CACHE_METHOD
|
67
|
+
raise <<-CACHE_METHOD
|
67
68
|
ActiveRemote::Cached::Cache must respond_to? #{method_name}
|
68
69
|
in order to be used as a caching interface for ActiveRemote
|
69
|
-
|
70
|
+
CACHE_METHOD
|
70
71
|
end
|
71
72
|
end
|
72
73
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'active_support/ordered_options'
|
2
4
|
|
3
5
|
module ActiveRemote
|
@@ -5,18 +7,16 @@ module ActiveRemote
|
|
5
7
|
class Railtie < ::Rails::Railtie
|
6
8
|
config.active_remote_cached = ::ActiveSupport::OrderedOptions.new
|
7
9
|
|
8
|
-
initializer
|
10
|
+
initializer 'active_remote-cached.initialize_cache' do |_app|
|
9
11
|
config.active_remote_cached.expires_in ||= 5.minutes
|
10
12
|
config.active_remote_cached.race_condition_ttl ||= 5.seconds
|
11
13
|
|
12
14
|
::ActiveRemote::Cached.cache(Rails.cache)
|
13
15
|
|
14
|
-
if config.active_remote_cached.enable_nested_caching
|
15
|
-
::ActiveRemote::Cached.cache.enable_nested_caching!
|
16
|
-
end
|
16
|
+
::ActiveRemote::Cached.cache.enable_nested_caching! if config.active_remote_cached.enable_nested_caching
|
17
17
|
|
18
18
|
::ActiveRemote::Cached.default_options(
|
19
|
-
:expires_in
|
19
|
+
:expires_in => config.active_remote_cached.expires_in,
|
20
20
|
:race_condition_ttl => config.active_remote_cached.race_condition_ttl
|
21
21
|
)
|
22
22
|
end
|