memoize_until 1.3.0 → 1.3.1

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: cef01fc07f2cd1bbce74ed4bfbd0037933dfe24e347e639090d2c009050cdf70
4
- data.tar.gz: 38107311086fa799d489bdf0eabf253ed599997cad8af56cb80db7104598743b
3
+ metadata.gz: 8d5800dd9464ea0e52a7c86dece3eba58dd9ac3c4aa4844d71619f7bdd18f740
4
+ data.tar.gz: 259618aa762f0c5000e77a5bd9926031290308f57c463962fb44a854ee7e7a2e
5
5
  SHA512:
6
- metadata.gz: 268c2cabb81fa7d67d205572eadb111f22348fa692e211780fb62beb46e1166c69bf0ccae3d626b9809718e1605ddfcdd1e91992eada7366ccf9ee33ad482f7f
7
- data.tar.gz: 6bc413d58e54c10c16284423d7b5af9ce4640faa9869f018691a24fe2e41d96f0b3a7bba054f007fedd834866af68bd46a926377e2fa3e1f34157e630a6e6997
6
+ metadata.gz: 1fa974aca2175396f8a18cebc69811332f08faeecfbcc0028d5c0c628b22eb02c1891949d50513ebed5aaaefb6a6d13bebbc21874afab048057eea3efcbef8a5
7
+ data.tar.gz: f6e5ff67499b9addec68276bbf0f6b2278baf371f2c0e7c927ae0852f713e0b8c71cc3c06022b0f142c7882c0e869b45d7083a18e263e48231ffc2d6e769edb4
@@ -0,0 +1,19 @@
1
+ name: "rubocop"
2
+ on:
3
+ push:
4
+ branches: [ "master" ]
5
+ pull_request:
6
+ branches: [ "master" ]
7
+ jobs:
8
+ lint:
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - name: Checkout code
12
+ uses: actions/checkout@v3
13
+ - name: Install Ruby and gems
14
+ uses: ruby/setup-ruby@v1
15
+ with:
16
+ ruby-version: '2.6.9'
17
+ bundler-cache: true
18
+ - name: Rubocop
19
+ run: bundle exec rubocop
@@ -0,0 +1,24 @@
1
+ name: minitest
2
+ on:
3
+ push:
4
+ branches: [ "master" ]
5
+ pull_request:
6
+ branches: [ "master" ]
7
+ permissions:
8
+ contents: read
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ ruby-version: [2.6.9, 2.7, 3.0, 3.1, 3.2]
15
+ steps:
16
+ - uses: actions/checkout@v3
17
+ - name: Set up Ruby
18
+ uses: ruby/setup-ruby@v1
19
+ with:
20
+ ruby-version: ${{ matrix.ruby-version }}
21
+ - name: Bundle Install
22
+ run: bundle install
23
+ - name: Run tests
24
+ run: rake
data/.rubocop.yml ADDED
@@ -0,0 +1,22 @@
1
+ require: rubocop-minitest
2
+
3
+ AllCops:
4
+ TargetRubyVersion: 2.6.9
5
+ NewCops: enable
6
+
7
+ Style/Documentation:
8
+ Enabled: false
9
+
10
+ Layout/LineLength:
11
+ Max: 175
12
+
13
+ Metrics/MethodLength:
14
+ Max: 15
15
+
16
+ Naming/AccessorMethodName:
17
+ Exclude:
18
+ - 'lib/memoize_until/store.rb'
19
+
20
+ Style/MutableConstant:
21
+ Exclude:
22
+ - 'lib/memoize_until/base.rb'
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
- ## 1.2.1 - 08 May, 2020
1
+ ## 1.3.1 - 21 April, 2023
2
+ * [DEPRECATION FIX] File.exists? is changed to File.exist?, since File.exists? is deprecated in Ruby 3.x. [#11](https://github.com/freshworks/memoize_until/pull/11). Thanks to [@ruban-thilak](https://github.com/ruban-thilak).
3
+ * [ENHANCEMENT] Add CI checks for rubocop and minitest via Github actions. [#12](https://github.com/freshworks/memoize_until/pull/12). Thanks to [@ruban-thilak](https://github.com/ruban-thilak).
4
+
5
+ ## 1.3.0 - 18 March, 2021
6
+ * [ENHANCEMENT] memoize_until is now thread safe [fc2b98f](https://github.com/freshworks/memoize_until/commit/fc2b98f197e641a5668ded1d332f9412fe231422). Thanks to [@ritikesh](https://github.com/ritikesh).
2
7
 
3
- * 🚀 [ENHANCEMENT] Public method `clear_now_for` added to `MemoizeUntil`, delegating the method to the underlying store object. This is done to support writing unit test cases without touching getting dirty with the private `Store` API. [#8](https://github.com/freshdesk/memoize_until/pull/8). Thanks to [@ritikesh](https://github.com/ritikesh).
8
+ ## 1.2.1 - 08 May, 2020
9
+ * [ENHANCEMENT] Public method `clear_now_for` added to `MemoizeUntil`, delegating the method to the underlying store object. This is done to support writing unit test cases without touching getting dirty with the private `Store` API. [#8](https://github.com/freshdesk/memoize_until/pull/8). Thanks to [@ritikesh](https://github.com/ritikesh).
data/Gemfile CHANGED
@@ -1,6 +1,8 @@
1
- source "https://rubygems.org"
1
+ # frozen_string_literal: true
2
2
 
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
6
 
5
7
  # Specify your gem's dependencies in memoize_until.gemspec
6
8
  gemspec
data/Rakefile CHANGED
@@ -1,10 +1,12 @@
1
- require "bundler/gem_tasks"
2
- require "rake/testtask"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rake/testtask'
3
5
 
4
6
  Rake::TestTask.new(:test) do |t|
5
- t.libs << "test"
6
- t.libs << "lib"
7
- t.test_files = FileList["test/**/*_test.rb"]
7
+ t.libs << 'test'
8
+ t.libs << 'lib'
9
+ t.test_files = FileList['test/**/*_test.rb']
8
10
  end
9
11
 
10
- task :default => :test
12
+ task default: :test
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.0
1
+ 1.3.1
@@ -1,26 +1,26 @@
1
- class MemoizeUntil
1
+ # frozen_string_literal: true
2
2
 
3
+ class MemoizeUntil
3
4
  memoizable_attributes = YAML.load_file("#{__dir__}/config/defaults.yml")
4
-
5
- if defined?(Rails) && File.exists?("#{Rails.root}/config/memoize_until.yml")
6
- memoizable_attributes.deep_merge!(YAML.load_file("#{Rails.root}/config/memoize_until.yml"))
5
+
6
+ if defined?(Rails) && File.exist?(Rails.root.join('/config/memoize_until.yml'))
7
+ memoizable_attributes.deep_merge!(YAML.load_file(Rails.root.join('/config/memoize_until.yml')))
7
8
  end
8
9
 
9
10
  TYPE_FACTORY = {}
10
11
  private_constant :TYPE_FACTORY
11
-
12
+
12
13
  memoizable_attributes.each do |kind, keys|
13
-
14
- TYPE_FACTORY[kind] = Store.new(kind)
15
-
16
- keys.each { |key|
14
+ TYPE_FACTORY[kind] = Store.new(kind)
15
+
16
+ keys.each do |key|
17
17
  TYPE_FACTORY[kind].add(key)
18
- }
19
-
18
+ end
19
+
20
20
  # Memoizes a complex operation for the pre-specified interval
21
21
  #
22
22
  # @param key [Symbol] the purpose defined in memoize_until.yml or :default.
23
-
23
+
24
24
  # @yield use this block to set the value to be memoized for the given moment
25
25
  #
26
26
  # @example Memoizing per day.
@@ -32,9 +32,8 @@ class MemoizeUntil
32
32
  define_singleton_method(kind) do |key, &block|
33
33
  TYPE_FACTORY[kind].fetch(key, &block)
34
34
  end
35
-
36
35
  end
37
-
36
+
38
37
  # Adds a purpose at runtime for the specified kind.
39
38
  #
40
39
  # @param kind [Symbol] one of the default or customised kind supported
@@ -47,7 +46,7 @@ class MemoizeUntil
47
46
  def self.add_to(kind, key)
48
47
  TYPE_FACTORY[kind].add(key)
49
48
  end
50
-
49
+
51
50
  # clears previously memoized value for "now" for the given key
52
51
  # only clears memory in the process that this code runs on.
53
52
  # added for supporting custom scripts / test cases
@@ -1,12 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class MemoizeUntil
2
-
3
- class NotImplementedError < StandardError; end
4
-
5
- class NullObject
6
-
7
- def self.instance
8
- @@null_object ||= NullObject.new
9
- end
10
-
11
- end
12
- end
4
+ class NotImplementedError < StandardError; end
5
+
6
+ class NullObject
7
+ @null_object ||= NullObject.new
8
+
9
+ def self.instance
10
+ @null_object
11
+ end
12
+ end
13
+ end
@@ -1,14 +1,16 @@
1
- class MemoizeUntil::Railtie < Rails::Railtie
2
-
3
- initializer "memoize_until.config_hook" do
4
- # initialising the memoize_until classes
5
- require 'memoize_until/base'
6
-
7
- # require extensions
8
- require 'memoize_until/extensions'
1
+ # frozen_string_literal: true
9
2
 
10
- # patches
11
- require 'memoize_until/time_patch'
3
+ class MemoizeUntil
4
+ class Railtie < Rails::Railtie
5
+ initializer 'memoize_until.config_hook' do
6
+ # initialising the memoize_until classes
7
+ require 'memoize_until/base'
8
+
9
+ # require extensions
10
+ require 'memoize_until/extensions'
11
+
12
+ # patches
13
+ require 'memoize_until/time_patch'
12
14
  end
13
-
14
- end
15
+ end
16
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class MemoizeUntil
2
4
  class Store
3
5
  attr_reader :_store, :_kind, :_mutex
@@ -11,7 +13,7 @@ class MemoizeUntil
11
13
  # returns the value from memory if already memoized for "now" for the given key
12
14
  # else evaluates the block and memoizes that
13
15
  # caches nils too
14
- def fetch(key, &block)
16
+ def fetch(key)
15
17
  now = Time.now.public_send(_kind)
16
18
  value = get(key, now)
17
19
 
@@ -69,8 +71,9 @@ class MemoizeUntil
69
71
  _mutex.synchronize do
70
72
  purpose = _store[key]
71
73
  raise NotImplementedError unless purpose
74
+
72
75
  purpose[now]
73
76
  end
74
77
  end
75
78
  end
76
- end
79
+ end
@@ -1,9 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  unless Time.instance_methods.include?(:week)
2
- module MemoizeUntil::TimePatch
3
- # returns number representing the nth week of the month
4
- def week
5
- self.day / 7
4
+ class MemoizeUntil
5
+ module TimePatch
6
+ # returns number representing the nth week of the month
7
+ def week
8
+ day / 7
9
+ end
6
10
  end
7
- end
8
- Time.prepend MemoizeUntil::TimePatch
9
- end
11
+ end
12
+ Time.prepend MemoizeUntil::TimePatch
13
+ end
data/lib/memoize_until.rb CHANGED
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # initialise the store and the memoize_until class
2
4
  require 'memoize_until/store'
3
5
 
4
6
  # require the railtie
5
- require 'memoize_until/railtie'
7
+ require 'memoize_until/railtie'
@@ -1,37 +1,41 @@
1
- # coding: utf-8
2
- lib = File.expand_path("../lib", __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- version = File.read(File.expand_path("VERSION", __dir__)).strip
5
+ version = File.read(File.expand_path('VERSION', __dir__)).strip
5
6
 
6
7
  Gem::Specification.new do |spec|
7
- spec.name = "memoize_until"
8
+ spec.name = 'memoize_until'
8
9
  spec.version = version
9
- spec.authors = ["Ritikesh"]
10
- spec.email = ["ritikesh.ganpathraj@freshworks.com"]
10
+ spec.authors = ['Ritikesh']
11
+ spec.email = ['ritikesh.ganpathraj@freshworks.com']
11
12
 
12
- spec.summary = %q{Local Memoization Pattern!}
13
- spec.description = %q{Local Memoization Pattern to store complex and repeated computations in memory until the next hour/day/week}
14
- spec.homepage = "https://github.com/freshdesk/memoize_until"
15
- spec.license = "MIT"
13
+ spec.summary = 'Local Memoization Pattern!'
14
+ spec.description = 'Local Memoization Pattern to store complex and repeated computations in memory until the next hour/day/week'
15
+ spec.homepage = 'https://github.com/freshdesk/memoize_until'
16
+ spec.license = 'MIT'
16
17
 
17
18
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
19
  # to allow pushing to a single host or delete this section to allow pushing to any host.
19
- if spec.respond_to?(:metadata)
20
- spec.metadata["allowed_push_host"] = "https://rubygems.org"
20
+ raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.' unless spec.respond_to?(:metadata)
21
21
 
22
- spec.metadata["homepage_uri"] = spec.homepage
23
- spec.metadata["source_code_uri"] = "https://github.com/freshdesk/memoize_until"
24
- else
25
- raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
26
- end
22
+ spec.required_ruby_version = '>= 2.6.9'
23
+
24
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
25
+
26
+ spec.metadata['homepage_uri'] = spec.homepage
27
+ spec.metadata['source_code_uri'] = 'https://github.com/freshdesk/memoize_until'
28
+ spec.metadata['rubygems_mfa_required'] = 'true'
27
29
 
28
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
30
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
29
31
  f.match(%r{^(test|spec|features)/})
30
32
  end
31
- spec.bindir = "exe"
33
+ spec.bindir = 'exe'
32
34
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33
- spec.require_paths = ["lib"]
35
+ spec.require_paths = ['lib']
34
36
 
35
37
  spec.add_development_dependency 'concurrent-ruby', '~> 1.0'
36
- spec.add_development_dependency "minitest", "~> 5.0"
38
+ spec.add_development_dependency 'minitest', '~> 5.0'
39
+ spec.add_development_dependency 'rubocop', '~> 1.49'
40
+ spec.add_development_dependency 'rubocop-minitest', '~> 0.30.0'
37
41
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: memoize_until
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ritikesh
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-19 00:00:00.000000000 Z
11
+ date: 2023-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -38,6 +38,34 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '5.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.49'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.49'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop-minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.30.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.30.0
41
69
  description: Local Memoization Pattern to store complex and repeated computations
42
70
  in memory until the next hour/day/week
43
71
  email:
@@ -46,7 +74,10 @@ executables: []
46
74
  extensions: []
47
75
  extra_rdoc_files: []
48
76
  files:
77
+ - ".github/workflows/.rubocop.yml"
78
+ - ".github/workflows/.tests.yml"
49
79
  - ".gitignore"
80
+ - ".rubocop.yml"
50
81
  - CHANGELOG.md
51
82
  - CODE_OF_CONDUCT.md
52
83
  - Gemfile
@@ -70,6 +101,7 @@ metadata:
70
101
  allowed_push_host: https://rubygems.org
71
102
  homepage_uri: https://github.com/freshdesk/memoize_until
72
103
  source_code_uri: https://github.com/freshdesk/memoize_until
104
+ rubygems_mfa_required: 'true'
73
105
  post_install_message:
74
106
  rdoc_options: []
75
107
  require_paths:
@@ -78,14 +110,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
78
110
  requirements:
79
111
  - - ">="
80
112
  - !ruby/object:Gem::Version
81
- version: '0'
113
+ version: 2.6.9
82
114
  required_rubygems_version: !ruby/object:Gem::Requirement
83
115
  requirements:
84
116
  - - ">="
85
117
  - !ruby/object:Gem::Version
86
118
  version: '0'
87
119
  requirements: []
88
- rubygems_version: 3.0.9
120
+ rubygems_version: 3.2.33
89
121
  signing_key:
90
122
  specification_version: 4
91
123
  summary: Local Memoization Pattern!