memo-it 0.3.0 → 0.3.1

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: ae2ef7f59fcce47065e9e4c8b9f1c80453575b27
4
- data.tar.gz: 1b75e93544b70146774b84051eb7dad5720bef00
3
+ metadata.gz: 5c219d9d1f53efd7dcb2686f35b8ad1627764aa3
4
+ data.tar.gz: 0b539381c33dd4037cfe3425055b5ead557ba47c
5
5
  SHA512:
6
- metadata.gz: 50212743b82d81f81650f51f15e0808c9a889bd94f9c8d301fa5aa5a96a603f120d10ec1f657f49c4541e2799e4d7559d9dfd0ef57c850b981b3889df58f8344
7
- data.tar.gz: 9a95c272ab56b6251cfba00d407887e890f0d0ec24898732a2d207913f57272074f3cb43de2c60144bd9eb9681beedcb407921d2992cfd6bc08a222ea37ba46f
6
+ metadata.gz: c64c5ce79094046b63f68d368c4da21583406e6fd27476508efc865d91084383bcfe070c435f6063bed3f819bcc35d2b5b38d014aaef999db9114f2a81a8a9d5
7
+ data.tar.gz: 14cb63e98f8431a9051de9d8fb11a43a3ccab8af6ae11cd6ca63244d9540707ed30cfa0aeb5a5db3bf92058b4626525060b934153d2329aaf52a45449eabae15
data/.travis.yml CHANGED
@@ -1,4 +1,7 @@
1
1
  sudo: false
2
2
  rvm:
3
+ - 2.2.0
3
4
  - 2.3.0
4
5
  - 2.4.0
6
+ notifications:
7
+ email: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,15 @@
1
+ # CHANGELOG
2
+
3
+ ## 0.3.1
4
+
5
+ * simplify key generation (see [issue #7](https://github.com/phoet/memo-it/pull/7) for details)
6
+
7
+ ## 0.3.0 ([list of commits](https://github.com/phoet/memo-it/compare/v0.2.0...v0.3.0))
8
+
9
+ * rename `:ignore` to `:except` (see [issue #5](https://github.com/phoet/memo-it/pull/5) for details)
10
+ * add easy way to disable memoization (see [issue #4](https://github.com/phoet/memo-it/pull/4) for details)
11
+ * add `:only` option for memoizing method parameters (see [issue #3](https://github.com/phoet/memo-it/pull/3) for details)
12
+
13
+ ## 0.2.0 ([list of commits](https://github.com/phoet/memo-it/compare/0.1.1...v0.2.0))
14
+
15
+ * support ignoring selected method parameters (see [issue #2](https://github.com/phoet/memo-it/pull/2) for details)
data/Gemfile CHANGED
@@ -4,3 +4,5 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  gem 'byebug'
7
+ gem 'benchmark-ips'
8
+ gem 'memoist'
data/README.md CHANGED
@@ -19,7 +19,7 @@ Requiring the gem will add a `memo` method to the `Object` class so that you can
19
19
  In case you want to memoize something that has parameters, memo-it will just use all local variables in scope to determine the memoization:
20
20
 
21
21
  ```ruby
22
- def load_repo(name = 'memo-it')
22
+ def load_repo(name = 'memo-it')
23
23
  memo do
24
24
  # in this case the result will be memoized per name
25
25
  HTTPClient.get("https://github.com/phoet/#{name}")
@@ -31,7 +31,7 @@ If, on the other hand, you want to memoize parameters but ignore one of them,
31
31
  you can do this by adding it to the `:except` list:
32
32
 
33
33
  ```ruby
34
- def load_repo(name = 'memo-it', time = Time.now)
34
+ def load_repo(name = 'memo-it', time = Time.now)
35
35
  memo(except: :time) do
36
36
  # in this case the result will be memoized per name
37
37
  HTTPClient.get("https://github.com/phoet/#{name}?time=#{time}")
@@ -42,7 +42,7 @@ you can do this by adding it to the `:except` list:
42
42
  Or provide a list of parameters to except:
43
43
 
44
44
  ```ruby
45
- def load_repo(name = 'memo-it', time = Time.now, other = 'irrelevant')
45
+ def load_repo(name = 'memo-it', time = Time.now, other = 'irrelevant')
46
46
  memo(except: [:time, :other]) do
47
47
  # in this case the result will be memoized per name
48
48
  HTTPClient.get("https://github.com/phoet/#{name}?time=#{time}&other=#{other}")
@@ -53,7 +53,7 @@ Or provide a list of parameters to except:
53
53
  To be symmetric, it's also possible to define one or more parameters through the `:only` key:
54
54
 
55
55
  ```ruby
56
- def load_repo(name = 'memo-it', time = Time.now, format = 'json')
56
+ def load_repo(name = 'memo-it', time = Time.now, format = 'json')
57
57
  memo(only: [:name, :format]) do
58
58
  # in this case the result will be memoized per name & format
59
59
  HTTPClient.get("https://github.com/phoet/#{name}?time=#{time}&format=#{format}")
@@ -100,6 +100,10 @@ If you don't want to include yet another Gem, just run this in your shell:
100
100
 
101
101
  $ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/phoet/memo-it/master/bin/install)"
102
102
 
103
+ ## Changelog
104
+
105
+ See [CHANGELOG.md](https://github.com/phoet/memo-it/blob/master/CHANGELOG.md).
106
+
103
107
  ## Development
104
108
 
105
109
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/Rakefile CHANGED
@@ -1,10 +1,38 @@
1
- require "bundler/gem_tasks"
2
- require "rake/testtask"
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
3
 
4
4
  Rake::TestTask.new(:test) do |t|
5
- t.libs << "test"
6
- t.libs << "lib"
5
+ t.libs << 'test'
6
+ t.libs << 'lib'
7
7
  t.test_files = FileList['test/**/*_test.rb']
8
8
  end
9
9
 
10
- task :default => :test
10
+ task default: :test
11
+
12
+ task :benchmark do
13
+ require_relative 'lib/memo/it'
14
+ require 'benchmark/ips'
15
+ require 'memoist'
16
+
17
+ class Tester
18
+ extend Memoist
19
+
20
+ def memo_it
21
+ memo { false }
22
+ end
23
+
24
+ def memoist
25
+ false
26
+ end
27
+
28
+ memoize :memoist
29
+ end
30
+
31
+ tester = Tester.new
32
+ Benchmark.ips do |x|
33
+ x.warmup = 3
34
+ x.time = 10
35
+ x.report('memo-it') { tester.memo_it }
36
+ x.report('memoist') { tester.memoist }
37
+ end
38
+ end
data/lib/memo/it.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Memo
2
- VERSION = '0.3.0'
2
+ VERSION = '0.3.1'
3
3
 
4
4
  @enabled = true
5
5
 
@@ -27,8 +27,7 @@ module Memo
27
27
  end
28
28
 
29
29
  keys = block.source_location
30
- keys << key_names.map { |name| [name, block.binding.local_variable_get(name)] }
31
- keys = keys.flatten.map(&:to_s)
30
+ keys << key_names.flat_map { |name| [name, block.binding.local_variable_get(name)] }
32
31
 
33
32
  @_memo_it ||= {}
34
33
  return @_memo_it[keys] if Memo.enabled? && @_memo_it.key?(keys)
data/memo-it.gemspec CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
22
  spec.require_paths = ["lib"]
23
23
 
24
- spec.add_development_dependency "bundler", "~> 1.13"
25
- spec.add_development_dependency "rake", "~> 10.0"
26
- spec.add_development_dependency "minitest", "~> 5.0"
24
+ spec.add_development_dependency "bundler", "> 1.0"
25
+ spec.add_development_dependency "rake", "> 10.0"
26
+ spec.add_development_dependency "minitest", "> 5.0"
27
27
  end
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: memo-it
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - phoet
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-15 00:00:00.000000000 Z
11
+ date: 2017-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.13'
19
+ version: '1.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
- version: '1.13'
26
+ version: '1.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: '10.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: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '5.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '5.0'
55
55
  description: "\U0001F4E5 \U0001F4E4 simple yet clever memoization helper with parameter
@@ -62,6 +62,7 @@ extra_rdoc_files: []
62
62
  files:
63
63
  - ".gitignore"
64
64
  - ".travis.yml"
65
+ - CHANGELOG.md
65
66
  - CODE_OF_CONDUCT.md
66
67
  - Gemfile
67
68
  - LICENSE.txt