adamantium 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  language: ruby
2
2
  before_install: gem install bundler
3
- bundler_args: --without yard guard
3
+ bundler_args: --without yard guard metrics benchmarks
4
4
  script: "bundle exec rake spec"
5
5
  rvm:
6
6
  - 1.8.7
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
@@ -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.6.4')
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')
@@ -1,3 +1,3 @@
1
1
  ---
2
2
  threshold: 9
3
- total_score: 61
3
+ total_score: 66
@@ -1,2 +1,2 @@
1
1
  ---
2
- threshold: 21.1
2
+ threshold: 21.3
@@ -1,5 +1,5 @@
1
1
  ---
2
- AbcMetricMethodCheck: { score: 10.3 }
2
+ AbcMetricMethodCheck: { score: 10.78 }
3
3
  AssignmentInConditionalCheck: { }
4
4
  CaseMissingElseCheck: { }
5
5
  ClassLineCountCheck: { line_count: 293 }
@@ -48,24 +48,28 @@ module Adamantium
48
48
 
49
49
  # Memoize the named method
50
50
  #
51
- # @param [#to_s] method
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(method, freezer)
60
- visibility = method_visibility(method)
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, method)
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 [Symbol] method
68
- # the name of the method
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
- original = instance_method(method)
77
- undef_method(method)
78
- define_method(method) do |*args|
79
- memory.fetch(method) do
80
- value = original.bind(self).call(*args)
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(method, frozen)
86
+ store_memory(method_name, frozen)
83
87
  end
84
88
  end
85
89
  end
@@ -1,3 +1,3 @@
1
1
  module Adamantium
2
- VERSION = '0.0.4'.freeze
2
+ VERSION = '0.0.5'.freeze
3
3
  end
@@ -4,6 +4,9 @@ module AdamantiumSpecs
4
4
  class Object
5
5
  include Adamantium
6
6
 
7
+ def argumented(foo)
8
+ end
9
+
7
10
  def test
8
11
  'test'
9
12
  end
@@ -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(80)
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: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
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: 2012-12-20 00:00:00 Z
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: 31
29
+ hash: 19
30
30
  segments:
31
31
  - 2
32
- - 6
33
- - 4
34
- version: 2.6.4
32
+ - 7
33
+ - 0
34
+ version: 2.7.0
35
35
  type: :runtime
36
36
  version_requirements: *id001
37
37
  - !ruby/object:Gem::Dependency