adamantium 0.0.4 → 0.0.5
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.
- data/.travis.yml +1 -1
- data/Gemfile +1 -2
- data/adamantium.gemspec +2 -2
- data/config/flay.yml +1 -1
- data/config/flog.yml +1 -1
- data/config/roodi.yml +1 -1
- data/lib/adamantium/module_methods.rb +17 -13
- data/lib/adamantium/version.rb +1 -1
- data/spec/unit/adamantium/fixtures/classes.rb +3 -0
- data/spec/unit/adamantium/module_methods/memoize_spec.rb +9 -1
- metadata +8 -8
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -27,9 +27,8 @@ end
|
|
27
27
|
group :metrics do
|
28
28
|
gem 'flay', '~> 1.4.3'
|
29
29
|
gem 'flog', '~> 2.5.3'
|
30
|
-
gem 'reek', '~> 1.2.8', :github => 'dkubb/reek'
|
31
30
|
gem 'roodi', '~> 2.1.0'
|
32
|
-
gem 'yardstick', '~> 0.8.0'
|
31
|
+
gem 'yardstick', '~> 0.8.0', :git => 'https://github.com/dkubb/yardstick.git'
|
33
32
|
|
34
33
|
platforms :ruby_18, :ruby_19 do
|
35
34
|
# this indirectly depends on ffi which does not build on ruby-head
|
data/adamantium.gemspec
CHANGED
@@ -13,10 +13,10 @@ Gem::Specification.new do |gem|
|
|
13
13
|
|
14
14
|
gem.require_paths = %w[lib]
|
15
15
|
gem.files = `git ls-files`.split($/)
|
16
|
-
gem.test_files = `git ls-files spec/{unit,integration}`.split($/)
|
16
|
+
gem.test_files = `git ls-files -- spec/{unit,integration}`.split($/)
|
17
17
|
gem.extra_rdoc_files = %w[LICENSE README.md TODO]
|
18
18
|
|
19
|
-
gem.add_runtime_dependency('backports', '~> 2.
|
19
|
+
gem.add_runtime_dependency('backports', '~> 2.7.0')
|
20
20
|
gem.add_runtime_dependency('ice_nine', '~> 0.6.0')
|
21
21
|
|
22
22
|
gem.add_development_dependency('rake', '~> 10.0.3')
|
data/config/flay.yml
CHANGED
data/config/flog.yml
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
---
|
2
|
-
threshold: 21.
|
2
|
+
threshold: 21.3
|
data/config/roodi.yml
CHANGED
@@ -48,24 +48,28 @@ module Adamantium
|
|
48
48
|
|
49
49
|
# Memoize the named method
|
50
50
|
#
|
51
|
-
# @param [#to_s]
|
52
|
-
# a method to memoize
|
51
|
+
# @param [#to_s] method_name
|
52
|
+
# a method name to memoize
|
53
53
|
# @param [#call] freezer
|
54
54
|
# a freezer for memoized values
|
55
55
|
#
|
56
56
|
# @return [undefined]
|
57
57
|
#
|
58
58
|
# @api private
|
59
|
-
def memoize_method(
|
60
|
-
|
59
|
+
def memoize_method(method_name, freezer)
|
60
|
+
method = instance_method(method_name)
|
61
|
+
if method.arity.nonzero?
|
62
|
+
raise ArgumentError, 'Cannot memoize method with nonzero arity'
|
63
|
+
end
|
64
|
+
visibility = method_visibility(method_name)
|
61
65
|
define_memoize_method(method, freezer)
|
62
|
-
send(visibility,
|
66
|
+
send(visibility, method_name)
|
63
67
|
end
|
64
68
|
|
65
69
|
# Define a memoized method that delegates to the original method
|
66
70
|
#
|
67
|
-
# @param [
|
68
|
-
# the
|
71
|
+
# @param [UnboundMethod] method
|
72
|
+
# the method to memoize
|
69
73
|
# @param [#call] freezer
|
70
74
|
# a freezer for memoized values
|
71
75
|
#
|
@@ -73,13 +77,13 @@ module Adamantium
|
|
73
77
|
#
|
74
78
|
# @api private
|
75
79
|
def define_memoize_method(method, freezer)
|
76
|
-
|
77
|
-
undef_method(
|
78
|
-
define_method(
|
79
|
-
memory.fetch(
|
80
|
-
value =
|
80
|
+
method_name = method.name.to_sym
|
81
|
+
undef_method(method_name)
|
82
|
+
define_method(method_name) do |*args|
|
83
|
+
memory.fetch(method_name) do
|
84
|
+
value = method.bind(self).call(*args)
|
81
85
|
frozen = freezer.call(value)
|
82
|
-
store_memory(
|
86
|
+
store_memory(method_name, frozen)
|
83
87
|
end
|
84
88
|
end
|
85
89
|
end
|
data/lib/adamantium/version.rb
CHANGED
@@ -23,7 +23,7 @@ shared_examples_for 'memoizes method' do
|
|
23
23
|
if method != :some_state
|
24
24
|
file, line = object.new.send(method).first.split(':')[0, 2]
|
25
25
|
File.expand_path(file).should eql(File.expand_path('../../../../../lib/adamantium/module_methods.rb', __FILE__))
|
26
|
-
line.to_i.should eql(
|
26
|
+
line.to_i.should eql(84)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -69,6 +69,14 @@ describe Adamantium::ModuleMethods, '#memoize' do
|
|
69
69
|
end
|
70
70
|
end
|
71
71
|
end
|
72
|
+
|
73
|
+
context 'on method with arguments' do
|
74
|
+
let(:method) { :argumented }
|
75
|
+
|
76
|
+
it 'should raise error' do
|
77
|
+
expect { subject }.to raise_error(ArgumentError, 'Cannot memoize method with nonzero arity')
|
78
|
+
end
|
79
|
+
end
|
72
80
|
|
73
81
|
context 'with :noop freezer option' do
|
74
82
|
let(:method) { :some_state }
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adamantium
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 5
|
10
|
+
version: 0.0.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Dan Kubb
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date:
|
19
|
+
date: 2013-01-20 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: backports
|
@@ -26,12 +26,12 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
hash:
|
29
|
+
hash: 19
|
30
30
|
segments:
|
31
31
|
- 2
|
32
|
-
-
|
33
|
-
-
|
34
|
-
version: 2.
|
32
|
+
- 7
|
33
|
+
- 0
|
34
|
+
version: 2.7.0
|
35
35
|
type: :runtime
|
36
36
|
version_requirements: *id001
|
37
37
|
- !ruby/object:Gem::Dependency
|