active_remote-cached 1.0.0 → 1.1.1

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: c89a29c20fea4fff1a59ab534285774e7758620a73fc4005866011326b67ddbe
4
- data.tar.gz: 1fbb57ba895a2aedb8067e399ac747cd6428b2e11c18c043e0fc9fbd8e3a63a1
3
+ metadata.gz: b6ac1efd0991c3ee528e08b55099bf6f05a6c1eb243f290e4197be290b725dca
4
+ data.tar.gz: 34229f667ea990196cf2593fe31207532ddbc60fdd72904c8ff618a5e9b3c5c1
5
5
  SHA512:
6
- metadata.gz: e07972d8b297ad00be81d09dc05330075db0f744d6d40f0323135f326368846325cc66975f8771260d14ba5cd96156c36e134e9bf500df4bff924d6bdcc9ef82
7
- data.tar.gz: 5a1818958e13bac846e04616c1762f1fdbb3d7e5e664d8d7c56e86b36e1fa10d608bf242bd666e43ba1bea5eef6f3a17be01e2c1f715bab205413aabe3a764eb
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in active_remote-cached.gemspec
data/Rakefile CHANGED
@@ -1,10 +1,12 @@
1
- require "bundler/gem_tasks"
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 "lib"
6
- t.libs.push "spec"
7
- t.pattern = "spec/**/*_spec.rb"
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
- # -*- encoding: utf-8 -*-
2
- lib = File.expand_path('../lib', __FILE__)
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 = "active_remote-cached"
10
+ gem.name = 'active_remote-cached'
8
11
  gem.version = ActiveRemote::Cached::VERSION
9
- gem.authors = ["Brandon Dewitt", "MXDevExperience"]
10
- gem.email = ["brandonsdewitt@gmail.com", "devexperience@mx.com"]
11
- gem.description = %q{ Provides "cached" finders and a DSL to enumerate which finders should have cached versions }
12
- gem.summary = %q{ Provides a configuration for caching mechanisms and finders on ActiveRemote models that are cached/cacheable }
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.files = `git ls-files`.split($/)
16
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
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 = ["lib"]
22
+ gem.require_paths = ['lib']
19
23
 
20
- gem.add_dependency "active_remote"
21
- gem.add_dependency "activesupport"
24
+ gem.add_dependency 'active_remote', '>= 6.1'
25
+ gem.add_dependency 'activesupport'
22
26
 
23
- gem.add_development_dependency "bundler"
24
- gem.add_development_dependency "mocha"
25
- gem.add_development_dependency "pry"
26
- gem.add_development_dependency "rake"
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::Cached
2
- class ArgumentKeys
3
- attr_reader :arguments, :argument_string, :options
4
-
5
- REMOVE_CHARACTERS = /[[:space:]+=><{}\[\];:\-,]/
6
- REPLACE_MAP = [
7
- [" ", "SP"],
8
- ["+", "PL"],
9
- ["=", "EQ"],
10
- [">", "GT"],
11
- ["<", "LT"],
12
- ["{", "LB"],
13
- ["}", "RB"],
14
- ["[", "LB2"],
15
- ["]", "RB2"],
16
- [";", "SC"],
17
- [":", "CO"],
18
- ["-", "DA"],
19
- [",", "COM"],
20
- ].freeze
21
-
22
- def initialize(*arguments, options)
23
- @options = options
24
- @arguments = arguments.flatten.compact
25
- @argument_string = ""
26
-
27
- @arguments.each do |argument|
28
- @argument_string << "#{argument}"
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
- def cache_key
33
- return @argument_string.gsub(REMOVE_CHARACTERS, "") if remove_characters?
34
- if replace_characters?
35
- REPLACE_MAP.each do |character, replacement|
36
- @argument_string.gsub!(character, replacement)
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
- @argument_string
41
- end
42
+ @argument_string
43
+ end
42
44
 
43
- def to_s
44
- cache_key
45
- end
45
+ def to_s
46
+ cache_key
47
+ end
46
48
 
47
- private
49
+ private
48
50
 
49
- def remove_characters?
50
- options.fetch(:active_remote_cached_remove_characters, false)
51
- end
51
+ def remove_characters?
52
+ options.fetch(:active_remote_cached_remove_characters, false)
53
+ end
52
54
 
53
- def replace_characters?
54
- options.fetch(:active_remote_cached_replace_characters, false)
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::Cached
4
- class Cache < ::SimpleDelegator
5
- attr_reader :cache_provider
5
+ module ActiveRemote
6
+ module Cached
7
+ class Cache < ::SimpleDelegator
8
+ attr_reader :cache_provider
6
9
 
7
- def initialize(new_cache_provider)
8
- @cache_provider = new_cache_provider
9
- @nested_cache_provider = ::ActiveSupport::Cache::NullStore.new
10
+ def initialize(new_cache_provider)
11
+ @cache_provider = new_cache_provider
12
+ @nested_cache_provider = ::ActiveSupport::Cache::NullStore.new
10
13
 
11
- validate_provider_method_present(:delete)
12
- validate_provider_method_present(:exist?)
13
- validate_provider_method_present(:fetch)
14
- validate_provider_method_present(:read)
15
- validate_provider_method_present(:write)
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
- super(@cache_provider)
18
- end
20
+ super(@cache_provider)
21
+ end
19
22
 
20
- def delete(*args)
21
- nested_cache_provider.delete(*args)
22
- super
23
- end
23
+ def delete(*args)
24
+ nested_cache_provider.delete(*args)
25
+ super
26
+ end
24
27
 
25
- def enable_nested_caching!
26
- @nested_cache_provider = ::ActiveSupport::Cache::MemoryStore.new
27
- end
28
+ def enable_nested_caching!
29
+ @nested_cache_provider = ::ActiveSupport::Cache::MemoryStore.new
30
+ end
28
31
 
29
- def exist?(*args)
30
- nested_cache_provider.exist?(*args) || super
31
- end
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
- def fetch(name, options = {})
34
- fetch_value = nested_cache_provider.fetch(name, options) { super }
39
+ delete(name) unless valid_fetched_value?(fetch_value, options)
35
40
 
36
- unless valid_fetched_value?(fetch_value, options)
37
- delete(name)
41
+ fetch_value
38
42
  end
39
43
 
40
- return fetch_value
41
- end
44
+ def read(*args)
45
+ nested_cache_provider.read(*args) || super
46
+ end
42
47
 
43
- def read(*args)
44
- nested_cache_provider.read(*args) || super
45
- end
48
+ def write(*args)
49
+ nested_cache_provider.write(*args)
50
+ super
51
+ end
46
52
 
47
- def write(*args)
48
- nested_cache_provider.write(*args)
49
- super
50
- end
53
+ private
51
54
 
52
- private
55
+ attr_reader :nested_cache_provider
53
56
 
54
- def nested_cache_provider
55
- @nested_cache_provider
56
- end
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
- def valid_fetched_value?(value, options = {})
59
- return false if value.nil? && !options.fetch(:allow_nil, false)
60
- return false if !options.fetch(:allow_empty, false) && value.respond_to?(:empty?) && value.empty?
61
- return true
62
- end
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
- def validate_provider_method_present(method_name)
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
- CACHE_METHOD
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 "active_remote-cached.initialize_cache" do |app|
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 => config.active_remote_cached.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
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveRemote
2
4
  module Cached
3
- VERSION = "1.0.0"
5
+ VERSION = '1.1.1'
4
6
  end
5
7
  end