memonic 1.0.0 → 1.0.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 +4 -4
- data/.coveralls.yml +1 -0
- data/README.md +2 -0
- data/lib/memonic.rb +2 -6
- data/lib/memonic/version.rb +1 -1
- data/memonic.gemspec +1 -0
- data/spec/memonic_spec.rb +31 -78
- data/spec/spec_helper.rb +9 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fbc4fc682b8e4b2fcb5ad38db3f5c8c863e71dbc
|
4
|
+
data.tar.gz: 492b8c26da1adcd58a0f6fc4fb6c635ab42cdf91
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84c12d3022903b732c21cb65c15c8a79b56817ff8a17c03291d3feed87d57aaf7f7967bf3898bfd2d87c25086105f36b8815f5624106c7158300ef3d5196ead2
|
7
|
+
data.tar.gz: f11f196de337dedf221a733fb85769b2b509f307235b00bcfe4670b7a7b0f10754e676805efe60682a3dcd25f6c60cec35cf8d1f93d4dbb5d7ce2dcc488d021d
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
data/README.md
CHANGED
data/lib/memonic.rb
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
require "memonic/version"
|
2
2
|
|
3
3
|
module Memonic
|
4
|
-
|
5
|
-
extend
|
6
|
-
else
|
7
|
-
def self.included(base)
|
8
|
-
base.extend(ClassMethods)
|
9
|
-
end
|
4
|
+
def self.included(base)
|
5
|
+
base.extend(ClassMethods)
|
10
6
|
end
|
11
7
|
|
12
8
|
private
|
data/lib/memonic/version.rb
CHANGED
data/memonic.gemspec
CHANGED
data/spec/memonic_spec.rb
CHANGED
@@ -2,117 +2,70 @@ require "spec_helper"
|
|
2
2
|
require "memonic"
|
3
3
|
|
4
4
|
describe Memonic do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
include Memonic
|
9
|
-
|
10
|
-
memoize :value do
|
11
|
-
computation
|
12
|
-
end
|
13
|
-
end
|
5
|
+
shared_context "memoize the result" do
|
6
|
+
before do
|
7
|
+
allow(memoizer).to receive(:computation).and_call_original
|
14
8
|
end
|
15
9
|
|
16
|
-
|
10
|
+
it "returns the computation result" do
|
11
|
+
expect(memoizer.value).to be result
|
12
|
+
end
|
17
13
|
|
18
|
-
|
19
|
-
|
14
|
+
it "invokes the computation only once" do
|
15
|
+
2.times { memoizer.value }
|
16
|
+
expect(memoizer).to have_received(:computation).once
|
20
17
|
end
|
18
|
+
end
|
19
|
+
|
20
|
+
shared_context "a memoizer" do
|
21
|
+
let(:memoizer) { memoizer_class.new(result) }
|
21
22
|
|
22
23
|
context "with a truthy result" do
|
23
24
|
let(:result) { Object.new }
|
24
25
|
|
25
|
-
|
26
|
-
expect(instance.value).to be result
|
27
|
-
end
|
28
|
-
|
29
|
-
it "invokes the computation only once" do
|
30
|
-
2.times { instance.value }
|
31
|
-
expect(instance).to have_received(:computation).once
|
32
|
-
end
|
26
|
+
it_will "memoize the result"
|
33
27
|
end
|
34
28
|
|
35
29
|
context "with a nil result" do
|
36
30
|
let(:result) { nil }
|
37
31
|
|
38
|
-
|
39
|
-
expect(instance.value).to be result
|
40
|
-
end
|
41
|
-
|
42
|
-
it "invokes the computation only once" do
|
43
|
-
2.times { instance.value }
|
44
|
-
expect(instance).to have_received(:computation).once
|
45
|
-
end
|
32
|
+
it_will "memoize the result"
|
46
33
|
end
|
47
34
|
|
48
35
|
context "with a false result" do
|
49
36
|
let(:result) { false }
|
50
37
|
|
51
|
-
|
52
|
-
expect(instance.value).to be result
|
53
|
-
end
|
54
|
-
|
55
|
-
it "invokes the computation only once" do
|
56
|
-
2.times { instance.value }
|
57
|
-
expect(instance).to have_received(:computation).once
|
58
|
-
end
|
38
|
+
it_will "memoize the result"
|
59
39
|
end
|
60
40
|
end
|
61
41
|
|
62
|
-
describe "
|
63
|
-
let(:
|
42
|
+
describe ".memoize" do
|
43
|
+
let(:memoizer_class) do
|
64
44
|
Struct.new(:computation) do
|
65
45
|
include Memonic
|
66
46
|
|
67
|
-
|
68
|
-
|
47
|
+
memoize :value do
|
48
|
+
computation
|
69
49
|
end
|
70
50
|
end
|
71
51
|
end
|
72
52
|
|
73
|
-
let(:
|
53
|
+
let(:memoizer) { memoizer_class.new(result) }
|
74
54
|
|
75
|
-
|
76
|
-
|
77
|
-
end
|
78
|
-
|
79
|
-
context "with a truthy result" do
|
80
|
-
let(:result) { Object.new }
|
81
|
-
|
82
|
-
it "returns the computation result" do
|
83
|
-
expect(instance.value).to be result
|
84
|
-
end
|
85
|
-
|
86
|
-
it "invokes the computation only once" do
|
87
|
-
2.times { instance.value }
|
88
|
-
expect(instance).to have_received(:computation).once
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
context "with a nil result" do
|
93
|
-
let(:result) { nil }
|
55
|
+
it_behaves_like "a memoizer"
|
56
|
+
end
|
94
57
|
|
95
|
-
|
96
|
-
|
97
|
-
|
58
|
+
describe "#memoize" do
|
59
|
+
let(:memoizer_class) do
|
60
|
+
Struct.new(:computation) do
|
61
|
+
include Memonic
|
98
62
|
|
99
|
-
|
100
|
-
|
101
|
-
|
63
|
+
def value
|
64
|
+
memoize(:@value) { computation }
|
65
|
+
end
|
102
66
|
end
|
103
67
|
end
|
104
68
|
|
105
|
-
|
106
|
-
let(:result) { false }
|
107
|
-
|
108
|
-
it "returns the computation result" do
|
109
|
-
expect(instance.value).to be result
|
110
|
-
end
|
111
|
-
|
112
|
-
it "invokes the computation only once" do
|
113
|
-
2.times { instance.value }
|
114
|
-
expect(instance).to have_received(:computation).once
|
115
|
-
end
|
116
|
-
end
|
69
|
+
it_behaves_like "a memoizer"
|
117
70
|
end
|
118
71
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -17,6 +17,13 @@
|
|
17
17
|
#
|
18
18
|
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
19
19
|
RSpec.configure do |config|
|
20
|
+
# Coveralls
|
21
|
+
require "coveralls"
|
22
|
+
|
23
|
+
Coveralls.wear! do
|
24
|
+
add_filter 'spec'
|
25
|
+
end
|
26
|
+
|
20
27
|
# rspec-expectations config goes here. You can use an alternate
|
21
28
|
# assertion/expectation library such as wrong or the stdlib/minitest
|
22
29
|
# assertions if you prefer.
|
@@ -40,6 +47,8 @@ RSpec.configure do |config|
|
|
40
47
|
mocks.verify_partial_doubles = true
|
41
48
|
end
|
42
49
|
|
50
|
+
config.alias_it_behaves_like_to :it_will, 'it will'
|
51
|
+
|
43
52
|
# The settings below are suggested to provide a good initial experience
|
44
53
|
# with RSpec, but feel free to customize to your heart's content.
|
45
54
|
=begin
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: memonic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Carney
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: coveralls
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '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'
|
55
69
|
description: Memonic is a simple, lightweight memoization helper.
|
56
70
|
email:
|
57
71
|
- john@carney.id.au
|
@@ -59,6 +73,7 @@ executables: []
|
|
59
73
|
extensions: []
|
60
74
|
extra_rdoc_files: []
|
61
75
|
files:
|
76
|
+
- ".coveralls.yml"
|
62
77
|
- ".gitignore"
|
63
78
|
- ".rspec"
|
64
79
|
- ".travis.yml"
|
@@ -90,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
105
|
version: '0'
|
91
106
|
requirements: []
|
92
107
|
rubyforge_project:
|
93
|
-
rubygems_version: 2.4.
|
108
|
+
rubygems_version: 2.4.3
|
94
109
|
signing_key:
|
95
110
|
specification_version: 4
|
96
111
|
summary: A simple, lightweight memoization helper.
|