mem 0.1.5 → 0.2.0

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
- SHA1:
3
- metadata.gz: 3dabbde891da1e6d7fdfbc10036bdf09dfc96c84
4
- data.tar.gz: be92cb3a9996e6a958c9b7493ae6bbca3be6e2e5
2
+ SHA256:
3
+ metadata.gz: 79881023089840024f922fa73cfd349e4b4268d5f9653fafc889c7842552af6e
4
+ data.tar.gz: 7b472ff4a10af6acd918d249da95126d4566f281969c4b5c4d0b67f5324b673f
5
5
  SHA512:
6
- metadata.gz: 06414b62be4874cabbac535aef1864a858ff6d89d445c31bbba840396d2da508e8fff08933b06b96e6fac2db65289a1a209b696eb76e03188022a6903760d6d8
7
- data.tar.gz: f7fe1c3e822e8718483d4bbd7e23490bf95b05bbca9ec99da3e74de7484476b5d90a9176dd99fcd8cb246d86e4ee97acf4a3982d69af2dad6a9b8cb933a08bf0
6
+ metadata.gz: 2195bcf0d411fcbcb27de706d16ecb8305ad4cb3d3305bdccf274121383b094368408e14fe4de283866e657e9a2958a5d98ae785c41dd13cc40f5555927f424d
7
+ data.tar.gz: 022e7927762eccc75c21f9e8c694785b430e31d37ce2f80ec6c3d2fbcaa4baed33210d427643e0cfa1dc747856a8b0660b1be738c3c95f57ce29266351fbeadf
@@ -0,0 +1,23 @@
1
+ changelog:
2
+ categories:
3
+ - title: Added
4
+ labels:
5
+ - add
6
+ - title: Changed
7
+ labels:
8
+ - change
9
+ - title: Deprecated
10
+ labels:
11
+ - deprecated
12
+ - title: Fixed
13
+ labels:
14
+ - fix
15
+ - title: Removed
16
+ labels:
17
+ - remove
18
+ - title: Security
19
+ labels:
20
+ - security
21
+ - title: Others
22
+ labels:
23
+ - "*"
@@ -0,0 +1,26 @@
1
+ name: bump-request
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ inputs:
6
+ version:
7
+ description: Version to change to.
8
+ required: true
9
+ type: string
10
+
11
+ jobs:
12
+ run:
13
+ runs-on: ubuntu-latest
14
+ steps:
15
+ - uses: actions/checkout@v4
16
+ - name: Set up Ruby
17
+ uses: ruby/setup-ruby@v1
18
+ with:
19
+ ruby-version: 3.3
20
+ bundler-cache: true
21
+ - uses: r7kamura/bump-request@v0
22
+ with:
23
+ command: |
24
+ sed -i -r 's/([0-9]+\.[0-9]+\.[0-9]+)/${{ inputs.version }}/' lib/mem/version.rb
25
+ bundle install
26
+ version: ${{ inputs.version }}
@@ -0,0 +1,26 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ pull_request:
8
+
9
+ jobs:
10
+ build:
11
+ runs-on: ubuntu-latest
12
+ name: Ruby ${{ matrix.ruby }}
13
+ strategy:
14
+ fail-fast: false
15
+ matrix:
16
+ ruby:
17
+ - '2.7'
18
+ - '3.3'
19
+ steps:
20
+ - uses: actions/checkout@v4
21
+ - uses: ruby/setup-ruby@v1
22
+ with:
23
+ ruby-version: ${{ matrix.ruby }}
24
+ bundler-cache: true
25
+ - run: bundle exec rubocop --format progress --format github
26
+ - run: bundle exec rspec
@@ -0,0 +1,18 @@
1
+ name: github-label-sync
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ paths:
8
+ - .github/workflows/github-label-sync.yml
9
+ workflow_dispatch:
10
+
11
+ jobs:
12
+ build:
13
+ runs-on: ubuntu-latest
14
+ steps:
15
+ - uses: r7kamura/github-label-sync-action@v0
16
+ with:
17
+ source_path: labels-keepachangelog.yml
18
+ source_repository: r7kamura/github-label-presets
@@ -0,0 +1,13 @@
1
+ name: release
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+
8
+ jobs:
9
+ release:
10
+ uses: r7kamura/workflows/.github/workflows/gem-release.yml@main
11
+ if: github.repository_owner == 'r7kamura'
12
+ secrets:
13
+ rubygems-org-api-key: ${{ secrets.RUBYGEMS_ORG_API_KEY }}
data/.gitignore CHANGED
@@ -1,17 +1,3 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
1
+ /.bundle/
2
+ /pkg/
3
+ /tmp/
data/.rubocop.yml ADDED
@@ -0,0 +1,28 @@
1
+ require:
2
+ - rubocop-rake
3
+ - rubocop-rspec
4
+
5
+ inherit_mode:
6
+ merge:
7
+ - Exclude
8
+
9
+ AllCops:
10
+ NewCops: enable
11
+ TargetRubyVersion: 2.7
12
+
13
+ Metrics:
14
+ Enabled: false
15
+
16
+ Naming/PredicateName:
17
+ ForbiddenPrefixes:
18
+ - have_
19
+ - is_
20
+
21
+ RSpec/ExampleLength:
22
+ Enabled: false
23
+
24
+ RSpec/MultipleExpectations:
25
+ Enabled: false
26
+
27
+ Style/Documentation:
28
+ Enabled: false
data/Gemfile CHANGED
@@ -1,4 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
- # Specify your gem's dependencies in mem.gemspec
4
5
  gemspec
6
+
7
+ gem 'bundler'
8
+ gem 'rake'
9
+ gem 'rspec'
10
+ gem 'rubocop'
11
+ gem 'rubocop-rake'
12
+ gem 'rubocop-rspec'
data/Gemfile.lock ADDED
@@ -0,0 +1,71 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ mem (0.2.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ diff-lcs (1.5.1)
11
+ json (2.7.2)
12
+ language_server-protocol (3.17.0.3)
13
+ parallel (1.26.3)
14
+ parser (3.3.4.2)
15
+ ast (~> 2.4.1)
16
+ racc
17
+ racc (1.8.1)
18
+ rainbow (3.1.1)
19
+ rake (13.2.1)
20
+ regexp_parser (2.9.2)
21
+ rexml (3.3.6)
22
+ strscan
23
+ rspec (3.13.0)
24
+ rspec-core (~> 3.13.0)
25
+ rspec-expectations (~> 3.13.0)
26
+ rspec-mocks (~> 3.13.0)
27
+ rspec-core (3.13.0)
28
+ rspec-support (~> 3.13.0)
29
+ rspec-expectations (3.13.2)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.13.0)
32
+ rspec-mocks (3.13.1)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.13.0)
35
+ rspec-support (3.13.1)
36
+ rubocop (1.65.1)
37
+ json (~> 2.3)
38
+ language_server-protocol (>= 3.17.0)
39
+ parallel (~> 1.10)
40
+ parser (>= 3.3.0.2)
41
+ rainbow (>= 2.2.2, < 4.0)
42
+ regexp_parser (>= 2.4, < 3.0)
43
+ rexml (>= 3.2.5, < 4.0)
44
+ rubocop-ast (>= 1.31.1, < 2.0)
45
+ ruby-progressbar (~> 1.7)
46
+ unicode-display_width (>= 2.4.0, < 3.0)
47
+ rubocop-ast (1.32.1)
48
+ parser (>= 3.3.1.0)
49
+ rubocop-rake (0.6.0)
50
+ rubocop (~> 1.0)
51
+ rubocop-rspec (3.0.4)
52
+ rubocop (~> 1.61)
53
+ ruby-progressbar (1.13.0)
54
+ strscan (3.1.0)
55
+ unicode-display_width (2.5.0)
56
+
57
+ PLATFORMS
58
+ ruby
59
+ x86_64-linux
60
+
61
+ DEPENDENCIES
62
+ bundler
63
+ mem!
64
+ rake
65
+ rspec
66
+ rubocop
67
+ rubocop-rake
68
+ rubocop-rspec
69
+
70
+ BUNDLED WITH
71
+ 2.4.9
data/README.md CHANGED
@@ -1,7 +1,19 @@
1
1
  # Mem
2
- Memoize any method call.
2
+
3
+ [![CI](https://github.com/r7kamura/mem/actions/workflows/ci.yml/badge.svg)](https://github.com/r7kamura/mem/actions/workflows/ci.yml)
4
+
5
+ Memoize method calls.
3
6
 
4
7
  ## Installation
8
+
9
+ Install the gem and add to the application's Gemfile by executing:
10
+
11
+ ```
12
+ bundle add mem
13
+ ```
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
5
17
  ```
6
18
  gem install mem
7
19
  ```
data/Rakefile CHANGED
@@ -1 +1,12 @@
1
- require "bundler/gem_tasks"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require 'rubocop/rake_task'
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/lib/mem/core_ext.rb CHANGED
@@ -1,3 +1,5 @@
1
- require "mem"
1
+ # frozen_string_literal: true
2
2
 
3
- Object.send(:include, Mem)
3
+ require 'mem'
4
+
5
+ Object.include Mem
data/lib/mem/version.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Mem
2
- VERSION = "0.1.5"
4
+ VERSION = '0.2.0'
3
5
  end
data/lib/mem.rb CHANGED
@@ -1,4 +1,6 @@
1
- require "mem/version"
1
+ # frozen_string_literal: true
2
+
3
+ require 'mem/version'
2
4
 
3
5
  module Mem
4
6
  def self.included(base)
@@ -28,10 +30,9 @@ module Mem
28
30
  module ClassMethods
29
31
  def memoize(method_name)
30
32
  original_visibility =
31
- case
32
- when protected_instance_methods.include?(method_name)
33
+ if protected_instance_methods.include?(method_name)
33
34
  :protected
34
- when private_instance_methods.include?(method_name)
35
+ elsif private_instance_methods.include?(method_name)
35
36
  :private
36
37
  else
37
38
  :public
@@ -54,12 +55,12 @@ module Mem
54
55
  end
55
56
  send(original_visibility, "unmemoize_#{method_name}")
56
57
 
57
- if original_visibility != :private
58
- define_method("#{method_name}=") do |value|
59
- memoize(method_name, value)
60
- end
61
- send(original_visibility, "#{method_name}=")
58
+ return unless original_visibility != :private
59
+
60
+ define_method("#{method_name}=") do |value|
61
+ memoize(method_name, value)
62
62
  end
63
+ send(original_visibility, "#{method_name}=")
63
64
  end
64
65
  end
65
66
  end
data/mem.gemspec CHANGED
@@ -1,22 +1,23 @@
1
- lib = File.expand_path("../lib", __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ require 'English'
4
+ lib = File.expand_path('lib', __dir__)
2
5
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require "mem/version"
6
+ require 'mem/version'
4
7
 
5
8
  Gem::Specification.new do |spec|
6
- spec.name = "mem"
9
+ spec.name = 'mem'
7
10
  spec.version = Mem::VERSION
8
- spec.authors = ["Ryo Nakamura"]
9
- spec.email = ["r7kamura@gmail.com"]
10
- spec.summary = "Memoize any method call"
11
- spec.homepage = "https://github.com/r7kamura/mem"
12
- spec.license = "MIT"
11
+ spec.authors = ['Ryo Nakamura']
12
+ spec.email = ['r7kamura@gmail.com']
13
+ spec.summary = 'Memoize method calls.'
14
+ spec.homepage = 'https://github.com/r7kamura/mem'
15
+ spec.license = 'MIT'
13
16
 
14
- spec.files = `git ls-files`.split($/)
15
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
- spec.require_paths = ["lib"]
17
+ spec.required_ruby_version = '>= 2.7'
18
18
 
19
- spec.add_development_dependency "bundler"
20
- spec.add_development_dependency "rake"
21
- spec.add_development_dependency "rspec", "2.14.1"
19
+ spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
20
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
+ spec.require_paths = ['lib']
22
+ spec.metadata['rubygems_mfa_required'] = 'true'
22
23
  end
data/spec/mem_spec.rb CHANGED
@@ -1,12 +1,18 @@
1
- require "spec_helper"
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Mem do
6
+ describe '#memoize' do
7
+ before do
8
+ allow(object).to receive(:b).and_call_original
9
+ end
2
10
 
3
- describe Mem do
4
- describe "#memoize" do
5
11
  let(:object) do
6
12
  klass.new
7
13
  end
8
14
 
9
- context "with normal method name" do
15
+ context 'with normal method name' do
10
16
  let(:klass) do
11
17
  Class.new do
12
18
  include Mem
@@ -21,26 +27,26 @@ describe Mem do
21
27
  end
22
28
 
23
29
  def c
24
- "c"
30
+ 'c'
25
31
  end
26
32
  memoize :c
27
33
  end
28
34
  end
29
35
 
30
- it "memoizes the method call" do
31
- expect(object).to receive(:b).once.and_call_original
36
+ it 'memoizes the method call' do
32
37
  expect(object.a(1) { 2 }).to eq [1, 2]
33
38
  expect(object.a(3) { 4 }).to eq [1, 2]
39
+ expect(object).to have_received(:b).once
34
40
  end
35
41
 
36
- it "defines setter" do
37
- expect(object.c).to eq "c"
38
- object.c = "d"
39
- expect(object.c).to eq "d"
42
+ it 'defines setter' do
43
+ expect(object.c).to eq 'c'
44
+ object.c = 'd'
45
+ expect(object.c).to eq 'd'
40
46
  end
41
47
  end
42
48
 
43
- context "with abnormal method name" do
49
+ context 'with abnormal method name' do
44
50
  let(:klass) do
45
51
  Class.new do
46
52
  include Mem
@@ -56,35 +62,32 @@ describe Mem do
56
62
  end
57
63
  end
58
64
 
59
- it "memoizes the method call" do
60
- expect(object).to receive(:b).once.and_call_original
65
+ it 'memoizes the method call' do
61
66
  expect(object.a!(1) { 2 }).to eq [1, 2]
62
67
  expect(object.a!(3) { 4 }).to eq [1, 2]
63
- object.should have_memoized(:a!)
64
- object.memoized(:a!).should == [1, 2]
65
- object.memoized_table.should == { a!: [1, 2] }
68
+ expect(object).to have_received(:b).once
69
+ expect(object).to have_memoized(:a!)
70
+ expect(object.memoized(:a!)).to eq [1, 2]
71
+ expect(object.memoized_table).to eq({ a!: [1, 2] })
66
72
  end
67
73
  end
68
74
 
69
- context "with non-public method name" do
75
+ context 'with non-public method name' do
70
76
  let(:klass) do
71
77
  Class.new do
72
78
  include Mem
73
79
 
74
- def a
75
- end
80
+ def a; end
76
81
  memoize :a
77
82
 
78
83
  protected
79
84
 
80
- def b
81
- end
85
+ def b; end
82
86
  memoize :b
83
87
 
84
88
  private
85
89
 
86
- def c
87
- end
90
+ def c; end
88
91
  memoize :c
89
92
  end
90
93
  end
data/spec/spec_helper.rb CHANGED
@@ -1,8 +1,13 @@
1
- $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
2
- require "mem"
1
+ # frozen_string_literal: true
2
+
3
+ require 'mem'
3
4
 
4
5
  RSpec.configure do |config|
5
- config.treat_symbols_as_metadata_keys_with_true_values = true
6
- config.run_all_when_everything_filtered = true
7
- config.filter_run :focus
6
+ config.disable_monkey_patching!
7
+
8
+ config.expect_with :rspec do |c|
9
+ c.syntax = :expect
10
+ end
11
+
12
+ config.filter_run_when_matching :focus
8
13
  end
metadata CHANGED
@@ -1,57 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-12 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: bundler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: rake
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: rspec
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - '='
46
- - !ruby/object:Gem::Version
47
- version: 2.14.1
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - '='
53
- - !ruby/object:Gem::Version
54
- version: 2.14.1
11
+ date: 2024-08-23 00:00:00.000000000 Z
12
+ dependencies: []
55
13
  description:
56
14
  email:
57
15
  - r7kamura@gmail.com
@@ -59,9 +17,16 @@ executables: []
59
17
  extensions: []
60
18
  extra_rdoc_files: []
61
19
  files:
20
+ - ".github/release.yml"
21
+ - ".github/workflows/bump-request.yml"
22
+ - ".github/workflows/ci.yml"
23
+ - ".github/workflows/github-label-sync.yml"
24
+ - ".github/workflows/release.yml"
62
25
  - ".gitignore"
26
+ - ".rubocop.yml"
63
27
  - CHANGELOG.md
64
28
  - Gemfile
29
+ - Gemfile.lock
65
30
  - LICENSE.txt
66
31
  - README.md
67
32
  - Rakefile
@@ -74,7 +39,8 @@ files:
74
39
  homepage: https://github.com/r7kamura/mem
75
40
  licenses:
76
41
  - MIT
77
- metadata: {}
42
+ metadata:
43
+ rubygems_mfa_required: 'true'
78
44
  post_install_message:
79
45
  rdoc_options: []
80
46
  require_paths:
@@ -83,19 +49,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
83
49
  requirements:
84
50
  - - ">="
85
51
  - !ruby/object:Gem::Version
86
- version: '0'
52
+ version: '2.7'
87
53
  required_rubygems_version: !ruby/object:Gem::Requirement
88
54
  requirements:
89
55
  - - ">="
90
56
  - !ruby/object:Gem::Version
91
57
  version: '0'
92
58
  requirements: []
93
- rubyforge_project:
94
- rubygems_version: 2.2.2
59
+ rubygems_version: 3.3.27
95
60
  signing_key:
96
61
  specification_version: 4
97
- summary: Memoize any method call
98
- test_files:
99
- - spec/mem_spec.rb
100
- - spec/spec_helper.rb
101
- has_rdoc:
62
+ summary: Memoize method calls.
63
+ test_files: []