memery 1.0.0 → 1.1.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
  SHA256:
3
- metadata.gz: 3a2db1b80dc2da0ad38dea657f09a1f4a029017d5c67610e27a71af3aeb9aef4
4
- data.tar.gz: b2e8bc1c499d2462096b0b4045c41de110ea8ea27b5750e23cbdf1a74c57d9f9
3
+ metadata.gz: 91c69224d38dc7b680a40c666d20e36ba65383235e70cec68b8b54b5e42f61ef
4
+ data.tar.gz: 8340fb04f65f8f57a5ee177d6affcb3183d892f65fae04153fb5c2e74d3ee2cf
5
5
  SHA512:
6
- metadata.gz: 813057c9b895b2b789a75c48ea49366a9a951494e90d07a21a628b46ed2bda35e3f9a8407a5efcbf0bf73712ddaff6002d8685e083d6b767e8c52d3102b65743
7
- data.tar.gz: 24a8b9ef7c10341336e301f6e9c09644101fd7c593f9535483cdbf8360ac8ac003d94869200303269fb8d3c6b7103675f7691a7c5d46b31acfd74f5f40b19a59
6
+ metadata.gz: 1acd168dd8d4bc989ac51ca5c37eb1229cf86c8378aac3ef0fef716e4ba81bb50e85975712ac4ea1997ded3c58db43647ffe342f186d6f3a12d7bfc87e646293
7
+ data.tar.gz: 219204fb9a75cd005dcd3102740ba81a67302b5b15609bfceb4c0fe0484698c5a0f1467ce737f7d30067ad85a7b2d9be68df4d489d56d11d6f6789536c7b0533
@@ -3,10 +3,10 @@ language: ruby
3
3
  sudo: false
4
4
 
5
5
  rvm:
6
- - 2.2
7
6
  - 2.3
8
7
  - 2.4
9
8
  - 2.5
9
+ - 2.6
10
10
  - ruby-head
11
11
 
12
12
  before_install: gem install bundler
@@ -19,7 +19,7 @@ matrix:
19
19
  fast_finish: true
20
20
  # Only run RuboCop on the latest Ruby
21
21
  include:
22
- - rvm: 2.5
22
+ - rvm: 2.6
23
23
  env: SUITE="rubocop"
24
24
  allow_failures:
25
25
  - rvm: ruby-head
@@ -1,8 +1,12 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.1.0] - 2019-08-05
4
+ ### Fixed
5
+ - Optimize speed and memory for cached values returns. ([@AlexWayfer]) [#10]
6
+
3
7
  ## [1.0.0] - 2018-08-31
4
8
  ### Added
5
- - Add `:condition` option for `.memoize` method ([@AlexWayfer]) [#7]
9
+ - Add `:condition` option for `.memoize` method. ([@AlexWayfer]) [#7]
6
10
 
7
11
  ## [0.6.0] - 2018-04-20
8
12
  ### Added
@@ -15,10 +19,12 @@
15
19
  [0.5.0]: https://github.com/tycooon/memery/tree/v0.5.0
16
20
  [0.6.0]: https://github.com/tycooon/memery/compare/v0.5.0...v0.6.0
17
21
  [1.0.0]: https://github.com/tycooon/memery/compare/v0.6.0...v1.0.0
18
- [Unreleased]: https://github.com/tycooon/memery/compare/v0.6.0...HEAD
22
+ [1.1.0]: https://github.com/tycooon/memery/compare/v1.0.0...v1.1.0
23
+ [Unreleased]: https://github.com/tycooon/memery/compare/v1.1.0...HEAD
19
24
 
20
25
  [@tycooon]: https://github.com/tycooon
21
26
  [@AlexWayfer]: https://github.com/AlexWayfer
22
27
 
23
28
  [#3]: https://github.com/tycooon/memery/pull/3
24
29
  [#7]: https://github.com/tycooon/memery/pull/7
30
+ [#10]: https://github.com/tycooon/memery/pull/10
data/README.md CHANGED
@@ -8,7 +8,7 @@ def user
8
8
  end
9
9
  ```
10
10
 
11
- However, this approach dosn't work if the calculated result can be `nil` or `false` or in case the method is using arguments. You will also require extra `begin`/`end` lines in case your method requires multiple lines:
11
+ However, this approach doesn't work if calculated result can be `nil` or `false` or in case the method is using arguments. You will also require extra `begin`/`end` lines in case your method requires multiple lines:
12
12
 
13
13
  ```ruby
14
14
  def user
@@ -31,7 +31,8 @@ end
31
31
  ```
32
32
 
33
33
  ## Installation
34
- Juts add `gem "memery"` to your Gemfile.
34
+
35
+ Simply add `gem "memery"` to your Gemfile.
35
36
 
36
37
  ## Usage
37
38
 
@@ -117,7 +118,7 @@ a.call # => 42
117
118
  ```
118
119
 
119
120
  ## Difference with other gems
120
- Memery is very similar to [Memoist](https://github.com/matthewrudy/memoist). The difference is that it doesn't override methods, instead it uses Ruby 2 `Module.prepend` feature. This approach is cleaner and it allows subclasses' methods to work properly: if you redefine a memoized method in a subclass, it's not memoized by default, but you can memoize it normally (without using awkward `identifier: ` argument) and it will just work:
121
+ Memery is very similar to [Memoist](https://github.com/matthewrudy/memoist). The difference is that it doesn't override methods, instead it uses Ruby 2 `Module.prepend` feature. This approach is cleaner (for example you are able to inspect the original method body using `method(:x).super_method.source`) and it allows subclasses' methods to work properly: if you redefine a memoized method in a subclass, it's not memoized by default, but you can memoize it normally (without using awkward `identifier: ` argument) and it will just work:
121
122
 
122
123
  ```ruby
123
124
  class A
@@ -172,10 +173,13 @@ a.users {}
172
173
  However, this solution is kind of hacky.
173
174
 
174
175
  ## Contributing
176
+
175
177
  Bug reports and pull requests are welcome on GitHub at https://github.com/tycooon/memery.
176
178
 
177
179
  ## License
180
+
178
181
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
179
182
 
180
183
  ## Author
184
+
181
185
  Created by Yuri Smirnov.
@@ -44,16 +44,15 @@ module Memery
44
44
  return super(*args, &block)
45
45
  end
46
46
 
47
- @_memery_memoized_values ||= {}
47
+ key = "#{method_name}_#{mod_id}"
48
48
 
49
- key = [method_name, mod_id].join("_").to_sym
50
- store = @_memery_memoized_values[key] ||= {}
49
+ store = @_memery_memoized_values&.[](key)
51
50
 
52
- if store.key?(args)
53
- store[args]
54
- else
55
- store[args] = super(*args)
56
- end
51
+ return store[args] if store&.key?(args)
52
+
53
+ @_memery_memoized_values ||= {}
54
+ @_memery_memoized_values[key] ||= {}
55
+ @_memery_memoized_values[key][args] = super(*args)
57
56
  end
58
57
 
59
58
  send(visibility, method_name)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Memery
4
- VERSION = "1.0.0"
4
+ VERSION = "1.1.0"
5
5
  end
@@ -25,6 +25,5 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency "pry"
26
26
  spec.add_development_dependency "rake"
27
27
  spec.add_development_dependency "rspec"
28
- spec.add_development_dependency "rubocop-config-umbrellio"
29
28
  spec.add_development_dependency "simplecov"
30
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: memery
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuri Smirnov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-31 00:00:00.000000000 Z
11
+ date: 2019-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,20 +80,6 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: rubocop-config-umbrellio
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
83
  - !ruby/object:Gem::Dependency
98
84
  name: simplecov
99
85
  requirement: !ruby/object:Gem::Requirement
@@ -147,8 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
133
  - !ruby/object:Gem::Version
148
134
  version: '0'
149
135
  requirements: []
150
- rubyforge_project:
151
- rubygems_version: 2.7.7
136
+ rubygems_version: 3.0.3
152
137
  signing_key:
153
138
  specification_version: 4
154
139
  summary: A gem for memoization.