memoist2 0.2.0 → 0.3.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
2
  SHA1:
3
- metadata.gz: 7e42697bf2e5d3807d6075bf5498bf849b86353c
4
- data.tar.gz: 80b78cee05bd57d58ccfd7afd5e46b4a6e4b79c3
3
+ metadata.gz: ef4b828c8b6a81a9fd4a8aac1c184a43bb7f780f
4
+ data.tar.gz: b8d944584b7b9a3c714ae90fe1604d4cd1673bf2
5
5
  SHA512:
6
- metadata.gz: 66d8dd9039e1f2ac5c724bbc01946cafda39c3d1d5201564f42a2cbe33f37e2ce087f1836b8ee130d408403862245f25bf68e614f1e50b25ce8fc424aa4c2786
7
- data.tar.gz: 2ad308d69a84799e565257ec2e4dedcfac853fc2039346b22abcaa38045859c2aea3d8347435f0d2444d2dace75124e2db7f3112fad440664f6afb734d1f9eec
6
+ metadata.gz: 0a175366c60c368b9cbc45a0b20c1a0da48a192b1704e63db7d78753aaf7b6b4c280e979f623e0f0f3adf7163650a977c8c21511cfeb90161967e506ae58923c
7
+ data.tar.gz: 648a750081622643148de2f103856c8858f149484937a18d2c41db0e479de72cfa19fecd7f98efa65049504b73f9681ae92789c9a571fed1a4a3f35946ad086e
@@ -1 +1 @@
1
- 2.0.0
1
+ 2.2.0
@@ -1,4 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.0.0
4
- # - jruby-20mode # Module prepend not supported yet
4
+ - 2.1.0
5
+ - 2.2.0
6
+ - ruby-head
data/README.md CHANGED
@@ -5,34 +5,47 @@ memoist2
5
5
 
6
6
  Simple Memoization for Ruby 2.0
7
7
 
8
+ ### Differences between Memoist & Memoist2
9
+
10
+ Unlike [Memoist], this is **not** a drop-in replacement for old ActiveSupport::Memoizable. Memoist will still work just fine for that if you're using Ruby 2.0. This project, on the other hand, is just me playing using Module#prepend which makes this stuff very simple.
11
+
12
+ * Memoist works on all Rubies
13
+ * Memoist is quite complicated
14
+ * Memoist has the exact same api as ActiveSupport::Memoizable
15
+ * Memoist2 only works on Ruby >= 2.0.0
16
+ * Memoist2 is deliberately much simpler
17
+ * Memoist2 has a slightly different API that could totally change
18
+
19
+ [Memoist]: https://github.com/matthewrudy/memoist
20
+
8
21
  Example
9
- =======
22
+ -------
10
23
 
11
24
  Memoize an instance method
12
25
 
13
- class Foo
14
- include Memoist2
15
-
16
- def bar
17
- sleep 1 && 2**10
26
+ class Foo
27
+ include Memoist2
28
+
29
+ def bar
30
+ sleep 1 && 2**10
31
+ end
32
+ memoize :bar
18
33
  end
19
- memoize :bar
20
- end
21
34
 
22
35
  Memoize a class method
23
36
 
24
- class Foo
25
- include Memoist2
26
-
27
- def self.bar
28
- # something expensive
37
+ class Foo
38
+ include Memoist2
39
+
40
+ def self.bar
41
+ # something expensive
42
+ end
43
+ memoize_class_method :bar
29
44
  end
30
- memoize_class_method :bar
31
- end
32
45
 
33
46
  Licence
34
- =======
47
+ -------
35
48
 
36
49
  Licensed under the MIT licence.
37
50
 
38
- See the file LICENCE.
51
+ See the file LICENCE.
data/Rakefile CHANGED
@@ -2,74 +2,4 @@ require 'rspec/core/rake_task'
2
2
  RSpec::Core::RakeTask.new(:spec)
3
3
  task :default => :spec
4
4
 
5
- require "rubygems"
6
- require "rubygems/package_task"
7
- require "rdoc/task"
8
-
9
- # This builds the actual gem. For details of what all these options
10
- # mean, and other ones you can add, check the documentation here:
11
- #
12
- # http://rubygems.org/read/chapter/20
13
- #
14
- spec = Gem::Specification.new do |s|
15
-
16
- # Basic details
17
- s.name = "memoist2"
18
- s.version = "0.2.0"
19
- s.summary = "Really simple memoization for ruby 2.0"
20
- s.author = "Matthew Rudy Jacobs"
21
- s.email = "MatthewRudyJacobs@gmail.com"
22
- s.homepage = "https://github.com/matthewrudy/memoist2"
23
- s.license = "MIT"
24
-
25
- s.has_rdoc = true
26
- s.extra_rdoc_files = %w(README.md)
27
- s.rdoc_options = %w(--main README.md)
28
-
29
- # Only works with Ruby 2
30
- s.required_ruby_version = '>= 2.0.0'
31
-
32
- # Add any extra files to include in the gem
33
- s.files = `git ls-files`.split
34
- s.require_paths = ["lib"]
35
-
36
- # Dependencies to run tests
37
- s.add_development_dependency("rspec")
38
- s.add_development_dependency("rake")
39
- end
40
-
41
- # This task actually builds the gem. We also regenerate a static
42
- # .gemspec file, which is useful if something (i.e. GitHub) will
43
- # be automatically building a gem for this project. If you're not
44
- # using GitHub, edit as appropriate.
45
- #
46
- # To publish your gem online, install the 'gemcutter' gem; Read more
47
- # about that here: http://gemcutter.org/pages/gem_docs
48
- Gem::PackageTask.new(spec) do |pkg|
49
- pkg.gem_spec = spec
50
- end
51
-
52
- desc "Build the gemspec file #{spec.name}.gemspec"
53
- task :gemspec do
54
- file = File.dirname(__FILE__) + "/#{spec.name}.gemspec"
55
- File.open(file, "w") {|f| f << spec.to_ruby }
56
- end
57
-
58
- # If you don't want to generate the .gemspec file, just remove this line. Reasons
59
- # why you might want to generate a gemspec:
60
- # - using bundler with a git source
61
- # - building the gem without rake (i.e. gem build blah.gemspec)
62
- # - maybe others?
63
- task :package => :gemspec
64
-
65
- # Generate documentation
66
- RDoc::Task.new do |rd|
67
- rd.main = "README.md"
68
- rd.rdoc_files.include("README.md", "lib/**/*.rb")
69
- rd.rdoc_dir = "rdoc"
70
- end
71
-
72
- desc 'Clear out RDoc and generated packages'
73
- task :clean => [:clobber_rdoc, :clobber_package] do
74
- rm "#{spec.name}.gemspec"
75
- end
5
+ require "bundler/gem_tasks"
@@ -1,3 +1,5 @@
1
+ require "memoist2/version"
2
+
1
3
  module Memoist2
2
4
 
3
5
  def self.memoized_ivar_for(symbol)
@@ -6,28 +8,34 @@ module Memoist2
6
8
 
7
9
  module ClassMethods
8
10
 
9
- def memoize(method_name)
10
- memoized_ivar = Memoist2.memoized_ivar_for(method_name)
11
- memoized_module = Module.new do
12
- module_eval <<-EVAL
13
- def #{method_name}
14
- unless #{memoized_ivar}
15
- #{memoized_ivar} = [super]
11
+ def memoize(*method_names)
12
+ method_names.each do |method_name|
13
+ memoized_ivar = Memoist2.memoized_ivar_for(method_name)
14
+ memoized_module = Module.new do
15
+ module_eval <<-EVAL
16
+ def #{method_name}
17
+ unless #{memoized_ivar}
18
+ #{memoized_ivar} = [super]
19
+ end
20
+ #{memoized_ivar}[0]
21
+ end
22
+
23
+ def self.to_s
24
+ "Memoist2::MemoizedMethod(#{method_name})"
16
25
  end
17
- #{memoized_ivar}[0]
18
- end
19
- EVAL
26
+ def self.inspect; to_s; end
27
+ EVAL
28
+ end
29
+ prepend memoized_module
20
30
  end
21
- prepend memoized_module
22
31
  end
23
32
 
24
- def memoize_class_method(method_name)
33
+ def memoize_class_method(*method_names)
25
34
  singleton_class.class_eval do
26
35
  include Memoist2 unless ancestors.include?(Memoist2)
27
- memoize method_name
36
+ memoize *method_names
28
37
  end
29
38
  end
30
-
31
39
  end
32
40
 
33
41
  def self.included(klass)
@@ -0,0 +1,3 @@
1
+ module Memoist2
2
+ VERSION = "0.3.0"
3
+ end
@@ -1,35 +1,29 @@
1
- # -*- encoding: utf-8 -*-
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'memoist2/version'
5
+
2
6
 
3
7
  Gem::Specification.new do |s|
4
- s.name = "memoist2"
5
- s.version = "0.1.2"
8
+ # Basic details
9
+ s.name = "memoist2"
10
+ s.version = Memoist2::VERSION
11
+ s.authors = ["Matthew Rudy Jacobs"]
12
+ s.email = ["matthewrudyjacobs@gmail.com"]
13
+
14
+ s.summary = "Really simple memoization for ruby 2.0"
15
+ s.homepage = "https://github.com/matthewrudy/memoist2"
16
+ s.license = "MIT"
6
17
 
7
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["Matthew Rudy Jacobs"]
9
- s.date = "2013-07-19"
10
- s.email = "MatthewRudyJacobs@gmail.com"
11
- s.extra_rdoc_files = ["README.md"]
12
- s.files = [".gitignore", ".rspec", ".ruby-version", ".travis.yml", "Gemfile", "LICENCE", "README.md", "Rakefile", "benchmark.rb", "example/foo.rb", "lib/memoist2.rb", "memoist2.gemspec", "spec/memoist2_spec.rb", "spec/spec_helper.rb"]
13
- s.homepage = "https://github.com/matthewrudy/memoist2"
14
- s.licenses = ["MIT"]
15
- s.rdoc_options = ["--main", "README.md"]
16
- s.require_paths = ["lib"]
17
- s.required_ruby_version = Gem::Requirement.new(">= 2.0.0")
18
- s.rubygems_version = "2.0.3"
19
- s.summary = "Really simple memoization for ruby 2.0"
18
+ # Only works with Ruby 2
19
+ s.required_ruby_version = '>= 2.0.0'
20
20
 
21
- if s.respond_to? :specification_version then
22
- s.specification_version = 4
21
+ # Add any extra files to include in the gem
22
+ s.files = `git ls-files`.split
23
+ s.require_paths = ["lib"]
24
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
23
25
 
24
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
25
- s.add_development_dependency(%q<rspec>, [">= 0"])
26
- s.add_development_dependency(%q<rake>, [">= 0"])
27
- else
28
- s.add_dependency(%q<rspec>, [">= 0"])
29
- s.add_dependency(%q<rake>, [">= 0"])
30
- end
31
- else
32
- s.add_dependency(%q<rspec>, [">= 0"])
33
- s.add_dependency(%q<rake>, [">= 0"])
34
- end
26
+ # Dependencies to run tests
27
+ s.add_development_dependency("rspec")
28
+ s.add_development_dependency("rake")
35
29
  end
@@ -29,7 +29,7 @@ describe Memoist2 do
29
29
 
30
30
  it "returns the expected value" do
31
31
  5.times do
32
- subject.nilly.should == nil
32
+ expect(subject.nilly).to be nil
33
33
  end
34
34
  end
35
35
 
@@ -55,7 +55,7 @@ describe Memoist2 do
55
55
 
56
56
  it "returns the expected value" do
57
57
  5.times do
58
- subject.foo.should == :bar
58
+ expect(subject.foo).to be :bar
59
59
  end
60
60
  end
61
61
 
@@ -64,6 +64,27 @@ describe Memoist2 do
64
64
  5.times{ subject.foo }
65
65
  end.to change{ subject.counter }.by(1)
66
66
  end
67
+
68
+ it "can memoize multiple methods simultaneously" do
69
+ subject = Class.new(Counter) do
70
+ include Memoist2
71
+
72
+ def a
73
+ count! && :a
74
+ end
75
+
76
+ def b
77
+ count! && :b
78
+ end
79
+
80
+ memoize :a, :b
81
+ end.new
82
+
83
+ 5.times{ subject.a }
84
+ 5.times{ subject.b }
85
+
86
+ expect(subject.counter).to be 2
87
+ end
67
88
  end
68
89
 
69
90
  describe "class methods" do
@@ -84,7 +105,7 @@ describe Memoist2 do
84
105
 
85
106
  it "works" do
86
107
  5.times do
87
- subject.foo.should == 1
108
+ expect(subject.foo).to be 1
88
109
  end
89
110
  end
90
111
  end
@@ -104,7 +125,7 @@ describe Memoist2 do
104
125
 
105
126
  it "works" do
106
127
  5.times do
107
- subject.foo.should == 1
128
+ expect(subject.foo).to be 1
108
129
  end
109
130
  end
110
131
  end
@@ -132,14 +153,14 @@ describe Memoist2 do
132
153
 
133
154
  it "can memoize question methods" do
134
155
  5.times do
135
- subject.question?.should == 1
156
+ expect(subject.question?).to be 1
136
157
  end
137
158
  end
138
159
 
139
160
  it "can memoize bang methods" do
140
161
  5.times do
141
- subject.bang!.should == 1
162
+ expect(subject.bang!).to be 1
142
163
  end
143
164
  end
144
165
  end
145
- end
166
+ end
metadata CHANGED
@@ -1,54 +1,54 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: memoist2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Rudy Jacobs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-19 00:00:00.000000000 Z
11
+ date: 2015-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  description:
42
- email: MatthewRudyJacobs@gmail.com
42
+ email:
43
+ - matthewrudyjacobs@gmail.com
43
44
  executables: []
44
45
  extensions: []
45
- extra_rdoc_files:
46
- - README.md
46
+ extra_rdoc_files: []
47
47
  files:
48
- - .gitignore
49
- - .rspec
50
- - .ruby-version
51
- - .travis.yml
48
+ - ".gitignore"
49
+ - ".rspec"
50
+ - ".ruby-version"
51
+ - ".travis.yml"
52
52
  - Gemfile
53
53
  - LICENCE
54
54
  - README.md
@@ -56,6 +56,7 @@ files:
56
56
  - benchmark.rb
57
57
  - example/foo.rb
58
58
  - lib/memoist2.rb
59
+ - lib/memoist2/version.rb
59
60
  - memoist2.gemspec
60
61
  - spec/memoist2_spec.rb
61
62
  - spec/spec_helper.rb
@@ -64,25 +65,25 @@ licenses:
64
65
  - MIT
65
66
  metadata: {}
66
67
  post_install_message:
67
- rdoc_options:
68
- - --main
69
- - README.md
68
+ rdoc_options: []
70
69
  require_paths:
71
70
  - lib
72
71
  required_ruby_version: !ruby/object:Gem::Requirement
73
72
  requirements:
74
- - - '>='
73
+ - - ">="
75
74
  - !ruby/object:Gem::Version
76
75
  version: 2.0.0
77
76
  required_rubygems_version: !ruby/object:Gem::Requirement
78
77
  requirements:
79
- - - '>='
78
+ - - ">="
80
79
  - !ruby/object:Gem::Version
81
80
  version: '0'
82
81
  requirements: []
83
82
  rubyforge_project:
84
- rubygems_version: 2.0.3
83
+ rubygems_version: 2.4.5
85
84
  signing_key:
86
85
  specification_version: 4
87
86
  summary: Really simple memoization for ruby 2.0
88
- test_files: []
87
+ test_files:
88
+ - spec/memoist2_spec.rb
89
+ - spec/spec_helper.rb