memorb 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.circleci/config.yml +52 -0
- data/.gitignore +4 -0
- data/.rspec +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +7 -0
- data/README.md +258 -0
- data/Rakefile +4 -0
- data/lib/memorb.rb +34 -0
- data/lib/memorb/agent.rb +30 -0
- data/lib/memorb/errors.rb +11 -0
- data/lib/memorb/integration.rb +277 -0
- data/lib/memorb/integrator_class_methods.rb +44 -0
- data/lib/memorb/key_value_store.rb +88 -0
- data/lib/memorb/method_identifier.rb +33 -0
- data/lib/memorb/ruby_compatibility.rb +55 -0
- data/lib/memorb/version.rb +5 -0
- data/memorb.gemspec +27 -0
- data/spec/memorb/agent_spec.rb +45 -0
- data/spec/memorb/integration_spec.rb +529 -0
- data/spec/memorb/integrator_class_methods_spec.rb +142 -0
- data/spec/memorb/key_value_store_spec.rb +91 -0
- data/spec/memorb/method_identifier_spec.rb +84 -0
- data/spec/memorb_spec.rb +198 -0
- data/spec/spec_helper.rb +69 -0
- metadata +111 -0
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../lib/memorb'
|
4
|
+
|
5
|
+
module SpecHelper
|
6
|
+
class << self
|
7
|
+
|
8
|
+
def basic_target_class
|
9
|
+
::Class.new do
|
10
|
+
attr_reader :counter
|
11
|
+
def initialize; @counter = 0; end
|
12
|
+
def increment; @counter += 1; end
|
13
|
+
def double; @counter *= 2; end
|
14
|
+
def noop(*args); nil; end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def prng
|
19
|
+
::Random.new(::RSpec.configuration.seed)
|
20
|
+
end
|
21
|
+
|
22
|
+
def force_garbage_collection(wait_cycle: 0.05, min_passes: 1, max_passes: 2)
|
23
|
+
::GC.stress = true
|
24
|
+
starting_count = ::GC.count
|
25
|
+
min_count = starting_count + min_passes
|
26
|
+
pass_count = 0
|
27
|
+
|
28
|
+
::GC.start
|
29
|
+
current_count = ::GC.count
|
30
|
+
|
31
|
+
# Wait for a garbage collection to occur.
|
32
|
+
while current_count < min_count
|
33
|
+
sleep wait_cycle
|
34
|
+
current_count = ::GC.count
|
35
|
+
pass_count += 1
|
36
|
+
if pass_count >= max_passes
|
37
|
+
raise "Exceeded maximum passes (#{max_passes}) for garbage collection during test"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
::GC.stress = false
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_method_name(stringlike, &block)
|
45
|
+
ctx = block.binding.receiver
|
46
|
+
[stringlike, stringlike.to_s].each do |converted|
|
47
|
+
type = converted.class.name.downcase
|
48
|
+
ctx.context "with method name supplied as a #{ type }" do
|
49
|
+
instance_exec(stringlike, converted, &block)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def for_testing_garbage_collection(&block)
|
55
|
+
# JRuby garbage collection isn't as straightforward as CRuby, so tests
|
56
|
+
# that rely on garbage collection are skipped. The expectation is that
|
57
|
+
# if this works for CRuby's GC, then it should work for the GCs of other
|
58
|
+
# Ruby implementations.
|
59
|
+
if ::RUBY_ENGINE != 'jruby'
|
60
|
+
# RSpec blocks aren't allowing out-of-scope variables to be garbage
|
61
|
+
# collected, so `WeakRef` is used to work around that.
|
62
|
+
require 'weakref'
|
63
|
+
|
64
|
+
block.call
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: memorb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Patrick Rebsch
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-06-08 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: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.9'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.9'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: concurrent-ruby
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.1'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.1'
|
55
|
+
description: 'Memorb makes instance method memoization easy to set up and use.
|
56
|
+
|
57
|
+
'
|
58
|
+
email:
|
59
|
+
- pjrebsch@gmail.com
|
60
|
+
executables: []
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- ".circleci/config.yml"
|
65
|
+
- ".gitignore"
|
66
|
+
- ".rspec"
|
67
|
+
- Gemfile
|
68
|
+
- LICENSE.txt
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- lib/memorb.rb
|
72
|
+
- lib/memorb/agent.rb
|
73
|
+
- lib/memorb/errors.rb
|
74
|
+
- lib/memorb/integration.rb
|
75
|
+
- lib/memorb/integrator_class_methods.rb
|
76
|
+
- lib/memorb/key_value_store.rb
|
77
|
+
- lib/memorb/method_identifier.rb
|
78
|
+
- lib/memorb/ruby_compatibility.rb
|
79
|
+
- lib/memorb/version.rb
|
80
|
+
- memorb.gemspec
|
81
|
+
- spec/memorb/agent_spec.rb
|
82
|
+
- spec/memorb/integration_spec.rb
|
83
|
+
- spec/memorb/integrator_class_methods_spec.rb
|
84
|
+
- spec/memorb/key_value_store_spec.rb
|
85
|
+
- spec/memorb/method_identifier_spec.rb
|
86
|
+
- spec/memorb_spec.rb
|
87
|
+
- spec/spec_helper.rb
|
88
|
+
homepage: https://github.com/pjrebsch/memorb
|
89
|
+
licenses:
|
90
|
+
- MIT
|
91
|
+
metadata: {}
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - "~>"
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '2.3'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '2.6'
|
106
|
+
requirements: []
|
107
|
+
rubygems_version: 3.0.4
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: Memoization made easy
|
111
|
+
test_files: []
|